Skip to content

Commit 7854f2f

Browse files
committed
Expand test for GCC Apple -arch and version flag
1 parent bfdf3d5 commit 7854f2f

File tree

1 file changed

+79
-8
lines changed

1 file changed

+79
-8
lines changed

tests/test.rs

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,28 +524,99 @@ fn asm_flags() {
524524
}
525525

526526
#[test]
527-
fn gnu_apple_darwin() {
528-
for (arch, ld64_arch, version) in &[("x86_64", "x86_64", "10.7"), ("aarch64", "arm64", "11.0")]
529-
{
530-
let target = format!("{}-apple-darwin", arch);
527+
fn gnu_apple_sysroot() {
528+
let targets = ["aarch64-apple-darwin", "x86_64-apple-darwin"];
529+
530+
for target in targets {
531531
let test = Test::gnu();
532532
test.shim("fake-gcc")
533533
.gcc()
534534
.compiler("fake-gcc")
535535
.target(&target)
536536
.host(&target)
537-
// Avoid test maintenance when minimum supported OSes change.
538-
.__set_env("MACOSX_DEPLOYMENT_TARGET", version)
539537
.file("foo.c")
540538
.compile("foo");
541539

542540
let cmd = test.cmd(0);
543-
cmd.must_have_in_order("-arch", ld64_arch);
544-
cmd.must_have(format!("-mmacosx-version-min={version}"));
545541
cmd.must_not_have("-isysroot");
546542
}
547543
}
548544

545+
#[test]
546+
#[cfg(target_os = "macos")] // Invokes xcrun
547+
fn gnu_apple_arch() {
548+
let cases = [
549+
("x86_64-apple-darwin", "x86_64"),
550+
("x86_64h-apple-darwin", "x86_64h"),
551+
("aarch64-apple-darwin", "arm64"),
552+
("arm64e-apple-darwin", "arm64e"),
553+
("i686-apple-darwin", "i386"),
554+
("aarch64-apple-ios", "arm64"),
555+
("armv7s-apple-ios", "armv7s"),
556+
("arm64_32-apple-watchos", "arm64_32"),
557+
("armv7k-apple-watchos", "armv7k"),
558+
];
559+
560+
for (target, arch) in cases {
561+
let test = Test::gnu();
562+
test.shim("fake-gcc")
563+
.gcc()
564+
.compiler("fake-gcc")
565+
.target(&target)
566+
.host(&"aarch64-apple-darwin")
567+
.file("foo.c")
568+
.compile("foo");
569+
570+
let cmd = test.cmd(0);
571+
cmd.must_have_in_order("-arch", arch);
572+
}
573+
}
574+
575+
#[test]
576+
#[cfg(target_os = "macos")] // Invokes xcrun
577+
fn gnu_apple_deployment_target() {
578+
let cases = [
579+
("x86_64-apple-darwin", "-mmacosx-version-min=10.12"),
580+
("aarch64-apple-darwin", "-mmacosx-version-min=10.12"),
581+
("aarch64-apple-ios", "-miphoneos-version-min=10.0"),
582+
("aarch64-apple-ios-sim", "-mios-simulator-version-min=10.0"),
583+
("x86_64-apple-ios", "-mios-simulator-version-min=10.0"),
584+
("aarch64-apple-ios-macabi", "-mtargetos=ios10.0-macabi"),
585+
("aarch64-apple-tvos", "-mappletvos-version-min=10.0"),
586+
(
587+
"aarch64-apple-tvos-sim",
588+
"-mappletvsimulator-version-min=10.0",
589+
),
590+
("aarch64-apple-watchos", "-mwatchos-version-min=5.0"),
591+
(
592+
"aarch64-apple-watchos-sim",
593+
"-mwatchsimulator-version-min=5.0",
594+
),
595+
("aarch64-apple-visionos", "-mtargetos=xros1.0"),
596+
("aarch64-apple-visionos-sim", "-mtargetos=xros1.0-simulator"),
597+
];
598+
599+
for (target, os_version_flag) in cases {
600+
let test = Test::gnu();
601+
test.shim("fake-gcc")
602+
.gcc()
603+
.compiler("fake-gcc")
604+
.target(&target)
605+
.host(&"aarch64-apple-darwin")
606+
// Avoid dependency on environment in test.
607+
.__set_env("MACOSX_DEPLOYMENT_TARGET", "10.12")
608+
.__set_env("IPHONEOS_DEPLOYMENT_TARGET", "10.0")
609+
.__set_env("TVOS_DEPLOYMENT_TARGET", "10.0")
610+
.__set_env("WATCHOS_DEPLOYMENT_TARGET", "5.0")
611+
.__set_env("XROS_DEPLOYMENT_TARGET", "1.0")
612+
.file("foo.c")
613+
.compile("foo");
614+
615+
let cmd = test.cmd(0);
616+
cmd.must_have(os_version_flag);
617+
}
618+
}
619+
549620
#[cfg(target_os = "macos")]
550621
#[test]
551622
fn macos_cpp_minimums() {

0 commit comments

Comments
 (0)