Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix paths on Mac Catalyst #1070

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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