swift-wrapper: set up Darwin SDK paths for Swift

This commit is contained in:
Randy Eckenrode 2024-09-25 21:47:47 -04:00
parent e694240f77
commit 7d5f19a354
No known key found for this signature in database
GPG Key ID: 64C1CD4EC2A600D9
2 changed files with 19 additions and 0 deletions

View File

@ -18,6 +18,10 @@ stdenv.mkDerivation (swift._wrapperParams // {
swiftStaticModuleSubdir swiftStaticLibSubdir;
swiftDriver = lib.optionalString useSwiftDriver "${swift-driver}/bin/swift-driver";
env.darwinMinVersion = lib.optionalString stdenv.targetPlatform.isDarwin (
stdenv.targetPlatform.darwinMinVersion
);
passAsFile = [ "buildCommand" ];
buildCommand = ''
mkdir -p $out/bin $out/nix-support
@ -48,6 +52,13 @@ stdenv.mkDerivation (swift._wrapperParams // {
ln -s ${swift.lib}/lib $out/lib
substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook
# Propagate any propagated inputs from the unwrapped Swift compiler, if any.
if [ -e "$swift/nix-support" ]; then
for input in "$swift/nix-support/"*propagated*; do
cp "$input" "$out/nix-support/$(basename "$input")"
done
fi
'';
passthru = {

View File

@ -156,6 +156,14 @@ if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then
source $cc_wrapper/nix-support/add-flags.sh
fi
# Only add darwin min version flag and set up `DEVELOPER_DIR` if a default darwin min version is set,
# which is a signal that we're targeting darwin. (Copied from add-flags in libc but tailored for Swift).
if [ "@darwinMinVersion@" ]; then
# Make sure the wrapped Swift compiler can find the overlays in the SDK.
NIX_SWIFTFLAGS_COMPILE+=" -I $SDKROOT/usr/lib/swift"
NIX_LDFLAGS_@suffixSalt@+=" -L $SDKROOT/usr/lib/swift"
fi
if [[ "$isCxx" = 1 ]]; then
if [[ "$cxxInclude" = 1 ]]; then
NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@"