Skip to content

Commit 61b81c8

Browse files
authored
Fix paths on Mac Catalyst (#1070)
1 parent b7455eb commit 61b81c8

File tree

2 files changed

+69
-33
lines changed

2 files changed

+69
-33
lines changed

src/lib.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,39 +2705,38 @@ impl Build {
27052705
let sdk_path = self.apple_sdk_root(&sdk_details.sdk)?;
27062706

27072707
cmd.args.push("-isysroot".into());
2708-
cmd.args.push(sdk_path);
2709-
}
2710-
2711-
if let AppleArchSpec::Catalyst(_) = arch {
2712-
// Mac Catalyst uses the macOS SDK, but to compile against and
2713-
// link to iOS-specific frameworks, we should have the support
2714-
// library stubs in the include and library search path.
2715-
let sdk_path = self.apple_sdk_root(&sdk_details.sdk)?;
2716-
let ios_support = PathBuf::from(sdk_path).join("/System/iOSSupport");
2717-
2718-
cmd.args.extend([
2719-
// Header search path
2720-
OsString::from("-isystem"),
2721-
ios_support.join("/usr/include").into(),
2722-
// Framework header search path
2723-
OsString::from("-iframework"),
2724-
ios_support.join("/System/Library/Frameworks").into(),
2725-
// Library search path
2726-
{
2727-
let mut s = OsString::from("-L");
2728-
s.push(&ios_support.join("/usr/lib"));
2729-
s
2730-
},
2731-
// Framework linker search path
2732-
{
2733-
// Technically, we _could_ avoid emitting `-F`, as
2734-
// `-iframework` implies it, but let's keep it in for
2735-
// clarity.
2736-
let mut s = OsString::from("-F");
2737-
s.push(&ios_support.join("/System/Library/Frameworks"));
2738-
s
2739-
},
2740-
]);
2708+
cmd.args.push(sdk_path.clone());
2709+
2710+
if let AppleArchSpec::Catalyst(_) = arch {
2711+
// Mac Catalyst uses the macOS SDK, but to compile against and
2712+
// link to iOS-specific frameworks, we should have the support
2713+
// library stubs in the include and library search path.
2714+
let ios_support = PathBuf::from(sdk_path).join("System/iOSSupport");
2715+
2716+
cmd.args.extend([
2717+
// Header search path
2718+
OsString::from("-isystem"),
2719+
ios_support.join("usr/include").into(),
2720+
// Framework header search path
2721+
OsString::from("-iframework"),
2722+
ios_support.join("System/Library/Frameworks").into(),
2723+
// Library search path
2724+
{
2725+
let mut s = OsString::from("-L");
2726+
s.push(&ios_support.join("usr/lib"));
2727+
s
2728+
},
2729+
// Framework linker search path
2730+
{
2731+
// Technically, we _could_ avoid emitting `-F`, as
2732+
// `-iframework` implies it, but let's keep it in for
2733+
// clarity.
2734+
let mut s = OsString::from("-F");
2735+
s.push(&ios_support.join("System/Library/Frameworks"));
2736+
s
2737+
},
2738+
]);
2739+
}
27412740
}
27422741

27432742
Ok(())

tests/test.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,43 @@ fn clang_apple_tvos() {
584584
}
585585
}
586586

587+
#[cfg(target_os = "macos")]
588+
#[test]
589+
fn clang_apple_mac_catalyst() {
590+
let output = std::process::Command::new("xcrun")
591+
.args(["--show-sdk-path", "--sdk", "macosx"])
592+
.output()
593+
.unwrap();
594+
if !output.status.success() {
595+
return;
596+
}
597+
let sdkroot = std::str::from_utf8(&output.stdout).unwrap().trim();
598+
599+
let test = Test::clang();
600+
test.gcc()
601+
.target("aarch64-apple-ios-macabi")
602+
.__set_env("IPHONEOS_DEPLOYMENT_TARGET", "15.0")
603+
.file("foo.c")
604+
.compile("foo");
605+
let execution = test.cmd(0);
606+
607+
// TODO: Add version to target here
608+
execution.must_have("--target=arm64-apple-ios-macabi");
609+
execution.must_have_in_order("-isysroot", sdkroot);
610+
execution.must_have_in_order(
611+
"-isystem",
612+
&format!("{sdkroot}/System/iOSSupport/usr/include"),
613+
);
614+
execution.must_have_in_order(
615+
"-iframework",
616+
&format!("{sdkroot}/System/iOSSupport/System/Library/Frameworks"),
617+
);
618+
execution.must_have(&format!("-L{sdkroot}/System/iOSSupport/usr/lib"));
619+
execution.must_have(&format!(
620+
"-F{sdkroot}/System/iOSSupport/System/Library/Frameworks"
621+
));
622+
}
623+
587624
#[cfg(target_os = "macos")]
588625
#[test]
589626
fn clang_apple_tvsimulator() {

0 commit comments

Comments
 (0)