From 431b3c3ec0143ebda84c3f719bb62c57cc3882e8 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 18:54:39 -0800 Subject: [PATCH 01/21] transpile: store `const GENERATED_RUST_TOOLCHAIN_TOML: &str` from `generated-rust-toolchain.toml` --- c2rust-transpile/src/build_files/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/c2rust-transpile/src/build_files/mod.rs b/c2rust-transpile/src/build_files/mod.rs index 5ab50d9a6b..b19af9183f 100644 --- a/c2rust-transpile/src/build_files/mod.rs +++ b/c2rust-transpile/src/build_files/mod.rs @@ -225,7 +225,7 @@ fn emit_build_rs( }); let output = reg.render("build.rs", &json).unwrap(); let output_path = build_dir.join("build.rs"); - maybe_write_to_file(&output_path, output, tcfg.overwrite_existing) + maybe_write_to_file(&output_path, &output, tcfg.overwrite_existing) } /// Emit lib.rs (main.rs) for a library (binary). Returns `Some(path)` @@ -253,15 +253,20 @@ fn emit_lib_rs( let output_path = build_dir.join(file_name); let output = reg.render("lib.rs", &json).unwrap(); - maybe_write_to_file(&output_path, output, tcfg.overwrite_existing) + maybe_write_to_file(&output_path, &output, tcfg.overwrite_existing) } +pub const GENERATED_RUST_TOOLCHAIN_TOML: &str = include_str!("generated-rust-toolchain.toml"); + /// If we translate variadic functions, the output will only compile /// on a nightly toolchain until the `c_variadics` feature is stable. fn emit_rust_toolchain(tcfg: &TranspilerConfig, build_dir: &Path) { let output_path = build_dir.join("rust-toolchain.toml"); - let output = include_str!("generated-rust-toolchain.toml").to_string(); - maybe_write_to_file(&output_path, output, tcfg.overwrite_existing); + maybe_write_to_file( + &output_path, + GENERATED_RUST_TOOLCHAIN_TOML, + tcfg.overwrite_existing, + ); } fn emit_cargo_toml<'lcmd>( @@ -306,10 +311,10 @@ fn emit_cargo_toml<'lcmd>( let file_name = "Cargo.toml"; let output_path = build_dir.join(file_name); let output = reg.render(file_name, &json).unwrap(); - maybe_write_to_file(&output_path, output, tcfg.overwrite_existing); + maybe_write_to_file(&output_path, &output, tcfg.overwrite_existing); } -fn maybe_write_to_file(output_path: &Path, output: String, overwrite: bool) -> Option { +fn maybe_write_to_file(output_path: &Path, output: &str, overwrite: bool) -> Option { if output_path.exists() && !overwrite { eprintln!("Skipping existing file {}", output_path.display()); return None; From b60012aecd75cde3af945126c036be30c9eeb8de Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 18:58:12 -0800 Subject: [PATCH 02/21] transpile: parse `const GENERATED_RUST_TOOLCHAIN: &str` from `GENERATED_RUST_TOOLCHAIN_TOML` and use it to deduplicate --- c2rust-transpile/src/build_files/mod.rs | 51 ++++++++++++++++++++++++- c2rust-transpile/src/lib.rs | 8 ++-- c2rust-transpile/tests/snapshots.rs | 4 +- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/c2rust-transpile/src/build_files/mod.rs b/c2rust-transpile/src/build_files/mod.rs index b19af9183f..80003422b5 100644 --- a/c2rust-transpile/src/build_files/mod.rs +++ b/c2rust-transpile/src/build_files/mod.rs @@ -2,7 +2,8 @@ use std::collections::BTreeMap; use std::fs::{self, File}; use std::io::Write; use std::path::{Path, PathBuf}; -use std::str::FromStr; +use std::slice; +use std::str::{from_utf8, FromStr}; use handlebars::Handlebars; use pathdiff::diff_paths; @@ -257,6 +258,54 @@ fn emit_lib_rs( } pub const GENERATED_RUST_TOOLCHAIN_TOML: &str = include_str!("generated-rust-toolchain.toml"); +pub const GENERATED_RUST_TOOLCHAIN: &str = { + const fn find_substring(s: &str, sub: &str, start: usize) -> usize { + let s = s.as_bytes(); + let sub = sub.as_bytes(); + assert!(sub.len() + start <= s.len()); + let n = s.len() - sub.len(); + let mut i = start; + while i < n { + let mut j = 0; + let mut eq = true; + while j < sub.len() { + if s[i + j] != sub[j] { + eq = false; + break; + } + j += 1; + } + if eq { + return i; + } + i += 1; + } + assert!(false); + return 0; + } + + let toml = GENERATED_RUST_TOOLCHAIN_TOML; + let prefix = "\nchannel = \""; + let suffix = "\""; + let prefix_start = find_substring(toml, prefix, 0); + let start = prefix_start + prefix.len(); + let end = find_substring(toml, suffix, start); + + let toml = toml.as_bytes(); + let len = end - start; + assert!(start + len <= toml.len()); + // `const` slicing. + // SAFETY: Above `assert!`. + let toolchain = unsafe { + let ptr = toml.as_ptr().add(start); + slice::from_raw_parts(ptr, len) + }; + let toolchain = match from_utf8(toolchain) { + Ok(toolchain) => toolchain, + Err(_) => panic!(), + }; + toolchain +}; /// If we translate variadic functions, the output will only compile /// on a nightly toolchain until the `c_variadics` feature is stable. diff --git a/c2rust-transpile/src/lib.rs b/c2rust-transpile/src/lib.rs index e94ab9ecb8..b4385c5422 100644 --- a/c2rust-transpile/src/lib.rs +++ b/c2rust-transpile/src/lib.rs @@ -27,15 +27,15 @@ use regex::Regex; use serde_derive::Serialize; pub use tempfile::TempDir; +use crate::build_files::{emit_build_files, get_build_dir, CrateConfig}; +pub use crate::build_files::{GENERATED_RUST_TOOLCHAIN, GENERATED_RUST_TOOLCHAIN_TOML}; use crate::c_ast::Printer; use crate::c_ast::*; -pub use crate::diagnostics::Diagnostic; -use c2rust_ast_exporter as ast_exporter; - -use crate::build_files::{emit_build_files, get_build_dir, CrateConfig}; use crate::compile_cmds::get_compile_commands; use crate::convert_type::RESERVED_NAMES; +pub use crate::diagnostics::Diagnostic; pub use crate::translator::ReplaceMode; +use c2rust_ast_exporter as ast_exporter; use std::prelude::v1::Vec; type PragmaVec = Vec<(&'static str, Vec<&'static str>)>; diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 0d9a59326f..6ac5fda45c 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::Path; use std::process::Command; -use c2rust_transpile::{ReplaceMode, TranspilerConfig}; +use c2rust_transpile::{ReplaceMode, TranspilerConfig, GENERATED_RUST_TOOLCHAIN}; fn config() -> TranspilerConfig { TranspilerConfig { @@ -120,7 +120,7 @@ fn transpile(platform: Option<&str>, c_path: &Path) { let rlib_path = format!("lib{crate_name}.rlib"); let status = Command::new("rustc") .args([ - "+nightly-2023-04-15", + &format!("+{GENERATED_RUST_TOOLCHAIN}"), "--crate-type", "lib", "--edition", From b57f81fbc2965bcb23d9381454b305faba618f8d Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 00:06:19 -0800 Subject: [PATCH 03/21] transpile: tests: use `-fsyntax-only` instead of `-c -o /dev/null` Contrary to its naming, `-fsyntax-only` checks semantics, too. It just doesn't emit anything, which is what we want. --- c2rust-transpile/tests/snapshots.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 6ac5fda45c..e866615919 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -51,9 +51,7 @@ fn config() -> TranspilerConfig { fn transpile(platform: Option<&str>, c_path: &Path) { let status = Command::new("clang") .args([ - "-c", - "-o", - "/dev/null", + "-fsyntax-only", "-w", // Disable warnings. ]) .arg(c_path) From a67bffd5a228f77844ae895458a42c03ee1adc31 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 23:32:35 -0800 Subject: [PATCH 04/21] ci: install `zig` for `zig cc` for cross compilation `zig` isn't available through `apt`, but it is in PyPI, so we can install it with `uv`. --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2bfeeb29b..84e50ed4ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,9 @@ jobs: run: | uv venv uv pip install -r ./scripts/requirements.txt + # `zig cc` needed for cross-compilation + uv tool install ziglang + ln -s $(which python-zig) $(dirname $(which python-zig))/zig # rust-cache very carefully caches toolchains and target directories, # based on the job and toolchain and other factors. See From 31309e8e6c3733ff7881e4e1ac9bcc449b38bcce Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 17:27:12 -0800 Subject: [PATCH 05/21] transpile: tests: use `zig cc -###` to look up cross-compilation args For cross-arch compilation, getting the right headers, sysroot, etc. is not, too, difficult, but for cross-os compilation, this is more difficult, as some OSes like macOS restrict these. `zig cc` contains headers for all possible C cross-compilation targets, so we use it to look them up. --- Cargo.lock | 7 + c2rust-transpile/Cargo.toml | 1 + c2rust-transpile/tests/snapshots.rs | 347 +++++++++++++++++++++++++--- 3 files changed, 322 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a734b069f..fddd742670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,6 +493,7 @@ dependencies = [ "serde_bytes", "serde_derive", "serde_json", + "shell-words", "smallvec", "strum", "strum_macros", @@ -2377,6 +2378,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shlex" version = "1.3.0" diff --git a/c2rust-transpile/Cargo.toml b/c2rust-transpile/Cargo.toml index fce3e7cbb4..8187fe4254 100644 --- a/c2rust-transpile/Cargo.toml +++ b/c2rust-transpile/Cargo.toml @@ -45,3 +45,4 @@ llvm-static = ["c2rust-ast-exporter/llvm-static"] [dev-dependencies] insta = { version = "1.43.2", features = ["glob"] } +shell-words = "1.1.0" diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index e866615919..04eab44e76 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -1,9 +1,12 @@ use std::env::current_dir; +use std::fmt::{self, Debug, Display, Formatter}; use std::fs; use std::path::Path; use std::process::Command; +use std::str::from_utf8; use c2rust_transpile::{ReplaceMode, TranspilerConfig, GENERATED_RUST_TOOLCHAIN}; +use tempfile::NamedTempFile; fn config() -> TranspilerConfig { TranspilerConfig { @@ -46,27 +49,311 @@ fn config() -> TranspilerConfig { } } +#[derive(Clone, Copy, PartialEq, Eq)] +enum Arch { + X86_64, + AArch64, +} + +impl Arch { + pub const fn name(&self) -> &'static str { + use Arch::*; + match *self { + X86_64 => "x86_64", + AArch64 => "aarch64", + } + } +} + +impl Display for Arch { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.name()) + } +} + +impl Debug for Arch { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.name()) + } +} + +#[derive(Clone, Copy, PartialEq, Eq)] +enum Os { + Linux, + MacOs, +} + +impl Os { + pub const fn name(&self) -> &'static str { + use Os::*; + match *self { + Linux => "linux", + MacOs => "macos", + } + } +} + +impl Display for Os { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.name()) + } +} + +impl Debug for Os { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.name()) + } +} + +#[derive(Clone, Copy, PartialEq, Eq)] +enum Target { + X86_64UnknownLinuxGnu, + X86_64AppleDarwin, + AArch64UnknownLinuxGnu, + AArch64AppleDarwin, +} + +impl Target { + pub const ALL: &[Self] = &[ + Self::X86_64UnknownLinuxGnu, + Self::X86_64AppleDarwin, + Self::AArch64UnknownLinuxGnu, + Self::AArch64AppleDarwin, + ]; + + pub const fn rust_name(&self) -> &'static str { + use Target::*; + match *self { + X86_64UnknownLinuxGnu => "x86_64-unknown-linux-gnu", + X86_64AppleDarwin => "x86_64-apple-darwin", + AArch64UnknownLinuxGnu => "aarch64-unknown-linux-gnu", + AArch64AppleDarwin => "aarch64-apple-darwin", + } + } + + pub const fn zig_name(&self) -> &'static str { + use Target::*; + match *self { + X86_64UnknownLinuxGnu => "x86_64-linux-gnu", + X86_64AppleDarwin => "x86_64-macos", + AArch64UnknownLinuxGnu => "aarch64-linux-gnu", + AArch64AppleDarwin => "aarch64-macos", + } + } + + pub const fn arch(&self) -> Arch { + use Arch::*; + use Target::*; + match *self { + X86_64UnknownLinuxGnu | X86_64AppleDarwin => X86_64, + AArch64UnknownLinuxGnu | AArch64AppleDarwin => AArch64, + } + } + + pub const fn os(&self) -> Os { + use Os::*; + use Target::*; + match *self { + X86_64UnknownLinuxGnu | AArch64UnknownLinuxGnu => Linux, + X86_64AppleDarwin | AArch64AppleDarwin => MacOs, + } + } +} + +impl Display for Target { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.rust_name()) + } +} + +impl Debug for Target { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.rust_name()) + } +} + +impl From<(Arch, Os)> for Target { + fn from((arch, os): (Arch, Os)) -> Self { + use Arch::*; + use Os::*; + use Target::*; + let target = match (arch, os) { + (X86_64, Linux) => X86_64UnknownLinuxGnu, + (X86_64, MacOs) => X86_64AppleDarwin, + (AArch64, Linux) => AArch64UnknownLinuxGnu, + (AArch64, MacOs) => AArch64AppleDarwin, + }; + assert_eq!(target.arch(), arch); + assert_eq!(target.os(), os); + target + } +} + +impl TryFrom<&str> for Target { + type Error = (); + + fn try_from(value: &str) -> Result { + for &target in Self::ALL { + if target.rust_name() == value { + return Ok(target); + } + } + Err(()) + } +} + +fn parse_cc1_commands(stderr: &str) -> Vec> { + stderr + .split('\n') + .filter_map(|line| { + let cc1 = "\"-cc1\""; + let i = line.find(cc1)?; + let args = &line[i..]; + let args = shell_words::split(args).unwrap(); + Some(args) + }) + .collect() +} + +fn cc1_command_to_driver_command(mut cc1_args: Vec) -> Vec { + let mut driver_args = Vec::new(); + + #[derive(PartialEq, Eq)] + enum Next { + Other, + ResourceDir, + ISystem, + Define, + } + + let mut next = Next::Other; + + for arg in cc1_args.drain(..) { + if next != Next::Other { + next = Next::Other; + driver_args.push(arg); + continue; + } + match arg.as_str() { + "-nostdsysteminc" => { + driver_args.push("-nostdinc".into()); + } + "-nobuiltininc" => { + driver_args.push(arg); + } + "-resource-dir" => { + next = Next::ResourceDir; + driver_args.push(arg); + } + "-isystem" => { + next = Next::ISystem; + driver_args.push(arg); + } + "-D" => { + next = Next::Define; + driver_args.push(arg); + } + _ => {} + } + } + + driver_args +} + +struct TargetArgs { + target: Target, + + /// `\0`-separated. + args: String, +} + +impl TargetArgs { + /// Use `zig cc` to determine the args needed to cross-compile to `target`. + /// `zig cc` is used because it can be otherwise quite difficult + /// to get the right headers for other OSes. + pub fn find(target: Target) -> Self { + let empty_c = NamedTempFile::new().unwrap(); + let empty_o = NamedTempFile::new().unwrap(); + let mut cmd = Command::new("zig"); + cmd.args([ + "cc", + "-target", + target.zig_name(), // + // `-###` will print the cc1 commands. + "-###", + // `-x c` is needed to tell `zig cc` this is a C file, since it isn't a `*.c`. + "-x", + "c", + // Don't use `-fsyntax-only`. `zig cc` doesn't handle it correctly. + // Don't use `-o /dev/null`. `zig cc` doesn't handle it correctly. + "-c", + "-o", + ]) + .args([empty_o.path(), empty_c.path()]); + let output = cmd.output().unwrap(); + let stderr = from_utf8(&output.stderr).unwrap(); + if !output.status.success() { + eprintln!("> {cmd:?}"); + eprintln!("{stderr}") + } + assert!(output.status.success()); + let mut cc1_cmds = parse_cc1_commands(stderr); + // There should only be one cc1 command. + assert!(cc1_cmds.len() == 1); + let cc1_cmd = cc1_cmds.pop().unwrap(); + let driver_cmd = cc1_command_to_driver_command(cc1_cmd); + let args = driver_cmd.join("\0"); + Self { target, args } + } + + pub const fn target(&self) -> Target { + self.target + } + + /// The `zig cc` args needed to cross-compile to [`Self::target`]. + pub const fn zig_cc_args(&self) -> [&str; 2] { + ["-target", self.target().zig_name()] + } + + /// The `clang` args needed to cross-compile to [`Self::target`]. + pub fn clang_args(&self) -> Vec<&str> { + self.args + .split('\0') + .chain([ + "-target", + self.target.zig_name(), + // Undefine `__BLOCKS__` because `c2rust-ast-exporter` doesn't handle them at all. + // macOS headers use `__BLOCKS__` and `^` block pointers. + "-U", + "__BLOCKS__", + ]) + .collect() + } +} + /// `platform` can be any platform-specific string. /// It could be the `target_arch`, `target_os`, some combination, or something else. -fn transpile(platform: Option<&str>, c_path: &Path) { - let status = Command::new("clang") +fn transpile(target: Target, platform: Option<&str>, c_path: &Path) { + let target_args = TargetArgs::find(target); + let o_path = NamedTempFile::new().unwrap(); + let status = Command::new("zig") + .arg("cc") + .args(target_args.zig_cc_args()) .args([ - "-fsyntax-only", "-w", // Disable warnings. + "-c", "-o", // `zig cc` doesn't work with `-fsyntax-only` or `-o /dev/null`. ]) - .arg(c_path) - .status(); - assert!(status.unwrap().success()); + .args([o_path.path(), c_path]) + .status() + .unwrap(); + assert!(status.success()); + + let mut extra_args = target_args.clang_args(); + extra_args.push("-w"); // Disable warnings. let (_temp_dir, temp_path) = c2rust_transpile::create_temp_compile_commands(&[c_path.to_owned()]); - c2rust_transpile::transpile( - config(), - &temp_path, - &[ - "-w", // Disable warnings. - ], - ); + c2rust_transpile::transpile(config(), &temp_path, &extra_args); let cwd = current_dir().unwrap(); let c_path = c_path.strip_prefix(&cwd).unwrap(); // The crate name can't have `.`s in it, so use the file stem. @@ -123,6 +410,8 @@ fn transpile(platform: Option<&str>, c_path: &Path) { "lib", "--edition", edition, + "--target", + target.rust_name(), "--crate-name", crate_name, "-o", @@ -137,38 +426,30 @@ fn transpile(platform: Option<&str>, c_path: &Path) { #[test] fn transpile_all() { - insta::glob!("snapshots/*.c", |x| transpile(None, x)); - // Some things transpile differently on Linux vs. macOS, // as they use `unsigned long` and `unsigned long long` differently for builtins. // This makes snapshot tests trickier, as the output will be OS-dependent. // We handle this by adding OS name to the snapshot result filename. - #[allow(unused)] - let os = "unknown"; - #[cfg(target_os = "linux")] - let os = "linux"; + let os = Os::Linux; #[cfg(target_os = "macos")] - let os = "macos"; + let os = Os::MacOs; // Similarly, some things transpile differently on different architectures. - #[allow(unused)] - let arch = "unknown"; - - #[cfg(target_arch = "x86")] - let arch = "x86"; #[cfg(target_arch = "x86_64")] - let arch = "x86_64"; - #[cfg(target_arch = "arm")] - let arch = "arm"; + let arch = Arch::X86_64; #[cfg(target_arch = "aarch64")] - let arch = "aarch64"; + let arch = Arch::AArch64; + + let target = Target::from((arch, os)); + + insta::glob!("snapshots/*.c", |x| transpile(target, None, x)); - insta::with_settings!({snapshot_suffix => os}, { - insta::glob!("snapshots/os-specific/*.c", |path| transpile(Some(os), path)); + insta::with_settings!({snapshot_suffix => os.name()}, { + insta::glob!("snapshots/os-specific/*.c", |path| transpile(target, Some(os.name()), path)); }); - insta::with_settings!({snapshot_suffix => arch}, { - insta::glob!("snapshots/arch-specific/*.c", |path| transpile(Some(arch), path)); + insta::with_settings!({snapshot_suffix => arch.name()}, { + insta::glob!("snapshots/arch-specific/*.c", |path| transpile(target, Some(arch.name()), path)); }) } From 38616fd7c5e7281a93fc09d66001ba190cf5c98c Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 17:43:26 -0800 Subject: [PATCH 06/21] transpile: tests: find `TargetArgs` for all `Target`s --- c2rust-transpile/tests/snapshots.rs | 78 ++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 04eab44e76..0cfd652bc1 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -1,11 +1,13 @@ use std::env::current_dir; use std::fmt::{self, Debug, Display, Formatter}; use std::fs; +use std::ops::Index; use std::path::Path; use std::process::Command; use std::str::from_utf8; use c2rust_transpile::{ReplaceMode, TranspilerConfig, GENERATED_RUST_TOOLCHAIN}; +use itertools::Itertools; use tempfile::NamedTempFile; fn config() -> TranspilerConfig { @@ -315,26 +317,65 @@ impl TargetArgs { ["-target", self.target().zig_name()] } + pub fn clang_args_iter(&self) -> impl Iterator { + [ + "-target", + self.target.zig_name(), + // Undefine `__BLOCKS__` because `c2rust-ast-exporter` doesn't handle them at all. + // macOS headers use `__BLOCKS__` and `^` block pointers. + "-U", + "__BLOCKS__", + ] + .into_iter() + .chain(self.args.split('\0')) + } + /// The `clang` args needed to cross-compile to [`Self::target`]. pub fn clang_args(&self) -> Vec<&str> { - self.args - .split('\0') - .chain([ - "-target", - self.target.zig_name(), - // Undefine `__BLOCKS__` because `c2rust-ast-exporter` doesn't handle them at all. - // macOS headers use `__BLOCKS__` and `^` block pointers. - "-U", - "__BLOCKS__", - ]) - .collect() + self.clang_args_iter().collect() + } +} + +impl Display for TargetArgs { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + let args = self.clang_args_iter().join(" "); + write!(f, "{args}") + } +} + +struct AllTargetArgs { + all: Vec, +} + +impl AllTargetArgs { + pub fn find() -> Self { + let all = Target::ALL + .into_iter() + .copied() + .map(TargetArgs::find) + .collect(); + Self { all } + } + + pub fn get(&self, target: Target) -> &TargetArgs { + self.all + .iter() + .find(|args| args.target() == target) + .unwrap() + } +} + +impl Index for AllTargetArgs { + type Output = TargetArgs; + + fn index(&self, index: Target) -> &Self::Output { + self.get(index) } } /// `platform` can be any platform-specific string. /// It could be the `target_arch`, `target_os`, some combination, or something else. -fn transpile(target: Target, platform: Option<&str>, c_path: &Path) { - let target_args = TargetArgs::find(target); +fn transpile(target_args: &TargetArgs, platform: Option<&str>, c_path: &Path) { let o_path = NamedTempFile::new().unwrap(); let status = Command::new("zig") .arg("cc") @@ -411,7 +452,7 @@ fn transpile(target: Target, platform: Option<&str>, c_path: &Path) { "--edition", edition, "--target", - target.rust_name(), + target_args.target().rust_name(), "--crate-name", crate_name, "-o", @@ -426,6 +467,8 @@ fn transpile(target: Target, platform: Option<&str>, c_path: &Path) { #[test] fn transpile_all() { + let targets = AllTargetArgs::find(); + // Some things transpile differently on Linux vs. macOS, // as they use `unsigned long` and `unsigned long long` differently for builtins. // This makes snapshot tests trickier, as the output will be OS-dependent. @@ -442,14 +485,15 @@ fn transpile_all() { let arch = Arch::AArch64; let target = Target::from((arch, os)); + let target_args = &targets[target]; - insta::glob!("snapshots/*.c", |x| transpile(target, None, x)); + insta::glob!("snapshots/*.c", |x| transpile(target_args, None, x)); insta::with_settings!({snapshot_suffix => os.name()}, { - insta::glob!("snapshots/os-specific/*.c", |path| transpile(target, Some(os.name()), path)); + insta::glob!("snapshots/os-specific/*.c", |path| transpile(target_args, Some(os.name()), path)); }); insta::with_settings!({snapshot_suffix => arch.name()}, { - insta::glob!("snapshots/arch-specific/*.c", |path| transpile(target, Some(arch.name()), path)); + insta::glob!("snapshots/arch-specific/*.c", |path| transpile(target_args, Some(arch.name()), path)); }) } From e39fef8311ffc04757e9019292010d67bbe01048 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 17:47:23 -0800 Subject: [PATCH 07/21] transpile: tests: make `fn transpile` a method on `struct TargetArgs` --- c2rust-transpile/tests/snapshots.rs | 184 ++++++++++++++-------------- 1 file changed, 93 insertions(+), 91 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 0cfd652bc1..22f7f1e884 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -373,96 +373,98 @@ impl Index for AllTargetArgs { } } -/// `platform` can be any platform-specific string. -/// It could be the `target_arch`, `target_os`, some combination, or something else. -fn transpile(target_args: &TargetArgs, platform: Option<&str>, c_path: &Path) { - let o_path = NamedTempFile::new().unwrap(); - let status = Command::new("zig") - .arg("cc") - .args(target_args.zig_cc_args()) - .args([ - "-w", // Disable warnings. - "-c", "-o", // `zig cc` doesn't work with `-fsyntax-only` or `-o /dev/null`. - ]) - .args([o_path.path(), c_path]) - .status() - .unwrap(); - assert!(status.success()); - - let mut extra_args = target_args.clang_args(); - extra_args.push("-w"); // Disable warnings. - - let (_temp_dir, temp_path) = - c2rust_transpile::create_temp_compile_commands(&[c_path.to_owned()]); - c2rust_transpile::transpile(config(), &temp_path, &extra_args); - let cwd = current_dir().unwrap(); - let c_path = c_path.strip_prefix(&cwd).unwrap(); - // The crate name can't have `.`s in it, so use the file stem. - // This is also why we set it explicitly with `--crate-name`, - // as once we add `.{platform}`, the crate name derived from - // the file name won't be valid anymore. - let crate_name = c_path.file_stem().unwrap().to_str().unwrap(); - let rs_path = c_path.with_extension("rs"); - // We need to move the `.rs` file to a platform-specific name - // so that they don't overwrite each other. - let rs_path = match platform { - None => rs_path, - Some(platform) => { - let platform_rs_path = rs_path.with_extension(format!("{platform}.rs")); - fs::rename(&rs_path, &platform_rs_path).unwrap(); - platform_rs_path +impl TargetArgs { + /// `platform` can be any platform-specific string. + /// It could be the `target_arch`, `target_os`, some combination, or something else. + pub fn transpile(&self, c_path: &Path, platform: Option<&str>) { + let o_path = NamedTempFile::new().unwrap(); + let status = Command::new("zig") + .arg("cc") + .args(self.zig_cc_args()) + .args([ + "-w", // Disable warnings. + "-c", "-o", // `zig cc` doesn't work with `-fsyntax-only` or `-o /dev/null`. + ]) + .args([o_path.path(), c_path]) + .status() + .unwrap(); + assert!(status.success()); + + let mut extra_args = self.clang_args(); + extra_args.push("-w"); // Disable warnings. + + let (_temp_dir, temp_path) = + c2rust_transpile::create_temp_compile_commands(&[c_path.to_owned()]); + c2rust_transpile::transpile(config(), &temp_path, &extra_args); + let cwd = current_dir().unwrap(); + let c_path = c_path.strip_prefix(&cwd).unwrap(); + // The crate name can't have `.`s in it, so use the file stem. + // This is also why we set it explicitly with `--crate-name`, + // as once we add `.{platform}`, the crate name derived from + // the file name won't be valid anymore. + let crate_name = c_path.file_stem().unwrap().to_str().unwrap(); + let rs_path = c_path.with_extension("rs"); + // We need to move the `.rs` file to a platform-specific name + // so that they don't overwrite each other. + let rs_path = match platform { + None => rs_path, + Some(platform) => { + let platform_rs_path = rs_path.with_extension(format!("{platform}.rs")); + fs::rename(&rs_path, &platform_rs_path).unwrap(); + platform_rs_path + } + }; + + let edition = "2021"; + + let status = Command::new("rustfmt") + .args(["--edition", edition]) + .arg(&rs_path) + .status(); + assert!(status.unwrap().success()); + + let rs = fs::read_to_string(&rs_path).unwrap(); + let debug_expr = format!("cat {}", rs_path.display()); + + let snapshot_name = match platform { + None => "transpile".into(), + Some(platform) => format!("transpile-{platform}"), + }; + insta::assert_snapshot!(snapshot_name, &rs, &debug_expr); + + // Using rustc itself to build snapshots that reference libc is difficult because we don't know + // the appropriate --extern libc=/path/to/liblibc-XXXXXXXXXXXXXXXX.rlib to pass. Skip for now, + // as we've already compared the literal text. + if rs.contains("libc::") { + eprintln!( + "warning: skipping compiling {} with rustc since it depends on libc", + rs_path.display() + ); + return; } - }; - - let edition = "2021"; - - let status = Command::new("rustfmt") - .args(["--edition", edition]) - .arg(&rs_path) - .status(); - assert!(status.unwrap().success()); - - let rs = fs::read_to_string(&rs_path).unwrap(); - let debug_expr = format!("cat {}", rs_path.display()); - - let snapshot_name = match platform { - None => "transpile".into(), - Some(platform) => format!("transpile-{platform}"), - }; - insta::assert_snapshot!(snapshot_name, &rs, &debug_expr); - - // Using rustc itself to build snapshots that reference libc is difficult because we don't know - // the appropriate --extern libc=/path/to/liblibc-XXXXXXXXXXXXXXXX.rlib to pass. Skip for now, - // as we've already compared the literal text. - if rs.contains("libc::") { - eprintln!( - "warning: skipping compiling {} with rustc since it depends on libc", - rs_path.display() - ); - return; - } - // Don't need to worry about platform clashes here, as this is immediately deleted. - let rlib_path = format!("lib{crate_name}.rlib"); - let status = Command::new("rustc") - .args([ - &format!("+{GENERATED_RUST_TOOLCHAIN}"), - "--crate-type", - "lib", - "--edition", - edition, - "--target", - target_args.target().rust_name(), - "--crate-name", - crate_name, - "-o", - &rlib_path, - "-Awarnings", // Disable warnings. - ]) - .arg(&rs_path) - .status(); - assert!(status.unwrap().success()); - fs::remove_file(&rlib_path).unwrap(); + // Don't need to worry about platform clashes here, as this is immediately deleted. + let rlib_path = format!("lib{crate_name}.rlib"); + let status = Command::new("rustc") + .args([ + &format!("+{GENERATED_RUST_TOOLCHAIN}"), + "--crate-type", + "lib", + "--edition", + edition, + "--target", + self.target().rust_name(), + "--crate-name", + crate_name, + "-o", + &rlib_path, + "-Awarnings", // Disable warnings. + ]) + .arg(&rs_path) + .status(); + assert!(status.unwrap().success()); + fs::remove_file(&rlib_path).unwrap(); + } } #[test] @@ -487,13 +489,13 @@ fn transpile_all() { let target = Target::from((arch, os)); let target_args = &targets[target]; - insta::glob!("snapshots/*.c", |x| transpile(target_args, None, x)); + insta::glob!("snapshots/*.c", |x| target_args.transpile(x, None)); insta::with_settings!({snapshot_suffix => os.name()}, { - insta::glob!("snapshots/os-specific/*.c", |path| transpile(target_args, Some(os.name()), path)); + insta::glob!("snapshots/os-specific/*.c", |path| target_args.transpile(path, Some(os.name()))); }); insta::with_settings!({snapshot_suffix => arch.name()}, { - insta::glob!("snapshots/arch-specific/*.c", |path| transpile(target_args, Some(arch.name()), path)); + insta::glob!("snapshots/arch-specific/*.c", |path| target_args.transpile(path, Some(arch.name()))); }) } From e76b287052a1d900c0e811403dfdd96f1a5be97e Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 18:02:44 -0800 Subject: [PATCH 08/21] transpile: tests: transpile snapshots on all targets For platform-specific snapshots, test in groups of all targets that match that platform (arch/os). --- .github/workflows/ci.yml | 8 +++ c2rust-transpile/tests/snapshots.rs | 50 ++++++++----------- .../snapshots__transpile-macos@types.c.snap | 9 ++-- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84e50ed4ec..b20a6b05f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,14 @@ jobs: # Run after `rust-cache` so that this is cached. - run: rustup component add rustfmt rustc-dev + - name: Install generated Rust targets + run: | + rustup +nightly-2023-04-15 target add \ + x86_64-unknown-linux-gnu \ + x86_64-apple-darwin \ + aarch64-unknown-linux-gnu \ + aarch64-apple-darwin + - name: cargo fmt --check run: | export RUSTFLAGS="$RUSTFLAGS -D warnings" diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 22f7f1e884..c580ccbdbe 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::env::current_dir; use std::fmt::{self, Debug, Display, Formatter}; use std::fs; @@ -376,7 +377,7 @@ impl Index for AllTargetArgs { impl TargetArgs { /// `platform` can be any platform-specific string. /// It could be the `target_arch`, `target_os`, some combination, or something else. - pub fn transpile(&self, c_path: &Path, platform: Option<&str>) { + pub fn transpile(&self, c_path: &Path, platform: Option<&'static str>) { let o_path = NamedTempFile::new().unwrap(); let status = Command::new("zig") .arg("cc") @@ -467,35 +468,28 @@ impl TargetArgs { } } +impl AllTargetArgs { + pub fn transpile(&self, c_path: &Path, get_platform: impl Fn(Target) -> Option<&'static str>) { + let mut platforms = HashMap::, Vec<&TargetArgs>>::new(); + for target in self.all.iter() { + let platform = get_platform(target.target()); + platforms.entry(platform).or_default().push(target); + } + for (platform, targets) in platforms { + for target_args in targets { + target_args.transpile(c_path, platform); + } + } + } +} + #[test] fn transpile_all() { let targets = AllTargetArgs::find(); - // Some things transpile differently on Linux vs. macOS, - // as they use `unsigned long` and `unsigned long long` differently for builtins. - // This makes snapshot tests trickier, as the output will be OS-dependent. - // We handle this by adding OS name to the snapshot result filename. - #[cfg(target_os = "linux")] - let os = Os::Linux; - #[cfg(target_os = "macos")] - let os = Os::MacOs; - - // Similarly, some things transpile differently on different architectures. - #[cfg(target_arch = "x86_64")] - let arch = Arch::X86_64; - #[cfg(target_arch = "aarch64")] - let arch = Arch::AArch64; - - let target = Target::from((arch, os)); - let target_args = &targets[target]; - - insta::glob!("snapshots/*.c", |x| target_args.transpile(x, None)); - - insta::with_settings!({snapshot_suffix => os.name()}, { - insta::glob!("snapshots/os-specific/*.c", |path| target_args.transpile(path, Some(os.name()))); - }); - - insta::with_settings!({snapshot_suffix => arch.name()}, { - insta::glob!("snapshots/arch-specific/*.c", |path| target_args.transpile(path, Some(arch.name()))); - }) + insta::glob!("snapshots/*.c", |path| targets.transpile(path, |_| None)); + insta::glob!("snapshots/os-specific/*.c", |path| targets + .transpile(path, |target| Some(target.os().name()))); + insta::glob!("snapshots/arch-specific/*.c", |path| targets + .transpile(path, |target| Some(target.arch().name()))); } diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@types.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@types.c.snap index 7f4315b098..a672d87a22 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@types.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@types.c.snap @@ -1,8 +1,7 @@ --- source: c2rust-transpile/tests/snapshots.rs -assertion_line: 69 -expression: cat tests/snapshots/platform-specific/types.rs -input_file: c2rust-transpile/tests/snapshots/platform-specific/types.c +expression: cat tests/snapshots/os-specific/types.macos.rs +input_file: c2rust-transpile/tests/snapshots/os-specific/types.c --- #![allow( dead_code, @@ -12,7 +11,6 @@ input_file: c2rust-transpile/tests/snapshots/platform-specific/types.c unused_assignments, unused_mut )] -pub type __darwin_ptrdiff_t = isize; pub type __darwin_size_t = usize; pub type __darwin_ssize_t = isize; pub type int8_t = i8; @@ -28,7 +26,7 @@ pub type uint32_t = u32; pub type uint64_t = u64; pub type intmax_t = ::libc::intmax_t; pub type uintmax_t = ::libc::uintmax_t; -pub type ptrdiff_t = __darwin_ptrdiff_t; +pub type ptrdiff_t = isize; pub type ssize_t = __darwin_ssize_t; #[no_mangle] pub static mut intvar: ::core::ffi::c_int = 0 as ::core::ffi::c_int; @@ -62,4 +60,3 @@ pub static mut int64var: int64_t = 0 as int64_t; pub static mut maxvar: intmax_t = 0 as intmax_t; #[no_mangle] pub static mut umaxvar: uintmax_t = 0 as uintmax_t; - From 82a1c8800510a66cb9703e22a1f381f776e0f7c8 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 19:11:18 -0800 Subject: [PATCH 09/21] transpile: tests: first check if all `rustup target`s are installed --- c2rust-transpile/tests/snapshots.rs | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index c580ccbdbe..11852befd0 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::env::current_dir; use std::fmt::{self, Debug, Display, Formatter}; use std::fs; @@ -469,6 +469,33 @@ impl TargetArgs { } impl AllTargetArgs { + pub fn check_if_targets_are_installed(&self) { + let output = Command::new("rustup") + .args([ + &format!("+{GENERATED_RUST_TOOLCHAIN}"), + "target", + "list", + "--installed", + ]) + .output() + .unwrap(); + assert!(output.status.success()); + let installed_targets = from_utf8(&output.stdout) + .unwrap() + .trim() + .split_whitespace() + .collect::>(); + let uninstalled_targets = self + .all + .iter() + .map(|args| args.target().rust_name()) + .filter(|target| !installed_targets.contains(target)) + .join(" "); + if !uninstalled_targets.is_empty() { + panic!("not all targets installed, run:\nrustup +{GENERATED_RUST_TOOLCHAIN} target add {uninstalled_targets}\n"); + } + } + pub fn transpile(&self, c_path: &Path, get_platform: impl Fn(Target) -> Option<&'static str>) { let mut platforms = HashMap::, Vec<&TargetArgs>>::new(); for target in self.all.iter() { @@ -486,6 +513,7 @@ impl AllTargetArgs { #[test] fn transpile_all() { let targets = AllTargetArgs::find(); + targets.check_if_targets_are_installed(); insta::glob!("snapshots/*.c", |path| targets.transpile(path, |_| None)); insta::glob!("snapshots/os-specific/*.c", |path| targets From 30365e6aa38320f2bc8f9693065cf43bf61286bf Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 19:49:34 -0800 Subject: [PATCH 10/21] transpile: tests: print which file we're transpiling to which target --- c2rust-transpile/tests/snapshots.rs | 44 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 11852befd0..8fa55eebce 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -378,6 +378,28 @@ impl TargetArgs { /// `platform` can be any platform-specific string. /// It could be the `target_arch`, `target_os`, some combination, or something else. pub fn transpile(&self, c_path: &Path, platform: Option<&'static str>) { + let cwd = current_dir().unwrap(); + let c_path = c_path.strip_prefix(&cwd).unwrap(); + // The crate name can't have `.`s in it, so use the file stem. + // This is also why we set it explicitly with `--crate-name`, + // as once we add `.{platform}`, the crate name derived from + // the file name won't be valid anymore. + let crate_name = c_path.file_stem().unwrap().to_str().unwrap(); + let original_rs_path = c_path.with_extension("rs"); + // We need to move the `.rs` file to a platform-specific name + // so that they don't overwrite each other. + let rs_path = match platform { + None => original_rs_path.clone(), + Some(platform) => original_rs_path.with_extension(format!("{platform}.rs")), + }; + + { + let c_path = c_path.display(); + let rs_path = rs_path.display(); + let target = self.target().rust_name(); + println!("transpiling {c_path} to {rs_path} for --target {target}"); + } + let o_path = NamedTempFile::new().unwrap(); let status = Command::new("zig") .arg("cc") @@ -397,24 +419,10 @@ impl TargetArgs { let (_temp_dir, temp_path) = c2rust_transpile::create_temp_compile_commands(&[c_path.to_owned()]); c2rust_transpile::transpile(config(), &temp_path, &extra_args); - let cwd = current_dir().unwrap(); - let c_path = c_path.strip_prefix(&cwd).unwrap(); - // The crate name can't have `.`s in it, so use the file stem. - // This is also why we set it explicitly with `--crate-name`, - // as once we add `.{platform}`, the crate name derived from - // the file name won't be valid anymore. - let crate_name = c_path.file_stem().unwrap().to_str().unwrap(); - let rs_path = c_path.with_extension("rs"); - // We need to move the `.rs` file to a platform-specific name - // so that they don't overwrite each other. - let rs_path = match platform { - None => rs_path, - Some(platform) => { - let platform_rs_path = rs_path.with_extension(format!("{platform}.rs")); - fs::rename(&rs_path, &platform_rs_path).unwrap(); - platform_rs_path - } - }; + + if platform.is_some() { + fs::rename(&original_rs_path, &rs_path).unwrap(); + } let edition = "2021"; From 88ac507eaf0a25248839ef159179fa7b264dd0f0 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 19:50:56 -0800 Subject: [PATCH 11/21] transpile: tests: switch from zig target to rust target for clang target For Rust targets, they seem to match the clang target, at least for all of the targets we're testing now. --- c2rust-transpile/tests/snapshots.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 8fa55eebce..b2e2bfa4b3 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -134,6 +134,11 @@ impl Target { } } + pub const fn clang_name(&self) -> &'static str { + // These seem to be the same, but there may be some differences if we add more targets. + self.rust_name() + } + pub const fn zig_name(&self) -> &'static str { use Target::*; match *self { @@ -321,7 +326,7 @@ impl TargetArgs { pub fn clang_args_iter(&self) -> impl Iterator { [ "-target", - self.target.zig_name(), + self.target.clang_name(), // Undefine `__BLOCKS__` because `c2rust-ast-exporter` doesn't handle them at all. // macOS headers use `__BLOCKS__` and `^` block pointers. "-U", From 94ea66d76abb6e516bb65a8591b802d4b31a160b Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 19:57:52 -0800 Subject: [PATCH 12/21] transpile: tests: make `AllTargetsArgs` take an explicit list of targets, not necessarily all --- c2rust-transpile/tests/snapshots.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index b2e2bfa4b3..7ac7aaedab 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -354,10 +354,16 @@ struct AllTargetArgs { } impl AllTargetArgs { - pub fn find() -> Self { - let all = Target::ALL + pub fn find(targets: &[T]) -> Self + where + T: Copy, + Target: TryFrom, + >::Error: Debug, + { + let all = targets .into_iter() .copied() + .map(|target| Target::try_from(target).unwrap()) .map(TargetArgs::find) .collect(); Self { all } @@ -525,7 +531,12 @@ impl AllTargetArgs { #[test] fn transpile_all() { - let targets = AllTargetArgs::find(); + let targets = AllTargetArgs::find(&[ + "x86_64-unknown-linux-gnu", + "x86_64-apple-darwin", + "aarch64-unknown-linux-gnu", + "aarch64-apple-darwin", + ]); targets.check_if_targets_are_installed(); insta::glob!("snapshots/*.c", |path| targets.transpile(path, |_| None)); From ac4c3622814b18f8403689e40257e58933060c2a Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 19:58:09 -0800 Subject: [PATCH 13/21] transpile: tests: rename `AllTargetArgs` to `Targets` since it's no longer necessarily all --- c2rust-transpile/tests/snapshots.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 7ac7aaedab..053a2cf2b3 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -349,11 +349,11 @@ impl Display for TargetArgs { } } -struct AllTargetArgs { +struct Targets { all: Vec, } -impl AllTargetArgs { +impl Targets { pub fn find(targets: &[T]) -> Self where T: Copy, @@ -377,7 +377,7 @@ impl AllTargetArgs { } } -impl Index for AllTargetArgs { +impl Index for Targets { type Output = TargetArgs; fn index(&self, index: Target) -> &Self::Output { @@ -487,7 +487,7 @@ impl TargetArgs { } } -impl AllTargetArgs { +impl Targets { pub fn check_if_targets_are_installed(&self) { let output = Command::new("rustup") .args([ @@ -531,7 +531,7 @@ impl AllTargetArgs { #[test] fn transpile_all() { - let targets = AllTargetArgs::find(&[ + let targets = Targets::find(&[ "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "aarch64-unknown-linux-gnu", From ab1e0054649e1ec2a05fafe826571a6025f8a8c9 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 19:59:22 -0800 Subject: [PATCH 14/21] transpile: tests: add `x86` and `arm` `linux` targets, but don't test them yet (32-bit has differences) --- .github/workflows/ci.yml | 4 +++- c2rust-transpile/tests/snapshots.rs | 31 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b20a6b05f6..b55d6bd5da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,9 @@ jobs: x86_64-unknown-linux-gnu \ x86_64-apple-darwin \ aarch64-unknown-linux-gnu \ - aarch64-apple-darwin + aarch64-apple-darwin \ + i686-unknown-linux-gnu \ + armv7-unknown-linux-gnueabihf - name: cargo fmt --check run: | diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 053a2cf2b3..1905a45f23 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -54,7 +54,9 @@ fn config() -> TranspilerConfig { #[derive(Clone, Copy, PartialEq, Eq)] enum Arch { + X86, X86_64, + Arm, AArch64, } @@ -62,7 +64,9 @@ impl Arch { pub const fn name(&self) -> &'static str { use Arch::*; match *self { + X86 => "x86", X86_64 => "x86_64", + Arm => "arm", AArch64 => "aarch64", } } @@ -114,6 +118,8 @@ enum Target { X86_64AppleDarwin, AArch64UnknownLinuxGnu, AArch64AppleDarwin, + I686UnknownLinuxGnu, + ArmV7UnknownLinuxGnueabihf, } impl Target { @@ -122,6 +128,8 @@ impl Target { Self::X86_64AppleDarwin, Self::AArch64UnknownLinuxGnu, Self::AArch64AppleDarwin, + Self::I686UnknownLinuxGnu, + Self::ArmV7UnknownLinuxGnueabihf, ]; pub const fn rust_name(&self) -> &'static str { @@ -131,6 +139,8 @@ impl Target { X86_64AppleDarwin => "x86_64-apple-darwin", AArch64UnknownLinuxGnu => "aarch64-unknown-linux-gnu", AArch64AppleDarwin => "aarch64-apple-darwin", + I686UnknownLinuxGnu => "i686-unknown-linux-gnu", + ArmV7UnknownLinuxGnueabihf => "armv7-unknown-linux-gnueabihf", } } @@ -146,6 +156,8 @@ impl Target { X86_64AppleDarwin => "x86_64-macos", AArch64UnknownLinuxGnu => "aarch64-linux-gnu", AArch64AppleDarwin => "aarch64-macos", + I686UnknownLinuxGnu => "x86-linux-gnu", + ArmV7UnknownLinuxGnueabihf => "arm-linux-gnueabihf", } } @@ -155,6 +167,8 @@ impl Target { match *self { X86_64UnknownLinuxGnu | X86_64AppleDarwin => X86_64, AArch64UnknownLinuxGnu | AArch64AppleDarwin => AArch64, + I686UnknownLinuxGnu => X86, + ArmV7UnknownLinuxGnueabihf => Arm, } } @@ -162,7 +176,10 @@ impl Target { use Os::*; use Target::*; match *self { - X86_64UnknownLinuxGnu | AArch64UnknownLinuxGnu => Linux, + X86_64UnknownLinuxGnu + | AArch64UnknownLinuxGnu + | I686UnknownLinuxGnu + | ArmV7UnknownLinuxGnueabihf => Linux, X86_64AppleDarwin | AArch64AppleDarwin => MacOs, } } @@ -180,8 +197,10 @@ impl Debug for Target { } } -impl From<(Arch, Os)> for Target { - fn from((arch, os): (Arch, Os)) -> Self { +impl TryFrom<(Arch, Os)> for Target { + type Error = (); + + fn try_from((arch, os): (Arch, Os)) -> Result { use Arch::*; use Os::*; use Target::*; @@ -190,10 +209,14 @@ impl From<(Arch, Os)> for Target { (X86_64, MacOs) => X86_64AppleDarwin, (AArch64, Linux) => AArch64UnknownLinuxGnu, (AArch64, MacOs) => AArch64AppleDarwin, + (X86, Linux) => I686UnknownLinuxGnu, + (X86, MacOs) => return Err(()), + (Arm, Linux) => ArmV7UnknownLinuxGnueabihf, + (Arm, MacOs) => return Err(()), }; assert_eq!(target.arch(), arch); assert_eq!(target.os(), os); - target + Ok(target) } } From b030af36d3cb9835ad477b2c12efec6df0e92e38 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 22:43:41 -0800 Subject: [PATCH 15/21] transpile: tests: add `riscv64` target, but don't test it yet (riscv builtin types are unhandled) --- .github/workflows/ci.yml | 3 ++- c2rust-transpile/tests/snapshots.rs | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b55d6bd5da..d1283dc1de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,8 @@ jobs: aarch64-unknown-linux-gnu \ aarch64-apple-darwin \ i686-unknown-linux-gnu \ - armv7-unknown-linux-gnueabihf + armv7-unknown-linux-gnueabihf \ + riscv64gc-unknown-linux-gnu - name: cargo fmt --check run: | diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 1905a45f23..623717089d 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -58,6 +58,7 @@ enum Arch { X86_64, Arm, AArch64, + RiscV64, } impl Arch { @@ -68,6 +69,7 @@ impl Arch { X86_64 => "x86_64", Arm => "arm", AArch64 => "aarch64", + RiscV64 => "riscv64", } } } @@ -120,6 +122,7 @@ enum Target { AArch64AppleDarwin, I686UnknownLinuxGnu, ArmV7UnknownLinuxGnueabihf, + RiscV64GcUnknownLinuxGnu, } impl Target { @@ -130,6 +133,7 @@ impl Target { Self::AArch64AppleDarwin, Self::I686UnknownLinuxGnu, Self::ArmV7UnknownLinuxGnueabihf, + Self::RiscV64GcUnknownLinuxGnu, ]; pub const fn rust_name(&self) -> &'static str { @@ -141,12 +145,16 @@ impl Target { AArch64AppleDarwin => "aarch64-apple-darwin", I686UnknownLinuxGnu => "i686-unknown-linux-gnu", ArmV7UnknownLinuxGnueabihf => "armv7-unknown-linux-gnueabihf", + RiscV64GcUnknownLinuxGnu => "riscv64gc-unknown-linux-gnu", } } pub const fn clang_name(&self) -> &'static str { - // These seem to be the same, but there may be some differences if we add more targets. - self.rust_name() + use Target::*; + match *self { + RiscV64GcUnknownLinuxGnu => "riscv64-unknown-linux-gnu", + _ => self.rust_name(), + } } pub const fn zig_name(&self) -> &'static str { @@ -158,6 +166,7 @@ impl Target { AArch64AppleDarwin => "aarch64-macos", I686UnknownLinuxGnu => "x86-linux-gnu", ArmV7UnknownLinuxGnueabihf => "arm-linux-gnueabihf", + RiscV64GcUnknownLinuxGnu => "riscv64-linux-gnu", } } @@ -169,6 +178,7 @@ impl Target { AArch64UnknownLinuxGnu | AArch64AppleDarwin => AArch64, I686UnknownLinuxGnu => X86, ArmV7UnknownLinuxGnueabihf => Arm, + RiscV64GcUnknownLinuxGnu => RiscV64, } } @@ -179,7 +189,8 @@ impl Target { X86_64UnknownLinuxGnu | AArch64UnknownLinuxGnu | I686UnknownLinuxGnu - | ArmV7UnknownLinuxGnueabihf => Linux, + | ArmV7UnknownLinuxGnueabihf + | RiscV64GcUnknownLinuxGnu => Linux, X86_64AppleDarwin | AArch64AppleDarwin => MacOs, } } @@ -210,9 +221,9 @@ impl TryFrom<(Arch, Os)> for Target { (AArch64, Linux) => AArch64UnknownLinuxGnu, (AArch64, MacOs) => AArch64AppleDarwin, (X86, Linux) => I686UnknownLinuxGnu, - (X86, MacOs) => return Err(()), (Arm, Linux) => ArmV7UnknownLinuxGnueabihf, - (Arm, MacOs) => return Err(()), + (RiscV64, Linux) => RiscV64GcUnknownLinuxGnu, + (X86 | Arm | RiscV64, MacOs) => return Err(()), }; assert_eq!(target.arch(), arch); assert_eq!(target.os(), os); From a16922c3a2f18845e106f126bbe9333ca1cb5524 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 22:49:35 -0800 Subject: [PATCH 16/21] transpile: tests: use `""` instead of `None` for `platform` --- c2rust-transpile/tests/snapshots.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 623717089d..7dba012b86 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -422,7 +422,7 @@ impl Index for Targets { impl TargetArgs { /// `platform` can be any platform-specific string. /// It could be the `target_arch`, `target_os`, some combination, or something else. - pub fn transpile(&self, c_path: &Path, platform: Option<&'static str>) { + pub fn transpile(&self, c_path: &Path, platform: &'static str) { let cwd = current_dir().unwrap(); let c_path = c_path.strip_prefix(&cwd).unwrap(); // The crate name can't have `.`s in it, so use the file stem. @@ -434,8 +434,8 @@ impl TargetArgs { // We need to move the `.rs` file to a platform-specific name // so that they don't overwrite each other. let rs_path = match platform { - None => original_rs_path.clone(), - Some(platform) => original_rs_path.with_extension(format!("{platform}.rs")), + "" => original_rs_path.clone(), + _ => original_rs_path.with_extension(format!("{platform}.rs")), }; { @@ -465,7 +465,7 @@ impl TargetArgs { c2rust_transpile::create_temp_compile_commands(&[c_path.to_owned()]); c2rust_transpile::transpile(config(), &temp_path, &extra_args); - if platform.is_some() { + if !platform.is_empty() { fs::rename(&original_rs_path, &rs_path).unwrap(); } @@ -481,8 +481,8 @@ impl TargetArgs { let debug_expr = format!("cat {}", rs_path.display()); let snapshot_name = match platform { - None => "transpile".into(), - Some(platform) => format!("transpile-{platform}"), + "" => "transpile".into(), + _ => format!("transpile-{platform}"), }; insta::assert_snapshot!(snapshot_name, &rs, &debug_expr); @@ -549,8 +549,8 @@ impl Targets { } } - pub fn transpile(&self, c_path: &Path, get_platform: impl Fn(Target) -> Option<&'static str>) { - let mut platforms = HashMap::, Vec<&TargetArgs>>::new(); + pub fn transpile(&self, c_path: &Path, get_platform: impl Fn(Target) -> &'static str) { + let mut platforms = HashMap::<&'static str, Vec<&TargetArgs>>::new(); for target in self.all.iter() { let platform = get_platform(target.target()); platforms.entry(platform).or_default().push(target); @@ -573,9 +573,9 @@ fn transpile_all() { ]); targets.check_if_targets_are_installed(); - insta::glob!("snapshots/*.c", |path| targets.transpile(path, |_| None)); + insta::glob!("snapshots/*.c", |path| targets.transpile(path, |_| "")); insta::glob!("snapshots/os-specific/*.c", |path| targets - .transpile(path, |target| Some(target.os().name()))); + .transpile(path, |target| target.os().name())); insta::glob!("snapshots/arch-specific/*.c", |path| targets - .transpile(path, |target| Some(target.arch().name()))); + .transpile(path, |target| target.arch().name())); } From 76dc388a49ec23844b8c255fec6995d1d5199c93 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 22:52:15 -0800 Subject: [PATCH 17/21] transpile: tests: change `fn Targets::transpile`'s `platform` to `Into>` --- c2rust-transpile/tests/snapshots.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 7dba012b86..7d8e00386c 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::collections::{HashMap, HashSet}; use std::env::current_dir; use std::fmt::{self, Debug, Display, Formatter}; @@ -422,7 +423,7 @@ impl Index for Targets { impl TargetArgs { /// `platform` can be any platform-specific string. /// It could be the `target_arch`, `target_os`, some combination, or something else. - pub fn transpile(&self, c_path: &Path, platform: &'static str) { + pub fn transpile(&self, c_path: &Path, platform: &str) { let cwd = current_dir().unwrap(); let c_path = c_path.strip_prefix(&cwd).unwrap(); // The crate name can't have `.`s in it, so use the file stem. @@ -549,15 +550,18 @@ impl Targets { } } - pub fn transpile(&self, c_path: &Path, get_platform: impl Fn(Target) -> &'static str) { - let mut platforms = HashMap::<&'static str, Vec<&TargetArgs>>::new(); + pub fn transpile<'a, P>(&self, c_path: &Path, get_platform: impl Fn(Target) -> P) + where + P: Into>, + { + let mut platforms = HashMap::, Vec<&TargetArgs>>::new(); for target in self.all.iter() { let platform = get_platform(target.target()); - platforms.entry(platform).or_default().push(target); + platforms.entry(platform.into()).or_default().push(target); } for (platform, targets) in platforms { for target_args in targets { - target_args.transpile(c_path, platform); + target_args.transpile(c_path, &platform); } } } From 03948fcd866724ab846bcb00f197abd534d36d39 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 23:16:08 -0800 Subject: [PATCH 18/21] transpile: tests: enable `x86` and `arm` snapshots Some of these tests (`macros.c` and `rotate.c`) had to be further disambiguated in `ptr-width-specific` and `os-ptr-width-specific`. `vm_x86.c` also didn't compile after transpilation on `x86` due to an assembly error, so that's now commented out for now with a TODO. --- c2rust-transpile/tests/snapshots.rs | 18 +++++ .../tests/snapshots/arch-specific/vm_x86.c | 15 ++-- c2rust-transpile/tests/snapshots/macros.c | 3 - .../snapshots/os-ptr-width-specific/dummy.c | 0 .../rotate.c | 0 .../snapshots/ptr-width-specific/dummy.c | 0 .../snapshots/ptr-width-specific/macros.c | 4 ++ .../snapshots__transpile-32@dummy.c.snap | 13 ++++ .../snapshots__transpile-32@macros.c.snap | 19 +++++ .../snapshots__transpile-64@dummy.c.snap | 13 ++++ .../snapshots__transpile-64@macros.c.snap | 19 +++++ ...snapshots__transpile-aarch64@vm_x86.c.snap | 2 +- .../snapshots__transpile-arm@dummy.c.snap | 13 ++++ .../snapshots__transpile-arm@spin.c.snap | 22 ++++++ .../snapshots__transpile-arm@vm_x86.c.snap | 71 +++++++++++++++++++ ...snapshots__transpile-linux-32@dummy.c.snap | 13 ++++ ...apshots__transpile-linux-32@rotate.c.snap} | 4 +- ...snapshots__transpile-linux-64@dummy.c.snap | 13 ++++ ...apshots__transpile-linux-64@rotate.c.snap} | 4 +- .../snapshots__transpile-linux@types.c.snap | 6 +- ...snapshots__transpile-macos-64@dummy.c.snap | 13 ++++ ...napshots__transpile-macos-64@rotate.c.snap | 25 +++++++ .../snapshots__transpile-x86@dummy.c.snap | 13 ++++ .../snapshots__transpile-x86@spin.c.snap | 22 ++++++ .../snapshots__transpile-x86@vm_x86.c.snap | 71 +++++++++++++++++++ ...pshots__transpile@incomplete_arrays.c.snap | 2 - .../snapshots__transpile@macros.c.snap | 6 -- 27 files changed, 378 insertions(+), 26 deletions(-) create mode 100644 c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c rename c2rust-transpile/tests/snapshots/{os-specific => os-ptr-width-specific}/rotate.c (100%) create mode 100644 c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c create mode 100644 c2rust-transpile/tests/snapshots/ptr-width-specific/macros.c create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-32@macros.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-64@macros.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-arm@spin.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-arm@vm_x86.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-macos@rotate.c.snap => snapshots__transpile-linux-32@rotate.c.snap} (80%) create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux@rotate.c.snap => snapshots__transpile-linux-64@rotate.c.snap} (83%) create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@rotate.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-x86@spin.c.snap create mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-x86@vm_x86.c.snap diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 7d8e00386c..203ca42c4b 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -73,6 +73,14 @@ impl Arch { RiscV64 => "riscv64", } } + + pub const fn ptr_width(&self) -> u8 { + use Arch::*; + match *self { + X86 | Arm => 32, + X86_64 | AArch64 | RiscV64 => 64, + } + } } impl Display for Arch { @@ -574,6 +582,8 @@ fn transpile_all() { "x86_64-apple-darwin", "aarch64-unknown-linux-gnu", "aarch64-apple-darwin", + "i686-unknown-linux-gnu", + "armv7-unknown-linux-gnueabihf", ]); targets.check_if_targets_are_installed(); @@ -582,4 +592,12 @@ fn transpile_all() { .transpile(path, |target| target.os().name())); insta::glob!("snapshots/arch-specific/*.c", |path| targets .transpile(path, |target| target.arch().name())); + insta::glob!("snapshots/ptr-width-specific/*.c", |path| targets + .transpile(path, |target| format!("{}", target.arch().ptr_width()))); + insta::glob!("snapshots/os-ptr-width-specific/*.c", |path| targets + .transpile(path, |target| format!( + "{}-{}", + target.os(), + target.arch().ptr_width() + ))); } diff --git a/c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c b/c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c index d5807dcf13..da87436634 100644 --- a/c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c +++ b/c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c @@ -76,12 +76,15 @@ int VM_CallCompiled(vm_t *vm, int *args) : "cc", "memory", "%rax", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r11" ); #elif __i386__ - __asm__ volatile( - "calll *%3\n" - : "+S" (programStack), "+D" (opStack), "+b" (opStackOfs) - : "g" (entryPoint) - : "cc", "memory", "%eax", "%ecx", "%edx" - ); + // TODO transpilation is broken: + // `unknown use of instruction mnemonic without a size suffix` on the `mov`. + + // __asm__ volatile( + // "calll *%3\n" + // : "+S" (programStack), "+D" (opStack), "+b" (opStackOfs) + // : "g" (entryPoint) + // : "cc", "memory", "%eax", "%ecx", "%edx" + // ); #endif if(opStackOfs != 1 || *opStack != 0xDEADBEEF) diff --git a/c2rust-transpile/tests/snapshots/macros.c b/c2rust-transpile/tests/snapshots/macros.c index ec07af1bb8..e38d845c98 100644 --- a/c2rust-transpile/tests/snapshots/macros.c +++ b/c2rust-transpile/tests/snapshots/macros.c @@ -1,6 +1,5 @@ #include #include -#include struct S { int i; @@ -385,8 +384,6 @@ int local_fn(void) { return 1234; } int use_local_value(void) { return LOCAL_VALUE; } -bool use_portable_type(uintptr_t len) { return len <= UINTPTR_MAX / 2; } - // From `curl`'s `curl_ntlm_core.c`. struct ntlmdata { diff --git a/c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c b/c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/c2rust-transpile/tests/snapshots/os-specific/rotate.c b/c2rust-transpile/tests/snapshots/os-ptr-width-specific/rotate.c similarity index 100% rename from c2rust-transpile/tests/snapshots/os-specific/rotate.c rename to c2rust-transpile/tests/snapshots/os-ptr-width-specific/rotate.c diff --git a/c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c b/c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/c2rust-transpile/tests/snapshots/ptr-width-specific/macros.c b/c2rust-transpile/tests/snapshots/ptr-width-specific/macros.c new file mode 100644 index 0000000000..e5d498b134 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/ptr-width-specific/macros.c @@ -0,0 +1,4 @@ +#include +#include + +bool use_portable_type(uintptr_t len) { return len <= UINTPTR_MAX / 2; } diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap new file mode 100644 index 0000000000..7f9fb9b561 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/ptr-width-specific/dummy.32.rs +input_file: c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-32@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-32@macros.c.snap new file mode 100644 index 0000000000..245c6e7262 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-32@macros.c.snap @@ -0,0 +1,19 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/ptr-width-specific/macros.32.rs +input_file: c2rust-transpile/tests/snapshots/ptr-width-specific/macros.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +pub type uintptr_t = usize; +pub const UINTPTR_MAX: ::core::ffi::c_uint = 4294967295 as ::core::ffi::c_uint; +#[no_mangle] +pub unsafe extern "C" fn use_portable_type(mut len: uintptr_t) -> bool { + return len <= (UINTPTR_MAX as uintptr_t).wrapping_div(2 as uintptr_t); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap new file mode 100644 index 0000000000..1b6349f941 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/ptr-width-specific/dummy.64.rs +input_file: c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-64@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-64@macros.c.snap new file mode 100644 index 0000000000..a529d65e41 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-64@macros.c.snap @@ -0,0 +1,19 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/ptr-width-specific/macros.64.rs +input_file: c2rust-transpile/tests/snapshots/ptr-width-specific/macros.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +pub type uintptr_t = usize; +pub const UINTPTR_MAX: ::core::ffi::c_ulong = 18446744073709551615 as ::core::ffi::c_ulong; +#[no_mangle] +pub unsafe extern "C" fn use_portable_type(mut len: uintptr_t) -> bool { + return len <= (UINTPTR_MAX as uintptr_t).wrapping_div(2 as uintptr_t); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@vm_x86.c.snap index 62be750e16..cd0b7aced0 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@vm_x86.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@vm_x86.c.snap @@ -1,6 +1,6 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/arch-specific/vm_x86.x86_64.rs +expression: cat tests/snapshots/arch-specific/vm_x86.aarch64.rs input_file: c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c --- #![allow( diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap new file mode 100644 index 0000000000..61ec91b3d8 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/arch-specific/dummy.arm.rs +input_file: c2rust-transpile/tests/snapshots/arch-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@spin.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@spin.c.snap new file mode 100644 index 0000000000..35287d6f8d --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@spin.c.snap @@ -0,0 +1,22 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/arch-specific/spin.arm.rs +input_file: c2rust-transpile/tests/snapshots/arch-specific/spin.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +#![feature(stdsimd)] +#[cfg(target_arch = "aarch64")] +pub use ::core::arch::aarch64::__yield; +#[cfg(target_arch = "arm")] +pub use ::core::arch::arm::__yield; +#[no_mangle] +pub unsafe extern "C" fn spin() { + __yield(); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@vm_x86.c.snap new file mode 100644 index 0000000000..e063f4ec6d --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@vm_x86.c.snap @@ -0,0 +1,71 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/arch-specific/vm_x86.arm.rs +input_file: c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +#[derive(Copy, Clone)] +#[repr(C)] +pub struct vm_t { + pub programStack: ::core::ffi::c_int, + pub entryOfs: ::core::ffi::c_int, + pub dataBase: *mut ::core::ffi::c_void, + pub codeBase: *mut ::core::ffi::c_void, + pub instructionPointers: *mut ::core::ffi::c_ulong, +} +pub type byte = ::core::ffi::c_uchar; +pub const MAX_VMMAIN_ARGS: ::core::ffi::c_int = 50 as ::core::ffi::c_int; +#[no_mangle] +pub unsafe extern "C" fn VM_CallCompiled( + mut vm: *mut vm_t, + mut args: *mut ::core::ffi::c_int, +) -> ::core::ffi::c_int { + let mut stack: [byte; 271] = [0; 271]; + let mut entryPoint: *mut ::core::ffi::c_void = 0 as *mut ::core::ffi::c_void; + let mut programStack: ::core::ffi::c_int = 0; + let mut stackOnEntry: ::core::ffi::c_int = 0; + let mut image: *mut byte = 0 as *mut byte; + let mut opStack: *mut ::core::ffi::c_int = 0 as *mut ::core::ffi::c_int; + let mut opStackOfs: ::core::ffi::c_int = 0; + let mut arg: ::core::ffi::c_int = 0; + let mut currentVM: *mut vm_t = vm; + stackOnEntry = (*vm).programStack; + programStack = stackOnEntry; + image = (*vm).dataBase as *mut byte; + programStack -= 8 as ::core::ffi::c_int + 4 as ::core::ffi::c_int * MAX_VMMAIN_ARGS; + arg = 0 as ::core::ffi::c_int; + while arg < MAX_VMMAIN_ARGS { + *(&mut *image.offset( + (programStack + 8 as ::core::ffi::c_int + arg * 4 as ::core::ffi::c_int) as isize, + ) as *mut byte as *mut ::core::ffi::c_int) = *args.offset(arg as isize); + arg += 1; + } + *(&mut *image.offset((programStack + 4 as ::core::ffi::c_int) as isize) as *mut byte + as *mut ::core::ffi::c_int) = 0 as ::core::ffi::c_int; + *(&mut *image.offset(programStack as isize) as *mut byte as *mut ::core::ffi::c_int) = + -(1 as ::core::ffi::c_int); + entryPoint = ((*vm).codeBase).offset((*vm).entryOfs as isize); + opStack = + (stack.as_mut_ptr() as *mut ::core::ffi::c_int).offset(16 as ::core::ffi::c_int as isize); + *opStack = 0 as ::core::ffi::c_int; + opStackOfs = 0 as ::core::ffi::c_int; + if opStackOfs != 1 as ::core::ffi::c_int + || *opStack as ::core::ffi::c_uint != 0xdeadbeef as ::core::ffi::c_uint + { + return 0 as ::core::ffi::c_int; + } + if programStack + != stackOnEntry - (8 as ::core::ffi::c_int + 4 as ::core::ffi::c_int * MAX_VMMAIN_ARGS) + { + return 0 as ::core::ffi::c_int; + } + (*vm).programStack = stackOnEntry; + return *opStack.offset(opStackOfs as isize); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap new file mode 100644 index 0000000000..c04b46edaa --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/os-ptr-width-specific/dummy.linux-32.rs +input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@rotate.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@rotate.c.snap similarity index 80% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-macos@rotate.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@rotate.c.snap index f6e1255ff6..55655d82d9 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@rotate.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@rotate.c.snap @@ -1,7 +1,7 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/rotate.macos.rs -input_file: c2rust-transpile/tests/snapshots/os-specific/rotate.c +expression: cat tests/snapshots/os-ptr-width-specific/rotate.linux-32.rs +input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/rotate.c --- #![allow( dead_code, diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap new file mode 100644 index 0000000000..36cc9d7423 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/os-ptr-width-specific/dummy.linux-64.rs +input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@rotate.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@rotate.c.snap similarity index 83% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux@rotate.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@rotate.c.snap index 5db0995d02..e228215f26 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@rotate.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@rotate.c.snap @@ -1,7 +1,7 @@ --- source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-specific/rotate.linux.rs -input_file: c2rust-transpile/tests/snapshots/os-specific/rotate.c +expression: cat tests/snapshots/os-ptr-width-specific/rotate.linux-64.rs +input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/rotate.c --- #![allow( dead_code, diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@types.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@types.c.snap index 5e14aeac65..e3b40f4150 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@types.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@types.c.snap @@ -1,8 +1,7 @@ --- source: c2rust-transpile/tests/snapshots.rs -assertion_line: 69 -expression: cat tests/snapshots/platform-specific/types.rs -input_file: c2rust-transpile/tests/snapshots/platform-specific/types.c +expression: cat tests/snapshots/os-specific/types.linux.rs +input_file: c2rust-transpile/tests/snapshots/os-specific/types.c --- #![allow( dead_code, @@ -67,4 +66,3 @@ pub static mut int64var: int64_t = 0 as int64_t; pub static mut maxvar: intmax_t = 0 as intmax_t; #[no_mangle] pub static mut umaxvar: uintmax_t = 0 as uintmax_t; - diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap new file mode 100644 index 0000000000..4dd578bacd --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/os-ptr-width-specific/dummy.macos-64.rs +input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@rotate.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@rotate.c.snap new file mode 100644 index 0000000000..916a6acb01 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@rotate.c.snap @@ -0,0 +1,25 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/os-ptr-width-specific/rotate.macos-64.rs +input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/rotate.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +#[no_mangle] +pub unsafe extern "C" fn rotate_left_64( + mut x: ::core::ffi::c_ulonglong, +) -> ::core::ffi::c_ulonglong { + return x.rotate_left(4 as ::core::ffi::c_int as ::core::ffi::c_ulonglong as u32); +} +#[no_mangle] +pub unsafe extern "C" fn rotate_right_64( + mut x: ::core::ffi::c_ulonglong, +) -> ::core::ffi::c_ulonglong { + return x.rotate_right(4 as ::core::ffi::c_int as ::core::ffi::c_ulonglong as u32); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap new file mode 100644 index 0000000000..ba1cf5b642 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap @@ -0,0 +1,13 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/arch-specific/dummy.x86.rs +input_file: c2rust-transpile/tests/snapshots/arch-specific/dummy.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@spin.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@spin.c.snap new file mode 100644 index 0000000000..e939a878e4 --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@spin.c.snap @@ -0,0 +1,22 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/arch-specific/spin.x86.rs +input_file: c2rust-transpile/tests/snapshots/arch-specific/spin.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +#![feature(stdsimd)] +#[cfg(target_arch = "x86")] +pub use ::core::arch::x86::_mm_pause; +#[cfg(target_arch = "x86_64")] +pub use ::core::arch::x86_64::_mm_pause; +#[no_mangle] +pub unsafe extern "C" fn spin() { + _mm_pause(); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@vm_x86.c.snap new file mode 100644 index 0000000000..e92154088e --- /dev/null +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@vm_x86.c.snap @@ -0,0 +1,71 @@ +--- +source: c2rust-transpile/tests/snapshots.rs +expression: cat tests/snapshots/arch-specific/vm_x86.x86.rs +input_file: c2rust-transpile/tests/snapshots/arch-specific/vm_x86.c +--- +#![allow( + dead_code, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +#[derive(Copy, Clone)] +#[repr(C)] +pub struct vm_t { + pub programStack: ::core::ffi::c_int, + pub entryOfs: ::core::ffi::c_int, + pub dataBase: *mut ::core::ffi::c_void, + pub codeBase: *mut ::core::ffi::c_void, + pub instructionPointers: *mut ::core::ffi::c_ulong, +} +pub type byte = ::core::ffi::c_uchar; +pub const MAX_VMMAIN_ARGS: ::core::ffi::c_int = 50 as ::core::ffi::c_int; +#[no_mangle] +pub unsafe extern "C" fn VM_CallCompiled( + mut vm: *mut vm_t, + mut args: *mut ::core::ffi::c_int, +) -> ::core::ffi::c_int { + let mut stack: [byte; 271] = [0; 271]; + let mut entryPoint: *mut ::core::ffi::c_void = 0 as *mut ::core::ffi::c_void; + let mut programStack: ::core::ffi::c_int = 0; + let mut stackOnEntry: ::core::ffi::c_int = 0; + let mut image: *mut byte = 0 as *mut byte; + let mut opStack: *mut ::core::ffi::c_int = 0 as *mut ::core::ffi::c_int; + let mut opStackOfs: ::core::ffi::c_int = 0; + let mut arg: ::core::ffi::c_int = 0; + let mut currentVM: *mut vm_t = vm; + stackOnEntry = (*vm).programStack; + programStack = stackOnEntry; + image = (*vm).dataBase as *mut byte; + programStack -= 8 as ::core::ffi::c_int + 4 as ::core::ffi::c_int * MAX_VMMAIN_ARGS; + arg = 0 as ::core::ffi::c_int; + while arg < MAX_VMMAIN_ARGS { + *(&mut *image.offset( + (programStack + 8 as ::core::ffi::c_int + arg * 4 as ::core::ffi::c_int) as isize, + ) as *mut byte as *mut ::core::ffi::c_int) = *args.offset(arg as isize); + arg += 1; + } + *(&mut *image.offset((programStack + 4 as ::core::ffi::c_int) as isize) as *mut byte + as *mut ::core::ffi::c_int) = 0 as ::core::ffi::c_int; + *(&mut *image.offset(programStack as isize) as *mut byte as *mut ::core::ffi::c_int) = + -(1 as ::core::ffi::c_int); + entryPoint = ((*vm).codeBase).offset((*vm).entryOfs as isize); + opStack = + (stack.as_mut_ptr() as *mut ::core::ffi::c_int).offset(16 as ::core::ffi::c_int as isize); + *opStack = 0 as ::core::ffi::c_int; + opStackOfs = 0 as ::core::ffi::c_int; + if opStackOfs != 1 as ::core::ffi::c_int + || *opStack as ::core::ffi::c_uint != 0xdeadbeef as ::core::ffi::c_uint + { + return 0 as ::core::ffi::c_int; + } + if programStack + != stackOnEntry - (8 as ::core::ffi::c_int + 4 as ::core::ffi::c_int * MAX_VMMAIN_ARGS) + { + return 0 as ::core::ffi::c_int; + } + (*vm).programStack = stackOnEntry; + return *opStack.offset(opStackOfs as isize); +} diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@incomplete_arrays.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@incomplete_arrays.c.snap index 4a422a89f3..622c36cb42 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@incomplete_arrays.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@incomplete_arrays.c.snap @@ -1,6 +1,5 @@ --- source: c2rust-transpile/tests/snapshots.rs -assertion_line: 80 expression: cat tests/snapshots/incomplete_arrays.rs input_file: c2rust-transpile/tests/snapshots/incomplete_arrays.c --- @@ -12,4 +11,3 @@ input_file: c2rust-transpile/tests/snapshots/incomplete_arrays.c unused_assignments, unused_mut )] - diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.snap index 4de2fbc9b4..771fef1ce3 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile@macros.c.snap @@ -14,7 +14,6 @@ input_file: c2rust-transpile/tests/snapshots/macros.c extern "C" { fn extern_fn() -> ::core::ffi::c_int; } -pub type uintptr_t = usize; #[derive(Copy, Clone)] #[repr(C)] pub struct S { @@ -35,7 +34,6 @@ pub struct ntlmdata { pub target_info_len: ::core::ffi::c_uint, } pub const true_0: ::core::ffi::c_int = 1 as ::core::ffi::c_int; -pub const UINTPTR_MAX: ::core::ffi::c_ulong = 18446744073709551615 as ::core::ffi::c_ulong; pub const LITERAL_INT: ::core::ffi::c_int = 0xffff as ::core::ffi::c_int; pub const LITERAL_BOOL: ::core::ffi::c_int = true_0; pub const LITERAL_FLOAT: ::core::ffi::c_double = 3.14f64; @@ -426,10 +424,6 @@ pub unsafe extern "C" fn use_local_value() -> ::core::ffi::c_int { return local_fn(); } #[no_mangle] -pub unsafe extern "C" fn use_portable_type(mut len: uintptr_t) -> bool { - return len <= (UINTPTR_MAX as uintptr_t).wrapping_div(2 as uintptr_t); -} -#[no_mangle] pub unsafe extern "C" fn ntlm_v2_blob_len(mut ntlm: *mut ntlmdata) -> ::core::ffi::c_uint { return ((44 as ::core::ffi::c_int - 16 as ::core::ffi::c_int) as ::core::ffi::c_uint) .wrapping_add((*ntlm).target_info_len) From b2ff8144abaf66d3c03ad5ac7e551f89474ba59f Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 23:18:59 -0800 Subject: [PATCH 19/21] transpile: tests: combine all the `insta::glob!`s so that we can remove all of the `dummy.c`s The `dummy.c`s were needed because if an `insta::glob!` only found one path, then the common prefix was the whole thing and removed too much. --- c2rust-transpile/tests/snapshots.rs | 32 +++++++++++-------- .../tests/snapshots/arch-specific/dummy.c | 0 .../snapshots/os-ptr-width-specific/dummy.c | 0 .../snapshots/ptr-width-specific/dummy.c | 0 .../snapshots__transpile-32@dummy.c.snap | 13 -------- ...pile-32@ptr-width-specific__macros.c.snap} | 0 .../snapshots__transpile-64@dummy.c.snap | 13 -------- ...pile-64@ptr-width-specific__macros.c.snap} | 0 ...nspile-aarch64@arch-specific__spin.c.snap} | 0 ...pile-aarch64@arch-specific__vm_x86.c.snap} | 0 .../snapshots__transpile-aarch64@dummy.c.snap | 13 -------- ..._transpile-arm@arch-specific__spin.c.snap} | 0 ...ranspile-arm@arch-specific__vm_x86.c.snap} | 0 .../snapshots__transpile-arm@dummy.c.snap | 13 -------- ...snapshots__transpile-linux-32@dummy.c.snap | 13 -------- ...x-32@os-ptr-width-specific__rotate.c.snap} | 0 ...snapshots__transpile-linux-64@dummy.c.snap | 13 -------- ...x-64@os-ptr-width-specific__rotate.c.snap} | 0 ...ranspile-linux@os-specific__macros.c.snap} | 0 ...__transpile-linux@os-specific__rnd.c.snap} | 0 ...ranspile-linux@os-specific__sigign.c.snap} | 0 ...transpile-linux@os-specific__types.c.snap} | 0 ...snapshots__transpile-macos-64@dummy.c.snap | 13 -------- ...s-64@os-ptr-width-specific__rotate.c.snap} | 0 ...ranspile-macos@os-specific__macros.c.snap} | 0 ...__transpile-macos@os-specific__rnd.c.snap} | 0 ...ranspile-macos@os-specific__sigign.c.snap} | 0 ...transpile-macos@os-specific__types.c.snap} | 0 ..._transpile-x86@arch-specific__spin.c.snap} | 0 ...ranspile-x86@arch-specific__vm_x86.c.snap} | 0 .../snapshots__transpile-x86@dummy.c.snap | 13 -------- ...anspile-x86_64@arch-specific__spin.c.snap} | 0 ...spile-x86_64@arch-specific__vm_x86.c.snap} | 0 .../snapshots__transpile-x86_64@dummy.c.snap | 13 -------- 34 files changed, 19 insertions(+), 130 deletions(-) delete mode 100644 c2rust-transpile/tests/snapshots/arch-specific/dummy.c delete mode 100644 c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c delete mode 100644 c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-32@macros.c.snap => snapshots__transpile-32@ptr-width-specific__macros.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-64@macros.c.snap => snapshots__transpile-64@ptr-width-specific__macros.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-aarch64@spin.c.snap => snapshots__transpile-aarch64@arch-specific__spin.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-aarch64@vm_x86.c.snap => snapshots__transpile-aarch64@arch-specific__vm_x86.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-arm@spin.c.snap => snapshots__transpile-arm@arch-specific__spin.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-arm@vm_x86.c.snap => snapshots__transpile-arm@arch-specific__vm_x86.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux-32@rotate.c.snap => snapshots__transpile-linux-32@os-ptr-width-specific__rotate.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux-64@rotate.c.snap => snapshots__transpile-linux-64@os-ptr-width-specific__rotate.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux@macros.c.snap => snapshots__transpile-linux@os-specific__macros.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux@rnd.c.snap => snapshots__transpile-linux@os-specific__rnd.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux@sigign.c.snap => snapshots__transpile-linux@os-specific__sigign.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-linux@types.c.snap => snapshots__transpile-linux@os-specific__types.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-macos-64@rotate.c.snap => snapshots__transpile-macos-64@os-ptr-width-specific__rotate.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-macos@macros.c.snap => snapshots__transpile-macos@os-specific__macros.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-macos@rnd.c.snap => snapshots__transpile-macos@os-specific__rnd.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-macos@sigign.c.snap => snapshots__transpile-macos@os-specific__sigign.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-macos@types.c.snap => snapshots__transpile-macos@os-specific__types.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-x86@spin.c.snap => snapshots__transpile-x86@arch-specific__spin.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-x86@vm_x86.c.snap => snapshots__transpile-x86@arch-specific__vm_x86.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap rename c2rust-transpile/tests/snapshots/{snapshots__transpile-x86_64@spin.c.snap => snapshots__transpile-x86_64@arch-specific__spin.c.snap} (100%) rename c2rust-transpile/tests/snapshots/{snapshots__transpile-x86_64@vm_x86.c.snap => snapshots__transpile-x86_64@arch-specific__vm_x86.c.snap} (100%) delete mode 100644 c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@dummy.c.snap diff --git a/c2rust-transpile/tests/snapshots.rs b/c2rust-transpile/tests/snapshots.rs index 203ca42c4b..475965fe57 100644 --- a/c2rust-transpile/tests/snapshots.rs +++ b/c2rust-transpile/tests/snapshots.rs @@ -587,17 +587,23 @@ fn transpile_all() { ]); targets.check_if_targets_are_installed(); - insta::glob!("snapshots/*.c", |path| targets.transpile(path, |_| "")); - insta::glob!("snapshots/os-specific/*.c", |path| targets - .transpile(path, |target| target.os().name())); - insta::glob!("snapshots/arch-specific/*.c", |path| targets - .transpile(path, |target| target.arch().name())); - insta::glob!("snapshots/ptr-width-specific/*.c", |path| targets - .transpile(path, |target| format!("{}", target.arch().ptr_width()))); - insta::glob!("snapshots/os-ptr-width-specific/*.c", |path| targets - .transpile(path, |target| format!( - "{}-{}", - target.os(), - target.arch().ptr_width() - ))); + let transpile = |path: &Path| { + let dir = path.parent().unwrap(); + let dir_name = dir.file_name().unwrap_or_default(); + let dir_name = dir_name.to_str().unwrap_or_default(); + match dir_name { + "snapshots" => targets.transpile(path, |_| ""), + "os-specific" => targets.transpile(path, |target| target.os().name()), + "arch-specific" => targets.transpile(path, |target| target.arch().name()), + "ptr-width-specific" => { + targets.transpile(path, |target| format!("{}", target.arch().ptr_width())) + } + "os-ptr-width-specific" => targets.transpile(path, |target| { + format!("{}-{}", target.os(), target.arch().ptr_width()) + }), + _ => unreachable!(), + } + }; + + insta::glob!("snapshots/**/*.c", transpile); } diff --git a/c2rust-transpile/tests/snapshots/arch-specific/dummy.c b/c2rust-transpile/tests/snapshots/arch-specific/dummy.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c b/c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c b/c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap deleted file mode 100644 index 7f9fb9b561..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-32@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/ptr-width-specific/dummy.32.rs -input_file: c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-32@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-32@ptr-width-specific__macros.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-32@macros.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-32@ptr-width-specific__macros.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap deleted file mode 100644 index 1b6349f941..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-64@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/ptr-width-specific/dummy.64.rs -input_file: c2rust-transpile/tests/snapshots/ptr-width-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-64@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-64@ptr-width-specific__macros.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-64@macros.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-64@ptr-width-specific__macros.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@spin.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@arch-specific__spin.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@spin.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@arch-specific__spin.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@arch-specific__vm_x86.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@vm_x86.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@arch-specific__vm_x86.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@dummy.c.snap deleted file mode 100644 index d8beb1e9af..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-aarch64@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/arch-specific/dummy.aarch64.rs -input_file: c2rust-transpile/tests/snapshots/arch-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@spin.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@arch-specific__spin.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-arm@spin.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-arm@arch-specific__spin.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@arch-specific__vm_x86.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-arm@vm_x86.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-arm@arch-specific__vm_x86.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap deleted file mode 100644 index 61ec91b3d8..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-arm@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/arch-specific/dummy.arm.rs -input_file: c2rust-transpile/tests/snapshots/arch-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap deleted file mode 100644 index c04b46edaa..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-ptr-width-specific/dummy.linux-32.rs -input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@rotate.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@os-ptr-width-specific__rotate.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@rotate.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux-32@os-ptr-width-specific__rotate.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap deleted file mode 100644 index 36cc9d7423..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-ptr-width-specific/dummy.linux-64.rs -input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@rotate.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@os-ptr-width-specific__rotate.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@rotate.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux-64@os-ptr-width-specific__rotate.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__macros.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux@macros.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__macros.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@rnd.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__rnd.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux@rnd.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__rnd.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@sigign.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__sigign.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux@sigign.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__sigign.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@types.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__types.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-linux@types.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-linux@os-specific__types.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap deleted file mode 100644 index 4dd578bacd..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/os-ptr-width-specific/dummy.macos-64.rs -input_file: c2rust-transpile/tests/snapshots/os-ptr-width-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@rotate.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@os-ptr-width-specific__rotate.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@rotate.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-macos-64@os-ptr-width-specific__rotate.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@macros.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__macros.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-macos@macros.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__macros.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@rnd.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__rnd.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-macos@rnd.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__rnd.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@sigign.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__sigign.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-macos@sigign.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__sigign.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@types.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__types.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-macos@types.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-macos@os-specific__types.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@spin.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@arch-specific__spin.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-x86@spin.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-x86@arch-specific__spin.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@arch-specific__vm_x86.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-x86@vm_x86.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-x86@arch-specific__vm_x86.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap deleted file mode 100644 index ba1cf5b642..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/arch-specific/dummy.x86.rs -input_file: c2rust-transpile/tests/snapshots/arch-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@spin.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@arch-specific__spin.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@spin.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@arch-specific__spin.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@arch-specific__vm_x86.c.snap similarity index 100% rename from c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap rename to c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@arch-specific__vm_x86.c.snap diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@dummy.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@dummy.c.snap deleted file mode 100644 index c23accc4da..0000000000 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@dummy.c.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: c2rust-transpile/tests/snapshots.rs -expression: cat tests/snapshots/arch-specific/dummy.x86_64.rs -input_file: c2rust-transpile/tests/snapshots/arch-specific/dummy.c ---- -#![allow( - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut -)] From 8d4c925164e209b16e34f500c819c81230309661 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Sun, 2 Nov 2025 23:46:10 -0800 Subject: [PATCH 20/21] ci: remove extra newline --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1283dc1de..b90746d4c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -112,7 +112,6 @@ jobs: # It's important that we keep `RUSTFLAGS` consistent between different steps # so that we don't have to rebuild everything. echo "RUSTFLAGS=-Clink-arg=-L/opt/homebrew/lib -Clink-arg=-Wl,-rpath,/opt/homebrew/lib" >> $GITHUB_ENV - - name: cargo build --release run: | From 559f83a5b19a0b6ecf57160b9a169c730070eed3 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 3 Nov 2025 00:26:55 -0800 Subject: [PATCH 21/21] ci: make sure `python 3.14` is used to ensure a stable version Also, print the `python` and `zig` versions. --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b90746d4c7..31062b4b44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,11 +32,16 @@ jobs: - name: Install Python Packages run: | + uv python install 3.14 + uv run python -V + uv venv uv pip install -r ./scripts/requirements.txt + # `zig cc` needed for cross-compilation uv tool install ziglang ln -s $(which python-zig) $(dirname $(which python-zig))/zig + zig version # rust-cache very carefully caches toolchains and target directories, # based on the job and toolchain and other factors. See