Skip to content

Commit

Permalink
Fix paths on Mac Catalyst (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed May 10, 2024
1 parent b7455eb commit 61b81c8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 33 deletions.
65 changes: 32 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2705,39 +2705,38 @@ impl Build {
let sdk_path = self.apple_sdk_root(&sdk_details.sdk)?;

cmd.args.push("-isysroot".into());
cmd.args.push(sdk_path);
}

if let AppleArchSpec::Catalyst(_) = arch {
// Mac Catalyst uses the macOS SDK, but to compile against and
// link to iOS-specific frameworks, we should have the support
// library stubs in the include and library search path.
let sdk_path = self.apple_sdk_root(&sdk_details.sdk)?;
let ios_support = PathBuf::from(sdk_path).join("/System/iOSSupport");

cmd.args.extend([
// Header search path
OsString::from("-isystem"),
ios_support.join("/usr/include").into(),
// Framework header search path
OsString::from("-iframework"),
ios_support.join("/System/Library/Frameworks").into(),
// Library search path
{
let mut s = OsString::from("-L");
s.push(&ios_support.join("/usr/lib"));
s
},
// Framework linker search path
{
// Technically, we _could_ avoid emitting `-F`, as
// `-iframework` implies it, but let's keep it in for
// clarity.
let mut s = OsString::from("-F");
s.push(&ios_support.join("/System/Library/Frameworks"));
s
},
]);
cmd.args.push(sdk_path.clone());

if let AppleArchSpec::Catalyst(_) = arch {
// Mac Catalyst uses the macOS SDK, but to compile against and
// link to iOS-specific frameworks, we should have the support
// library stubs in the include and library search path.
let ios_support = PathBuf::from(sdk_path).join("System/iOSSupport");

cmd.args.extend([
// Header search path
OsString::from("-isystem"),
ios_support.join("usr/include").into(),
// Framework header search path
OsString::from("-iframework"),
ios_support.join("System/Library/Frameworks").into(),
// Library search path
{
let mut s = OsString::from("-L");
s.push(&ios_support.join("usr/lib"));
s
},
// Framework linker search path
{
// Technically, we _could_ avoid emitting `-F`, as
// `-iframework` implies it, but let's keep it in for
// clarity.
let mut s = OsString::from("-F");
s.push(&ios_support.join("System/Library/Frameworks"));
s
},
]);
}
}

Ok(())
Expand Down
37 changes: 37 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,43 @@ fn clang_apple_tvos() {
}
}

#[cfg(target_os = "macos")]
#[test]
fn clang_apple_mac_catalyst() {
let output = std::process::Command::new("xcrun")
.args(["--show-sdk-path", "--sdk", "macosx"])
.output()
.unwrap();
if !output.status.success() {
return;
}
let sdkroot = std::str::from_utf8(&output.stdout).unwrap().trim();

let test = Test::clang();
test.gcc()
.target("aarch64-apple-ios-macabi")
.__set_env("IPHONEOS_DEPLOYMENT_TARGET", "15.0")
.file("foo.c")
.compile("foo");
let execution = test.cmd(0);

// TODO: Add version to target here
execution.must_have("--target=arm64-apple-ios-macabi");
execution.must_have_in_order("-isysroot", sdkroot);
execution.must_have_in_order(
"-isystem",
&format!("{sdkroot}/System/iOSSupport/usr/include"),
);
execution.must_have_in_order(
"-iframework",
&format!("{sdkroot}/System/iOSSupport/System/Library/Frameworks"),
);
execution.must_have(&format!("-L{sdkroot}/System/iOSSupport/usr/lib"));
execution.must_have(&format!(
"-F{sdkroot}/System/iOSSupport/System/Library/Frameworks"
));
}

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

0 comments on commit 61b81c8

Please sign in to comment.