2018-07-11 16:45:23 +01:00
|
|
|
{ stdenv, lib, buildPackages, makeWrapper, writeText, runCommand
|
2018-07-06 23:49:38 +01:00
|
|
|
, CoreServices, ImageIO, CoreGraphics
|
2019-04-23 03:45:58 +01:00
|
|
|
, runtimeShell, callPackage
|
2018-08-20 19:43:41 +01:00
|
|
|
, xcodePlatform ? stdenv.targetPlatform.xcodePlatform or "MacOSX"
|
|
|
|
, xcodeVer ? stdenv.targetPlatform.xcodeVer or "9.4.1"
|
2019-03-01 00:19:04 +00:00
|
|
|
, sdkVer ? stdenv.targetPlatform.sdkVer or "10.12" }:
|
2016-06-26 05:45:55 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
toolchainName = "com.apple.dt.toolchain.XcodeDefault";
|
2018-07-06 23:49:38 +01:00
|
|
|
sdkName = "${xcodePlatform}${sdkVer}";
|
|
|
|
|
|
|
|
# TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here.
|
|
|
|
sdkBuildVersion = "17E189";
|
|
|
|
xcodeSelectVersion = "2349";
|
2016-06-26 05:45:55 +01:00
|
|
|
|
2019-04-23 03:45:58 +01:00
|
|
|
xcbuild = callPackage ./default.nix {
|
|
|
|
inherit CoreServices ImageIO CoreGraphics stdenv;
|
2016-06-26 05:45:55 +01:00
|
|
|
};
|
|
|
|
|
2019-04-23 03:45:58 +01:00
|
|
|
toolchains = callPackage ./toolchains.nix {
|
|
|
|
inherit toolchainName stdenv;
|
2016-06-26 05:45:55 +01:00
|
|
|
};
|
|
|
|
|
2019-04-23 03:45:58 +01:00
|
|
|
sdks = callPackage ./sdks.nix {
|
2018-07-06 23:49:38 +01:00
|
|
|
inherit toolchainName sdkName xcodePlatform;
|
|
|
|
version = sdkVer;
|
2016-06-26 05:45:55 +01:00
|
|
|
};
|
|
|
|
|
2019-04-23 03:45:58 +01:00
|
|
|
platforms = callPackage ./platforms.nix {
|
2018-07-06 23:49:38 +01:00
|
|
|
inherit sdks xcodePlatform;
|
2016-06-26 05:45:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
xcconfig = writeText "nix.xcconfig" ''
|
2016-11-06 00:51:15 +00:00
|
|
|
SDKROOT=${sdkName}
|
2016-06-26 05:45:55 +01:00
|
|
|
'';
|
|
|
|
|
2018-07-06 23:49:38 +01:00
|
|
|
xcode-select = writeText "xcode-select" ''
|
2019-02-26 11:45:54 +00:00
|
|
|
#!${runtimeShell}
|
2018-07-06 23:49:38 +01:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-h | --help) ;; # noop
|
|
|
|
-s | --switch) shift;; # noop
|
|
|
|
-r | --reset) ;; # noop
|
|
|
|
-v | --version) echo xcode-select version ${xcodeSelectVersion} ;;
|
2018-07-10 23:10:04 +01:00
|
|
|
-p | -print-path | --print-path) echo @DEVELOPER_DIR@ ;;
|
2018-07-06 23:49:38 +01:00
|
|
|
--install) ;; # noop
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
'';
|
2016-11-12 21:51:25 +00:00
|
|
|
|
2018-07-06 23:49:38 +01:00
|
|
|
xcrun = writeText "xcrun" ''
|
2019-02-26 11:45:54 +00:00
|
|
|
#!${runtimeShell}
|
2018-07-06 23:49:38 +01:00
|
|
|
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 05:45:55 +01:00
|
|
|
'';
|
|
|
|
|
2018-07-06 23:49:38 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
runCommand "xcodebuild-${xcbuild.version}" {
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2016-12-15 17:07:54 +00:00
|
|
|
inherit (xcbuild) meta;
|
|
|
|
|
2018-07-06 23:49:38 +01:00
|
|
|
# ensure that the toolchain goes in PATH
|
2018-07-11 16:45:23 +01:00
|
|
|
propagatedBuildInputs = [ "${toolchains}/XcodeDefault.xctoolchain" ];
|
2018-07-06 23:49:38 +01:00
|
|
|
|
2018-07-11 16:45:23 +01:00
|
|
|
passthru = {
|
|
|
|
inherit xcbuild;
|
|
|
|
toolchain = "${toolchains}/XcodeDefault.xctoolchain";
|
|
|
|
sdk = "${sdks}/${sdkName}";
|
|
|
|
platform = "${platforms}/${xcodePlatform}.platform";
|
|
|
|
};
|
2016-11-02 05:17:58 +00:00
|
|
|
|
2016-06-26 05:45:55 +01:00
|
|
|
preferLocalBuild = true;
|
2018-07-06 23:49:38 +01:00
|
|
|
} ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
|
2018-07-11 16:45:23 +01:00
|
|
|
ln -s $out $out/usr
|
2018-07-06 23:49:38 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-03-01 00:19:04 +00:00
|
|
|
mkdir -p $out/Applications/Xcode.app/Contents
|
|
|
|
ln -s $out $out/Applications/Xcode.app/Contents/Developer
|
|
|
|
|
2018-07-06 23:49:38 +01:00
|
|
|
makeWrapper ${xcbuild}/bin/xcodebuild $out/bin/xcodebuild \
|
|
|
|
--add-flags "-xcconfig ${xcconfig}" \
|
|
|
|
--add-flags "DERIVED_DATA_DIR=." \
|
|
|
|
--set DEVELOPER_DIR "$out" \
|
|
|
|
--set SDKROOT ${sdkName} \
|
2018-08-20 19:14:05 +01:00
|
|
|
--run '[ "$1" = "-version" ] && [ "$#" -eq 1 ] && (echo Xcode ${xcodeVer}; echo Build version ${sdkBuildVersion}) && exit 0' \
|
2018-07-11 16:45:23 +01:00
|
|
|
--run '[ "$1" = "-license" ] && exit 0'
|
2018-07-06 23:49:38 +01:00
|
|
|
|
|
|
|
substitute ${xcode-select} $out/bin/xcode-select \
|
2019-03-01 00:19:04 +00:00
|
|
|
--subst-var-by DEVELOPER_DIR $out/Applications/Xcode.app/Contents/Developer
|
2018-07-06 23:49:38 +01:00
|
|
|
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
|
|
|
|
''
|