Skip to content

Commit

Permalink
Expand test for GCC Apple -arch and version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Feb 8, 2025
1 parent bfdf3d5 commit 7854f2f
Showing 1 changed file with 79 additions and 8 deletions.
87 changes: 79 additions & 8 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,28 +524,99 @@ fn asm_flags() {
}

#[test]
fn gnu_apple_darwin() {
for (arch, ld64_arch, version) in &[("x86_64", "x86_64", "10.7"), ("aarch64", "arm64", "11.0")]
{
let target = format!("{}-apple-darwin", arch);
fn gnu_apple_sysroot() {
let targets = ["aarch64-apple-darwin", "x86_64-apple-darwin"];

for target in targets {
let test = Test::gnu();
test.shim("fake-gcc")
.gcc()
.compiler("fake-gcc")
.target(&target)
.host(&target)
// Avoid test maintenance when minimum supported OSes change.
.__set_env("MACOSX_DEPLOYMENT_TARGET", version)
.file("foo.c")
.compile("foo");

let cmd = test.cmd(0);
cmd.must_have_in_order("-arch", ld64_arch);
cmd.must_have(format!("-mmacosx-version-min={version}"));
cmd.must_not_have("-isysroot");
}
}

#[test]
#[cfg(target_os = "macos")] // Invokes xcrun
fn gnu_apple_arch() {
let cases = [
("x86_64-apple-darwin", "x86_64"),
("x86_64h-apple-darwin", "x86_64h"),
("aarch64-apple-darwin", "arm64"),
("arm64e-apple-darwin", "arm64e"),
("i686-apple-darwin", "i386"),
("aarch64-apple-ios", "arm64"),
("armv7s-apple-ios", "armv7s"),
("arm64_32-apple-watchos", "arm64_32"),
("armv7k-apple-watchos", "armv7k"),
];

for (target, arch) in cases {
let test = Test::gnu();
test.shim("fake-gcc")
.gcc()
.compiler("fake-gcc")
.target(&target)
.host(&"aarch64-apple-darwin")
.file("foo.c")
.compile("foo");

let cmd = test.cmd(0);
cmd.must_have_in_order("-arch", arch);
}
}

#[test]
#[cfg(target_os = "macos")] // Invokes xcrun
fn gnu_apple_deployment_target() {
let cases = [
("x86_64-apple-darwin", "-mmacosx-version-min=10.12"),
("aarch64-apple-darwin", "-mmacosx-version-min=10.12"),
("aarch64-apple-ios", "-miphoneos-version-min=10.0"),
("aarch64-apple-ios-sim", "-mios-simulator-version-min=10.0"),
("x86_64-apple-ios", "-mios-simulator-version-min=10.0"),
("aarch64-apple-ios-macabi", "-mtargetos=ios10.0-macabi"),
("aarch64-apple-tvos", "-mappletvos-version-min=10.0"),
(
"aarch64-apple-tvos-sim",
"-mappletvsimulator-version-min=10.0",
),
("aarch64-apple-watchos", "-mwatchos-version-min=5.0"),
(
"aarch64-apple-watchos-sim",
"-mwatchsimulator-version-min=5.0",
),
("aarch64-apple-visionos", "-mtargetos=xros1.0"),
("aarch64-apple-visionos-sim", "-mtargetos=xros1.0-simulator"),
];

for (target, os_version_flag) in cases {
let test = Test::gnu();
test.shim("fake-gcc")
.gcc()
.compiler("fake-gcc")
.target(&target)
.host(&"aarch64-apple-darwin")
// Avoid dependency on environment in test.
.__set_env("MACOSX_DEPLOYMENT_TARGET", "10.12")
.__set_env("IPHONEOS_DEPLOYMENT_TARGET", "10.0")
.__set_env("TVOS_DEPLOYMENT_TARGET", "10.0")
.__set_env("WATCHOS_DEPLOYMENT_TARGET", "5.0")
.__set_env("XROS_DEPLOYMENT_TARGET", "1.0")
.file("foo.c")
.compile("foo");

let cmd = test.cmd(0);
cmd.must_have(os_version_flag);
}
}

#[cfg(target_os = "macos")]
#[test]
fn macos_cpp_minimums() {
Expand Down

0 comments on commit 7854f2f

Please # to comment.