Open
Description
Hi all, invoking cargo build
from Xcode on Big Sur currently fails when a crate needs to link against a system library from a build script, unless SDKROOT
has been explicitly set to the path of the macOS SDK. Test project here.
When invoking cargo build
from an Xcode build script, SDKROOT
is set for the platform that's being built. #64254 made it so that SDKROOT
gets un-set if the target platform doesn't match the host platform. This seems reasonable to me, but then I don't understand why there's now a difference in behaviour between Xcode and non-Xcode builds.
I logged a similiar issue for cargo-lipo
, which has a different workaround of instead setting LIBRARY_PATH
.
Activity
nfriedly commentedon Dec 14, 2022
My team has also been hitting this issue since macOS 11/Big Sur, and initially setting the
LIBRARY_PATH
andSDK_ROOT
seemed to make it work, but after upgrading to macOS 14/Ventura, I (and apparently only I) started hitting this same issue again. I dug into it for a while and noticed this tidbit mentioning that Xcode's copy ofld
behaves differently from the one in/usr/bin
.So, the final solution I settled on was undoing my
LIBRARY_PATH
andSDK_ROOT
and instead resettingPATH
to exclude all of the Xcode folders in my build script:After that, rust builds seem to work reliably from both Xcode and the command line.
SDKROOT
ignore on macOS #130334Rollup merge of rust-lang#130334 - madsmtm:macos-sdkroot-ignore, r=ji…
Rollup merge of rust-lang#130334 - madsmtm:macos-sdkroot-ignore, r=ji…
Unrolled build for rust-lang#130334
Always attempt to get SDK root, and pass it to Clang via env var
Always attempt to get SDK root, and pass it to Clang via env var
cc
, and pass it viaSDKROOT
env var #131477madsmtm commentedon Oct 10, 2024
I can reproduce this with:
PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH" rustc foo.rs
With the current nightly, it should work with
-Clinker-flavor=ld
, and #131477 will make this work with the default linker.Always attempt to get SDK root, and pass it to Clang via env var
Always attempt to get SDK root, and pass it to Clang via env var
10 remaining items