nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05 142 lines 4.6 kB view raw
1{ stdenv, makeWrapper, writeText, runCommand 2, CoreServices, ImageIO, CoreGraphics 3, runtimeShell, callPackage 4, xcodePlatform ? stdenv.targetPlatform.xcodePlatform or "MacOSX" 5, xcodeVer ? stdenv.targetPlatform.xcodeVer or "9.4.1" 6, sdkVer ? stdenv.targetPlatform.darwinSdkVersion or "10.12" }: 7 8let 9 10 toolchainName = "com.apple.dt.toolchain.XcodeDefault"; 11 sdkName = "${xcodePlatform}${sdkVer}"; 12 13 # TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here. 14 sdkBuildVersion = "17E189"; 15 xcodeSelectVersion = "2349"; 16 17 xcbuild = callPackage ./default.nix { 18 inherit CoreServices ImageIO CoreGraphics stdenv; 19 }; 20 21 toolchains = callPackage ./toolchains.nix { 22 inherit toolchainName stdenv; 23 }; 24 25 sdks = callPackage ./sdks.nix { 26 inherit toolchainName sdkName xcodePlatform; 27 version = sdkVer; 28 }; 29 30 platforms = callPackage ./platforms.nix { 31 inherit sdks xcodePlatform stdenv; 32 }; 33 34 xcconfig = writeText "nix.xcconfig" '' 35 SDKROOT=${sdkName} 36 ''; 37 38 xcode-select = writeText "xcode-select" '' 39#!${runtimeShell} 40while [ $# -gt 0 ]; do 41 case "$1" in 42 -h | --help) ;; # noop 43 -s | --switch) shift;; # noop 44 -r | --reset) ;; # noop 45 -v | --version) echo xcode-select version ${xcodeSelectVersion} ;; 46 -p | -print-path | --print-path) echo @DEVELOPER_DIR@ ;; 47 --install) ;; # noop 48 esac 49 shift 50done 51 ''; 52 53 xcrun = writeText "xcrun" '' 54#!${runtimeShell} 55while [ $# -gt 0 ]; do 56 case "$1" in 57 --sdk | -sdk) shift ;; 58 --find | -find) 59 shift 60 command -v $1 ;; 61 --log | -log) ;; # noop 62 --verbose | -verbose) ;; # noop 63 --no-cache | -no-cache) ;; # noop 64 --kill-cache | -kill-cache) ;; # noop 65 --show-sdk-path | -show-sdk-path) 66 echo ${sdks}/${sdkName}.sdk ;; 67 --show-sdk-platform-path | -show-sdk-platform-path) 68 echo ${platforms}/${xcodePlatform}.platform ;; 69 --show-sdk-version | -show-sdk-version) 70 echo ${sdkVer} ;; 71 --show-sdk-build-version | -show-sdk-build-version) 72 echo ${sdkBuildVersion} ;; 73 *) break ;; 74 esac 75 shift 76done 77if ! [[ -z "$@" ]]; then 78 exec "$@" 79fi 80 ''; 81 82in 83 84runCommand "xcodebuild-${xcbuild.version}" { 85 nativeBuildInputs = [ makeWrapper ]; 86 inherit (xcbuild) meta; 87 88 # ensure that the toolchain goes in PATH 89 propagatedBuildInputs = [ "${toolchains}/XcodeDefault.xctoolchain" ]; 90 91 passthru = { 92 inherit xcbuild; 93 toolchain = "${toolchains}/XcodeDefault.xctoolchain"; 94 sdk = "${sdks}/${sdkName}"; 95 platform = "${platforms}/${xcodePlatform}.platform"; 96 }; 97 98 preferLocalBuild = true; 99} '' 100 mkdir -p $out/bin 101 102 ln -s $out $out/usr 103 104 mkdir -p $out/Library/Xcode 105 ln -s ${xcbuild}/Library/Xcode/Specifications $out/Library/Xcode/Specifications 106 107 ln -s ${platforms} $out/Platforms 108 ln -s ${toolchains} $out/Toolchains 109 110 mkdir -p $out/Applications/Xcode.app/Contents 111 ln -s $out $out/Applications/Xcode.app/Contents/Developer 112 113 # The native xcodebuild command supports an invocation like "xcodebuild -version -sdk" without specifying the specific SDK, so we simulate this by 114 # detecting this case and simulating the output; printing the header and appending the normal output via appending the sdk version to the positional 115 # arguments we pass through to the wrapped xcodebuild. 116 makeWrapper ${xcbuild}/bin/xcodebuild $out/bin/xcodebuild \ 117 --add-flags "-xcconfig ${xcconfig}" \ 118 --add-flags "DERIVED_DATA_DIR=." \ 119 --set DEVELOPER_DIR "$out" \ 120 --set SDKROOT ${sdkName} \ 121 --run '[ "$#" -eq 2 ] && [ "$1" = "-version" ] && [ "$2" = "-sdk" ] && echo ${sdkName}.sdk - macOS ${sdkVer} \(macosx${sdkVer}\) && set -- "$@" "${sdkName}"' \ 122 --run '[ "$1" = "-version" ] && [ "$#" -eq 1 ] && (echo Xcode ${xcodeVer}; echo Build version ${sdkBuildVersion}) && exit 0' \ 123 --run '[ "$1" = "-license" ] && exit 0' 124 125 substitute ${xcode-select} $out/bin/xcode-select \ 126 --subst-var-by DEVELOPER_DIR $out/Applications/Xcode.app/Contents/Developer 127 chmod +x $out/bin/xcode-select 128 129 substitute ${xcrun} $out/bin/xcrun 130 chmod +x $out/bin/xcrun 131 132 for bin in PlistBuddy actool builtin-copy builtin-copyPlist \ 133 builtin-copyStrings builtin-copyTiff \ 134 builtin-embeddedBinaryValidationUtility \ 135 builtin-infoPlistUtility builtin-lsRegisterURL \ 136 builtin-productPackagingUtility builtin-validationUtility \ 137 lsbom plutil; do 138 ln -s ${xcbuild}/bin/$bin $out/bin/$bin 139 done 140 141 fixupPhase 142''