xcbuild: refactor
This reworks some of xcbuild logic to make it more compatible with Apple’s SDK. - Add a fake version of xcrun & xcode-select - Cleanup platform generation. Clang does not like having 20 char hashes in sysroot so it is much easier to just build the parent directory for each runCommand. This is a little awkward but I have renamed everything with an added ‘s’ to make the distinction more clear. - Cleaned up wrapper.nix in some different ways - Reuse some versioning logic so that we don’t end up with two different versions of Xcode or SDK reported.
This commit is contained in:
@@ -1,80 +1,132 @@
|
||||
{ stdenv, buildPackages, makeWrapper, writeText, runCommand
|
||||
, CoreServices, ImageIO, CoreGraphics }:
|
||||
{ stdenv, lib, buildPackages, makeWrapper, writeText, runCommand
|
||||
, CoreServices, ImageIO, CoreGraphics
|
||||
, targetPlatform
|
||||
, xcodePlatform ? targetPlatform.xcodePlatform or "MacOSX"
|
||||
, xcodeVer ? targetPlatform.xcodeVer or "9.4.1"
|
||||
, sdkVer ? targetPlatform.sdkVer or "10.10" }:
|
||||
|
||||
let
|
||||
|
||||
inherit (lib) toLower;
|
||||
|
||||
toolchainName = "com.apple.dt.toolchain.XcodeDefault";
|
||||
platformName = "com.apple.platform.macosx";
|
||||
sdkName = "macosx10.10";
|
||||
sdkName = "${xcodePlatform}${sdkVer}";
|
||||
|
||||
# TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here.
|
||||
sdkBuildVersion = "17E189";
|
||||
xcodeSelectVersion = "2349";
|
||||
|
||||
xcbuild = buildPackages.callPackage ./default.nix {
|
||||
inherit CoreServices ImageIO CoreGraphics;
|
||||
};
|
||||
|
||||
toolchain = buildPackages.callPackage ./toolchain.nix {
|
||||
toolchains = buildPackages.callPackage ./toolchains.nix {
|
||||
inherit toolchainName;
|
||||
};
|
||||
|
||||
sdk = buildPackages.callPackage ./sdk.nix {
|
||||
inherit toolchainName sdkName;
|
||||
sdks = buildPackages.callPackage ./sdks.nix {
|
||||
inherit toolchainName sdkName xcodePlatform;
|
||||
version = sdkVer;
|
||||
};
|
||||
|
||||
platform = buildPackages.callPackage ./platform.nix {
|
||||
inherit sdk platformName;
|
||||
platforms = buildPackages.callPackage ./platforms.nix {
|
||||
inherit sdks xcodePlatform;
|
||||
};
|
||||
|
||||
xcconfig = writeText "nix.xcconfig" ''
|
||||
SDKROOT=${sdkName}
|
||||
'';
|
||||
|
||||
in
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "xcbuild-wrapper-${xcbuild.version}";
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
setupHook = ./setup-hook.sh;
|
||||
|
||||
phases = [ "installPhase" "fixupPhase" ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
|
||||
for file in ${xcbuild}/bin/*; do
|
||||
ln -s $file $out/bin
|
||||
done
|
||||
|
||||
mkdir -p $out/usr
|
||||
ln -s $out/bin $out/usr/bin
|
||||
|
||||
mkdir -p $out/Library/Xcode
|
||||
ln -s ${xcbuild}/Library/Xcode/Specifications $out/Library/Xcode/Specifications
|
||||
|
||||
mkdir -p $out/Platforms
|
||||
ln -s ${platform} $out/Platforms/nixpkgs.platform
|
||||
|
||||
mkdir -p $out/Toolchains
|
||||
ln -s ${toolchain} $out/Toolchains/nixpkgs.xctoolchain
|
||||
|
||||
wrapProgram $out/bin/xcodebuild \
|
||||
--add-flags "-xcconfig ${xcconfig}" \
|
||||
--add-flags "DERIVED_DATA_DIR=." \
|
||||
--set DEVELOPER_DIR "$out" \
|
||||
--set SDKROOT ${sdkName}
|
||||
wrapProgram $out/bin/xcrun \
|
||||
--set DEVELOPER_DIR "$out" \
|
||||
--set SDKROOT ${sdkName}
|
||||
wrapProgram $out/bin/xcode-select \
|
||||
--set DEVELOPER_DIR "$out" \
|
||||
--set SDKROOT ${sdkName}
|
||||
xcode-select = writeText "xcode-select" ''
|
||||
#!/usr/bin/env sh
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-h | --help) ;; # noop
|
||||
-s | --switch) shift;; # noop
|
||||
-r | --reset) ;; # noop
|
||||
-v | --version) echo xcode-select version ${xcodeSelectVersion} ;;
|
||||
-p | --print-path) echo @DEVELOPER_DIR@ ;;
|
||||
--install) ;; # noop
|
||||
esac
|
||||
shift
|
||||
done
|
||||
'';
|
||||
|
||||
xcrun = writeText "xcrun" ''
|
||||
#!/usr/bin/env sh
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--sdk | -sdk) shift ;;
|
||||
--find | -find)
|
||||
shift
|
||||
command -v $1 ;;
|
||||
--log | -log) ;; # noop
|
||||
--verbose | -verbose) ;; # noop
|
||||
--no-cache | -no-cache) ;; # noop
|
||||
--kill-cache | -kill-cache) ;; # noop
|
||||
--show-sdk-path | -show-sdk-path)
|
||||
echo ${sdks}/${sdkName}.sdk ;;
|
||||
--show-sdk-platform-path | -show-sdk-platform-path)
|
||||
echo ${platforms}/${xcodePlatform}.platform ;;
|
||||
--show-sdk-version | -show-sdk-version)
|
||||
echo ${sdkVer} ;;
|
||||
--show-sdk-build-version | -show-sdk-build-version)
|
||||
echo ${sdkBuildVersion} ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if ! [[ -z "$@" ]]; then
|
||||
exec "$@"
|
||||
fi
|
||||
'';
|
||||
|
||||
in
|
||||
|
||||
runCommand "xcodebuild-${xcbuild.version}" {
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
inherit (xcbuild) meta;
|
||||
|
||||
passthru = {
|
||||
raw = xcbuild;
|
||||
};
|
||||
# ensure that the toolchain goes in PATH
|
||||
propagatedBuildInputs = [ "${toolchains}/XcodeDefault.xctoolchain/usr" ];
|
||||
|
||||
passthru = { inherit xcbuild; };
|
||||
|
||||
preferLocalBuild = true;
|
||||
}
|
||||
} ''
|
||||
mkdir -p $out/bin
|
||||
|
||||
mkdir -p $out/usr
|
||||
ln -s $out/bin $out/usr/bin
|
||||
|
||||
mkdir -p $out/Library/Xcode
|
||||
ln -s ${xcbuild}/Library/Xcode/Specifications $out/Library/Xcode/Specifications
|
||||
|
||||
ln -s ${platforms} $out/Platforms
|
||||
ln -s ${toolchains} $out/Toolchains
|
||||
|
||||
makeWrapper ${xcbuild}/bin/xcodebuild $out/bin/xcodebuild \
|
||||
--add-flags "-xcconfig ${xcconfig}" \
|
||||
--add-flags "DERIVED_DATA_DIR=." \
|
||||
--set DEVELOPER_DIR "$out" \
|
||||
--set SDKROOT ${sdkName} \
|
||||
--run '[ "$1" = "-version" ] && (echo Xcode ${xcodeVer}; echo Build version ${sdkBuildVersion}) && exit 0'
|
||||
|
||||
substitute ${xcode-select} $out/bin/xcode-select \
|
||||
--subst-var-by DEVELOPER_DIR $out
|
||||
chmod +x $out/bin/xcode-select
|
||||
|
||||
substitute ${xcrun} $out/bin/xcrun
|
||||
chmod +x $out/bin/xcrun
|
||||
|
||||
for bin in PlistBuddy actool builtin-copy builtin-copyPlist \
|
||||
builtin-copyStrings builtin-copyTiff \
|
||||
builtin-embeddedBinaryValidationUtility \
|
||||
builtin-infoPlistUtility builtin-lsRegisterURL \
|
||||
builtin-productPackagingUtility builtin-validationUtility \
|
||||
lsbom plutil; do
|
||||
ln -s ${xcbuild}/bin/$bin $out/bin/$bin
|
||||
done
|
||||
|
||||
fixupPhase
|
||||
''
|
||||
|
||||
Reference in New Issue
Block a user