diff --git a/src/lib.rs b/src/lib.rs index cb2e51ca..9b2816fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(()) diff --git a/tests/test.rs b/tests/test.rs index e9bbc94a..8fc8da64 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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() {