From b7896e07a193f590d758c2a0361bd1712bb68fdc Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 22:15:04 -0400 Subject: [PATCH 01/11] Fix cargo fmt --- .github/workflows/rust.yml | 10 ++++++---- src/main.rs | 8 +++----- tests/integration/compiler_tests.rs | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fcafc28..d5a1aaa 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,7 +2,7 @@ name: Rust on: push: - branches: [ main, tests ] + branches: [ main, tests, ci ] pull_request: branches: [ main ] @@ -89,9 +89,11 @@ jobs: - name: Install npiet run: | - git clone git@github.com:gleitz/npiet.git && cd npiet - make install - sudo cp npiet /bin/ + sudo apt install libgd-dev groff + git clone https://github.com/gleitz/npiet.git && cd npiet + ./configure + make + sudo make install - name: Run clippy run: cargo clippy --all-targets --all-features -- -D warnings diff --git a/src/main.rs b/src/main.rs index c3e8d8f..81a4910 100644 --- a/src/main.rs +++ b/src/main.rs @@ -281,11 +281,9 @@ fn main() -> Result<(), Error> { // Use the already-built CFG instead of creating a new one let mut piet_ctx = LoweringCtx::new(&context, module, builder, cfg_builder, compile_options); - if let Err(e) = pipeline::run_piet_optimization_pipeline( - &mut piet_ctx, - &mut cfg, - compile_options, - ) { + if let Err(e) = + pipeline::run_piet_optimization_pipeline(&mut piet_ctx, &mut cfg, compile_options) + { println!("{:?}", e); } } diff --git a/tests/integration/compiler_tests.rs b/tests/integration/compiler_tests.rs index 0a52ab4..4daf531 100644 --- a/tests/integration/compiler_tests.rs +++ b/tests/integration/compiler_tests.rs @@ -53,8 +53,7 @@ fn compile_program( opt_level: Option<&str>, ) -> Result<(), String> { let mut cmd = Command::new(pietcc_binary()); - cmd.arg(image_path) - .arg("--uw"); // Treat unknown pixels as white (some test images need this) + cmd.arg(image_path).arg("--uw"); // Treat unknown pixels as white (some test images need this) // Add optimization flag if specified if let Some(opt) = opt_level { From a94a6379e2a3b91c239d7c1e183e740017a9dfb1 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 22:38:24 -0400 Subject: [PATCH 02/11] Clippy fix --- src/main.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81a4910..d03dfec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,7 +159,9 @@ fn main() -> Result<(), Error> { if let Some(val) = matches.value_of("codel_size") { if let Ok(val) = val.parse::() { - if program.dimensions().0 % val != 0 || program.dimensions().1 % val != 0 { + if !program.dimensions().0.is_multiple_of(val) + || !program.dimensions().1.is_multiple_of(val) + { match env::consts::OS { "linux" => { eprintln!( @@ -187,7 +189,7 @@ fn main() -> Result<(), Error> { } } - if let Some(_) = matches.value_of("use_default") { + if matches.value_of("use_default").is_some() { codel_settings = CodelSettings::Default } @@ -256,16 +258,8 @@ fn main() -> Result<(), Error> { } let warn_nt = matches.is_present("warn_nontermination"); - - let show_codel_size = match verbosity { - Verbosity::Low | Verbosity::Normal => false, - _ => true, - }; - - let show_cfg_size = match verbosity { - Verbosity::Low => false, - _ => true, - }; + let show_codel_size = !matches!(verbosity, Verbosity::Low | Verbosity::Normal); + let show_cfg_size = !matches!(verbosity, Verbosity::Low); let compile_options = CompilerSettings { opt_level, From 96c8ffa3e24184b749a5e82677a6f0a48cecada3 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 22:40:58 -0400 Subject: [PATCH 03/11] Clippy tests --- tests/integration/compiler_tests.rs | 4 ++-- tests/integration/interpreter_tests.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/compiler_tests.rs b/tests/integration/compiler_tests.rs index 4daf531..c531db0 100644 --- a/tests/integration/compiler_tests.rs +++ b/tests/integration/compiler_tests.rs @@ -123,10 +123,10 @@ fn compile_and_run( /// Helper to test that pietcc output matches npiet output fn test_against_npiet(image_path: &str, input: &str, opt_level: Option<&str>) { let npiet_output = - run_npiet(image_path, input).expect(&format!("npiet failed for {}", image_path)); + run_npiet(image_path, input).unwrap_or_else(|_| panic!("npiet failed for {}", image_path)); let pietcc_raw_output = compile_and_run(image_path, input, opt_level) - .expect(&format!("pietcc failed for {}", image_path)); + .unwrap_or_else(|_| panic!("pietcc failed for {}", image_path)); // Strip debug output (lines containing "Stack") from pietcc output let pietcc_output: String = pietcc_raw_output diff --git a/tests/integration/interpreter_tests.rs b/tests/integration/interpreter_tests.rs index c45acf0..807b082 100644 --- a/tests/integration/interpreter_tests.rs +++ b/tests/integration/interpreter_tests.rs @@ -98,7 +98,7 @@ fn test_hi_interpreter() { assert!(result.is_ok(), "Interpreter failed: {:?}", result.err()); let output = result.unwrap(); assert!( - output.contains("Hi") || output.len() > 0, + output.contains("Hi") || !output.is_empty(), "Expected non-empty output, got: {}", output ); @@ -112,7 +112,7 @@ fn test_pi_interpreter() { assert!(result.is_ok(), "Interpreter failed: {:?}", result.err()); let output = result.unwrap(); // Pi calculation should produce digits - assert!(output.len() > 0, "Expected output from pi calculation"); + assert!(!output.is_empty(), "Expected output from pi calculation"); } #[test] @@ -124,7 +124,7 @@ fn test_fizzbuzz_interpreter() { let output = result.unwrap(); // FizzBuzz should contain Fizz or Buzz assert!( - output.contains("Fizz") || output.contains("Buzz") || output.len() > 0, + output.contains("Fizz") || output.contains("Buzz") || !output.is_empty(), "Expected FizzBuzz output, got: {}", output ); @@ -139,7 +139,7 @@ fn test_factorial_interpreter() { let output = result.unwrap(); // 5! = 120 assert!( - output.contains("120") || output.len() > 0, + output.contains("120") || !output.is_empty(), "Expected factorial output, got: {}", output ); @@ -154,7 +154,7 @@ fn test_adder_interpreter() { let output = result.unwrap(); // Should add 3 + 5 = 8 assert!( - output.contains("8") || output.len() > 0, + output.contains("8") || !output.is_empty(), "Expected addition output, got: {}", output ); @@ -169,7 +169,7 @@ fn test_euclid_interpreter() { let output = result.unwrap(); // GCD of 48 and 18 is 6 assert!( - output.contains("6") || output.len() > 0, + output.contains("6") || !output.is_empty(), "Expected GCD output, got: {}", output ); From eec1b681548d8ef6c06718d3793458ac9634c2f1 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 22:57:06 -0400 Subject: [PATCH 04/11] Add npiet installation for test and codecov --- .github/workflows/rust.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d5a1aaa..387539c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -57,6 +57,14 @@ jobs: brew install llvm@18 echo "LLVM_SYS_180_PREFIX=$(brew --prefix llvm@18)" >> $GITHUB_ENV + - name: Install npiet + run: | + sudo apt install libgd-dev groff + git clone https://github.com/gleitz/npiet.git && cd npiet + ./configure + make + sudo make install + - name: Run unit tests run: cargo test --lib --bins @@ -114,6 +122,14 @@ jobs: sudo ./llvm.sh 18 sudo apt-get install -y llvm-18-dev libpolly-18-dev + - name: Install npiet + run: | + sudo apt install libgd-dev groff + git clone https://github.com/gleitz/npiet.git && cd npiet + ./configure + make + sudo make install + - name: Check compilation run: cargo check --all-targets @@ -129,6 +145,14 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Install npiet + run: | + sudo apt install libgd-dev groff + git clone https://github.com/gleitz/npiet.git && cd npiet + ./configure + make + sudo make install + - name: Install LLVM run: | wget https://apt.llvm.org/llvm.sh From 09f82d6733f48e5f941fce7bbb72ec5007787589 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 23:24:22 -0400 Subject: [PATCH 05/11] Try llc version --- .github/workflows/rust.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 387539c..9daf213 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -129,7 +129,7 @@ jobs: ./configure make sudo make install - + - name: Check compilation run: cargo check --all-targets @@ -158,7 +158,8 @@ jobs: wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 18 - sudo apt-get install -y llvm-18-dev libpolly-18-dev + sudo apt-get install -y llvm-18-dev libpolly-18-dev llvm-18-tools + sudo ln -s /usr/bin/llc-18 /usr/bin/llc - name: Install cargo-tarpaulin run: cargo install cargo-tarpaulin From 7d3700cd772a8d78ddc649af358ac289167a5383 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 23:48:59 -0400 Subject: [PATCH 06/11] Add MacOS specific jobs --- .github/workflows/rust.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9daf213..0905992 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -56,8 +56,10 @@ jobs: run: | brew install llvm@18 echo "LLVM_SYS_180_PREFIX=$(brew --prefix llvm@18)" >> $GITHUB_ENV + echo "$(brew --prefix llvm@18)/bin" >> $GITHUB_PATH - - name: Install npiet + - name: Install npiet (Ubuntu) + if: matrix.os == 'ubuntu-latest' run: | sudo apt install libgd-dev groff git clone https://github.com/gleitz/npiet.git && cd npiet @@ -65,6 +67,15 @@ jobs: make sudo make install + - name: Install npiet (macOS) + if: matrix.os == 'macos-latest' + run: | + brew install gd groff + git clone https://github.com/gleitz/npiet.git && cd npiet + ./configure + make + sudo make install + - name: Run unit tests run: cargo test --lib --bins From 62502e402cf5ad43ee2df8eb9a344767f0253d5e Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Sun, 29 Mar 2026 23:54:29 -0400 Subject: [PATCH 07/11] Remove unit test jobs --- .github/workflows/rust.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0905992..8f7d772 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -75,10 +75,7 @@ jobs: ./configure make sudo make install - - - name: Run unit tests - run: cargo test --lib --bins - + - name: Build release binary run: cargo build --release From eb46ac9478de4acf74302d40830819c7c5e0c399 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Mon, 30 Mar 2026 00:39:15 -0400 Subject: [PATCH 08/11] Fix gd.h header missing --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8f7d772..7b9b5dc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -71,6 +71,8 @@ jobs: if: matrix.os == 'macos-latest' run: | brew install gd groff + export CFLAGS="-I$(brew --prefix)/include" + export LDFLAGS="-L$(brew --prefix)/lib" git clone https://github.com/gleitz/npiet.git && cd npiet ./configure make From 50120ce58d4272f2fcd5c48e2903f50553e10f10 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Mon, 30 Mar 2026 00:55:38 -0400 Subject: [PATCH 09/11] Test fix --- .github/workflows/rust.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7b9b5dc..9fe3990 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -71,11 +71,9 @@ jobs: if: matrix.os == 'macos-latest' run: | brew install gd groff - export CFLAGS="-I$(brew --prefix)/include" - export LDFLAGS="-L$(brew --prefix)/lib" git clone https://github.com/gleitz/npiet.git && cd npiet - ./configure - make + ./configure CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" + make CFLAGS="-I$(brew --prefix)/include -g -O2 -Wall -DHAVE_CONFIG_H" LDFLAGS="-L$(brew --prefix)/lib" sudo make install - name: Build release binary From f60c288f1c5595c79dd1b50e075d1c8062e12f75 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Mon, 30 Mar 2026 01:09:06 -0400 Subject: [PATCH 10/11] Remove npiet macos tests (versioning issue) --- .github/workflows/rust.yml | 10 ++-------- README.md | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fe3990..f7e35e2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -67,14 +67,8 @@ jobs: make sudo make install - - name: Install npiet (macOS) - if: matrix.os == 'macos-latest' - run: | - brew install gd groff - git clone https://github.com/gleitz/npiet.git && cd npiet - ./configure CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" - make CFLAGS="-I$(brew --prefix)/include -g -O2 -Wall -DHAVE_CONFIG_H" LDFLAGS="-L$(brew --prefix)/lib" - sudo make install + # npiet installation skipped on macOS due to giflib 5.x API incompatibility + # npiet was written for giflib 4.x and requires patching for giflib 5.x - name: Build release binary run: cargo build --release diff --git a/README.md b/README.md index fa4ef8b..c06ad07 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,25 @@ Alternatively, it is possible to combine the build / run workflow via ## Testing -PietCC includes comprehensive unit and integration tests. To run all tests: +PietCC includes comprehensive unit and integration tests. + +### Prerequisites + +Integration tests require [npiet](https://github.com/gleitz/npiet) to be installed: + +**Ubuntu/Debian:** +```bash +sudo apt install libgd-dev groff +git clone https://github.com/gleitz/npiet.git && cd npiet +./configure +make +sudo make install +``` + +**macOS:** +npiet is not currently supported on macOS due to giflib API incompatibilities. Unit tests will still work. + +### Running Tests ```bash # Run all tests From 1952722e3baf817cb1085951ee4fc6aa39d993fe Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Mon, 30 Mar 2026 01:18:11 -0400 Subject: [PATCH 11/11] Add CFG directives for tests --- .github/workflows/rust.yml | 5 ++++- tests/integration/mod.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f7e35e2..c6b5bf8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -50,6 +50,7 @@ jobs: chmod +x llvm.sh sudo ./llvm.sh 18 sudo apt-get install -y llvm-18-dev libpolly-18-dev + sudo ln -s /usr/bin/llc-18 /usr/bin/llc - name: Install LLVM (macOS) if: matrix.os == 'macos-latest' @@ -73,7 +74,7 @@ jobs: - name: Build release binary run: cargo build --release - - name: Run integration tests + - name: Run integration tests (Ubuntu) run: cargo test --test '*' lint: @@ -93,6 +94,7 @@ jobs: chmod +x llvm.sh sudo ./llvm.sh 18 sudo apt-get install -y llvm-18-dev libpolly-18-dev + sudo ln -s /usr/bin/llc-18 /usr/bin/llc - name: Run rustfmt run: cargo fmt -- --check @@ -123,6 +125,7 @@ jobs: chmod +x llvm.sh sudo ./llvm.sh 18 sudo apt-get install -y llvm-18-dev libpolly-18-dev + sudo ln -s /usr/bin/llc-18 /usr/bin/llc - name: Install npiet run: | diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs index 427a0ce..6a30f82 100644 --- a/tests/integration/mod.rs +++ b/tests/integration/mod.rs @@ -5,5 +5,6 @@ #[path = "../common/mod.rs"] mod common; +#[cfg(not(target_os = "macos"))] mod compiler_tests; mod interpreter_tests;