diff --git a/pkgs/development/compilers/swift/wrapper/default.nix b/pkgs/development/compilers/swift/wrapper/default.nix index 0c7e0f8cbcf8..2bf8ef60ebf3 100644 --- a/pkgs/development/compilers/swift/wrapper/default.nix +++ b/pkgs/development/compilers/swift/wrapper/default.nix @@ -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 = { diff --git a/pkgs/development/compilers/swift/wrapper/wrapper.sh b/pkgs/development/compilers/swift/wrapper/wrapper.sh index 5cd5d8da8819..3079bb182b1a 100644 --- a/pkgs/development/compilers/swift/wrapper/wrapper.sh +++ b/pkgs/development/compilers/swift/wrapper/wrapper.sh @@ -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@"