2018-07-07 00:49:38 +02:00
|
|
|
{ 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" }:
|
2016-06-26 06:45:55 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
inherit (lib) toLower;
|
|
|
|
|
2016-06-26 06:45:55 +02:00
|
|
|
toolchainName = "com.apple.dt.toolchain.XcodeDefault";
|
2018-07-07 00:49:38 +02:00
|
|
|
sdkName = "${xcodePlatform}${sdkVer}";
|
|
|
|
|
|
|
|
# TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here.
|
|
|
|
sdkBuildVersion = "17E189";
|
|
|
|
xcodeSelectVersion = "2349";
|
2016-06-26 06:45:55 +02:00
|
|
|
|
2018-06-27 21:36:00 +02:00
|
|
|
xcbuild = buildPackages.callPackage ./default.nix {
|
2016-06-26 06:45:55 +02:00
|
|
|
inherit CoreServices ImageIO CoreGraphics;
|
|
|
|
};
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
toolchains = buildPackages.callPackage ./toolchains.nix {
|
2018-06-27 21:36:00 +02:00
|
|
|
inherit toolchainName;
|
2016-06-26 06:45:55 +02:00
|
|
|
};
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
sdks = buildPackages.callPackage ./sdks.nix {
|
|
|
|
inherit toolchainName sdkName xcodePlatform;
|
|
|
|
version = sdkVer;
|
2016-06-26 06:45:55 +02:00
|
|
|
};
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
platforms = buildPackages.callPackage ./platforms.nix {
|
|
|
|
inherit sdks xcodePlatform;
|
2016-06-26 06:45:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
xcconfig = writeText "nix.xcconfig" ''
|
2016-11-06 01:51:15 +01:00
|
|
|
SDKROOT=${sdkName}
|
2016-06-26 06:45:55 +02:00
|
|
|
'';
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
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
|
|
|
|
'';
|
2016-11-12 22:51:25 +01:00
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
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
|
2016-06-26 06:45:55 +02:00
|
|
|
'';
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
runCommand "xcodebuild-${xcbuild.version}" {
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2016-12-15 18:07:54 +01:00
|
|
|
inherit (xcbuild) meta;
|
|
|
|
|
2018-07-07 00:49:38 +02:00
|
|
|
# ensure that the toolchain goes in PATH
|
|
|
|
propagatedBuildInputs = [ "${toolchains}/XcodeDefault.xctoolchain/usr" ];
|
|
|
|
|
|
|
|
passthru = { inherit xcbuild; };
|
2016-11-02 06:17:58 +01:00
|
|
|
|
2016-06-26 06:45:55 +02:00
|
|
|
preferLocalBuild = true;
|
2018-07-07 00:49:38 +02:00
|
|
|
} ''
|
|
|
|
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
|
|
|
|
''
|