nixpkgs/pkgs/os-specific/darwin/apple-sdk/sdkRoot.nix
Randy Eckenrode 39a5f4a6ee
darwin.apple_sdk.sdkRoot: init at 10.12 and 11.0
Based on the derivation from xcbuild.sdk. apple_sdk.sdkRoot provides
version plists and a hook that passes them automatically to the compiler
as `-isysroot`. This is needed to correctly set the SDK version in
compiled binaries. Otherwise, clang will infer the SDK version to be the
same as the deployment target, which is usually not what you want.
2024-03-29 08:47:41 -04:00

69 lines
1.9 KiB
Nix

{
lib,
runCommand,
writeText,
sdkVersion,
}:
let
sdkName = "MacOSX${sdkVersion}";
toolchainName = "com.apple.dt.toolchain.XcodeDefault";
productBuildVer = null;
inherit (lib.generators) toPlist toJSON;
SDKSettings = {
CanonicalName = "macosx${sdkVersion}";
DisplayName = "macOS ${sdkVersion}";
Toolchains = [ toolchainName ];
Version = sdkVersion;
MaximumDeploymentTarget = "${sdkVersion}.99";
isBaseSDK = "YES";
};
SystemVersion =
lib.optionalAttrs (productBuildVer != null) { ProductBuildVersion = productBuildVer; }
// {
ProductName = "macOS";
ProductVersion = sdkVersion;
};
in
runCommand "sdkroot-${sdkVersion}" { } ''
sdk="$out/${sdkName}.sdk"
install -D ${writeText "SDKSettings.plist" (toPlist { } SDKSettings)} "$sdk/SDKSettings.plist"
install -D ${writeText "SDKSettings.json" (toJSON { } SDKSettings)} "$sdk/SDKSettings.json"
install -D ${
writeText "SystemVersion.plist" (toPlist { } SystemVersion)
} "$sdk/System/Library/CoreServices/SystemVersion.plist"
ln -s "$sdk" "$sdk/usr"
install -D '${../../../build-support/setup-hooks/role.bash}' "$out/nix-support/setup-hook"
cat >> "$out/nix-support/setup-hook" <<-hook
#
# See comments in cc-wrapper's setup hook. This works exactly the same way.
#
[[ -z \''${strictDeps-} ]] || (( "\$hostOffset" < 0 )) || return 0
sdkRootHook() {
# See ../../../build-support/setup-hooks/role.bash
local role_post
getHostRoleEnvHook
# Only set the SDK root if one has not been set via this hook or some other means.
if [[ ! \$NIX_CFLAGS_COMPILE =~ isysroot ]]; then
export NIX_CFLAGS_COMPILE\''${role_post}+=' -isysroot $out/${sdkName}.sdk'
fi
}
# See ../../../build-support/setup-hooks/role.bash
getTargetRole
addEnvHooks "\$targetOffset" sdkRootHook
# No local scope in sourced file
unset -v role_post
hook
''