xcbuild: rework to use lib.PLIST

This is a good way to test that plist works.

Sorry for the large diff. There are a bunch of cleanups in here that
needed to be done. Should make it possible to use in cross
compilation.

+83 -157
+4 -2
pkgs/development/tools/xcbuild/default.nix
··· 1 - { stdenv, cmake, fetchFromGitHub, zlib, libxml2, libpng, CoreServices, CoreGraphics, ImageIO, ninja }: 1 + { stdenv, cmake, fetchFromGitHub, zlib, libxml2, libpng 2 + , CoreServices, CoreGraphics, ImageIO, ninja }: 2 3 3 4 let 4 5 googletest = fetchFromGitHub { ··· 17 18 in stdenv.mkDerivation rec { 18 19 name = "xcbuild-${version}"; 19 20 20 - # Once a version is released that includes https://github.com/facebook/xcbuild/commit/183c087a6484ceaae860c6f7300caf50aea0d710, 21 + # Once a version is released that includes 22 + # https://github.com/facebook/xcbuild/commit/183c087a6484ceaae860c6f7300caf50aea0d710, 21 23 # we can stop doing this -pre thing. 22 24 version = "0.1.2-pre"; 23 25
+13 -21
pkgs/development/tools/xcbuild/platform.nix
··· 1 - { stdenv, sdk, writeText, platformName, xcbuild }: 1 + { runCommand, lib, sdk, platformName, writeText }: 2 2 3 3 let 4 + 5 + inherit (lib.generators) toPLIST; 4 6 5 7 Info = { 6 8 CFBundleIdentifier = platformName; ··· 283 285 284 286 in 285 287 286 - stdenv.mkDerivation { 287 - name = "MacOSX.platform"; 288 - buildInputs = [ xcbuild ]; 289 - buildCommand = '' 290 - mkdir -p $out/ 291 - cd $out/ 292 - 293 - plutil -convert xml1 -o Info.plist ${writeText "Info.plist" (builtins.toJSON Info)} 294 - plutil -convert xml1 -o version.plist ${writeText "version.plist" (builtins.toJSON Version)} 295 - 296 - mkdir -p $out/Developer/Library/Xcode/Specifications/ 297 - cd $out/Developer/Library/Xcode/Specifications/ 298 - plutil -convert xml1 -o Architectures.xcspec ${writeText "Architectures.xcspec" (builtins.toJSON Architectures)} 299 - plutil -convert xml1 -o PackageTypes.xcspec ${writeText "PackageTypes.xcspec" (builtins.toJSON PackageTypes)} 300 - plutil -convert xml1 -o ProductTypes.xcspec ${writeText "ProductTypes.xcspec" (builtins.toJSON ProductTypes)} 288 + runCommand "MacOSX.platform" {} '' 289 + install -D ${writeText "Info.plist" (toPLIST Info)} $out/Info.plist 290 + install -D ${writeText "version.plist" (toPLIST Version)} $out/version.plist 291 + install -D ${writeText "Architectures.xcspec" (toPLIST Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec 292 + install -D ${writeText "PackageTypes.xcspec" (toPLIST PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec 293 + install -D ${writeText "ProductTypes.xcspec" (toPLIST ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec 301 294 302 - mkdir -p $out/Developer/SDKs/ 303 - cd $out/Developer/SDKs/ 304 - cp -r ${sdk} ${sdk.name} 305 - ''; 306 - } 295 + mkdir -p $out/Developer/SDKs/ 296 + cd $out/Developer/SDKs/ 297 + cp -r ${sdk} ${sdk.name} 298 + ''
+8 -14
pkgs/development/tools/xcbuild/sdk.nix
··· 1 - { stdenv, writeText, toolchainName, sdkName, xcbuild }: 1 + { runCommand, lib, toolchainName, sdkName, writeText }: 2 2 3 3 let 4 + inherit (lib.generators) toPLIST; 5 + 4 6 # TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here. 5 7 version = "10.10"; 6 8 ··· 19 21 }; 20 22 in 21 23 22 - stdenv.mkDerivation { 23 - name = "MacOSX${version}.sdk"; 24 + runCommand "MacOSX${version}.sdk" { 24 25 inherit version; 25 - 26 - buildInputs = [ xcbuild ]; 27 - 28 - buildCommand = '' 29 - mkdir -p $out/ 30 - plutil -convert xml1 -o $out/SDKSettings.plist ${writeText "SDKSettings.json" (builtins.toJSON SDKSettings)} 31 - 32 - mkdir -p $out/System/Library/CoreServices/ 33 - plutil -convert xml1 -o $out/System/Library/CoreServices/SystemVersion.plist ${writeText "SystemVersion.plist" (builtins.toJSON SystemVersion)} 34 - ''; 35 - } 26 + } '' 27 + install -D ${writeText "SDKSettings.plist" (toPLIST SDKSettings)} $out/SDKSettings.plist 28 + install -D ${writeText "SystemVersion.plist" (toPLIST SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist 29 + ''
+42 -102
pkgs/development/tools/xcbuild/toolchain.nix
··· 1 - {stdenv, writeText, toolchainName, xcbuild, fetchurl 2 - , llvm, cctools, gcc, bootstrap_cmds, binutils 3 - , yacc, flex, m4, unifdef, gperf, indent, ctags, makeWrapper 4 - , xib2nib}: 1 + { runCommand, toolchainName, fetchurl, makeWrapper, stdenv 2 + , buildPackages, lib, writeText }: 5 3 6 4 let 5 + 6 + inherit (lib) getBin optionalString; 7 + inherit (lib.generators) toPLIST; 7 8 8 9 ToolchainInfo = { 9 10 Identifier = toolchainName; 10 11 }; 11 12 12 - # We could pull this out of developer_cmds but it adds an annoying loop if we want to bootstrap and 13 - # this is just a tiny script so I'm not going to bother 13 + # We could pull this out of developer_cmds but it adds an annoying 14 + # loop if we want to bootstrap and this is just a tiny script so I'm 15 + # not going to bother. 14 16 mkdep-darwin-src = fetchurl { 15 17 url = "https://opensource.apple.com/source/developer_cmds/developer_cmds-63/mkdep/mkdep.sh"; 16 18 sha256 = "0n4wpqfslfjs5zbys5yri8pfi2awyhlmknsf6laa5jzqbzq9x541"; ··· 18 20 }; 19 21 in 20 22 21 - stdenv.mkDerivation { 22 - name = "nixpkgs.xctoolchain"; 23 - buildInputs = [ xcbuild makeWrapper ]; 24 - 25 - ## cctools should build on Linux but it doesn't currently 26 - 27 - buildCommand = '' 28 - mkdir -p $out 29 - plutil -convert xml1 -o $out/ToolchainInfo.plist ${writeText "ToolchainInfo.plist" (builtins.toJSON ToolchainInfo)} 30 - 31 - mkdir -p $out/usr/include 32 - mkdir -p $out/usr/lib 33 - mkdir -p $out/usr/libexec 34 - mkdir -p $out/usr/share 35 - 36 - mkdir -p $out/usr/bin 37 - cd $out/usr/bin 38 - ln -s ${stdenv.cc}/bin/cpp 39 - ln -s ${stdenv.cc}/bin/c++ 40 - ln -s ${stdenv.cc}/bin/cc 41 - ln -s c++ clang++ 42 - ln -s cc clang 43 - 44 - ln -s ${llvm}/bin/llvm-cov 45 - ln -s ${llvm}/bin/llvm-dsymutil 46 - ln -s ${llvm}/bin/llvm-dwarfdump 47 - ln -s ${llvm}/bin/llvm-nm 48 - ln -s ${llvm}/bin/llvm-objdump 49 - ln -s ${llvm}/bin/llvm-otool 50 - ln -s ${llvm}/bin/llvm-profdata 51 - ln -s ${llvm}/bin/llvm-size 52 - 53 - ln -s ${yacc}/bin/yacc 54 - ln -s ${yacc}/bin/bison 55 - ln -s ${flex}/bin/flex 56 - ln -s ${flex}/bin/flex++ 57 - 58 - ln -s flex lex 59 - 60 - ln -s ${m4}/bin/m4 61 - ln -s m4 gm4 23 + runCommand "nixpkgs.xctoolchain" { 24 + nativeBuildInputs = [ makeWrapper ]; 25 + } ('' 26 + mkdir -p $out 27 + install -D ${writeText "ToolchainInfo.plist" (toPLIST ToolchainInfo)} $out/ToolchainInfo.plist 62 28 63 - ln -s ${unifdef}/bin/unifdef 64 - ln -s ${unifdef}/bin/unifdefall 29 + mkdir -p $out/usr/include 30 + mkdir -p $out/usr/lib 31 + mkdir -p $out/usr/libexec 32 + mkdir -p $out/usr/share 33 + mkdir -p $out/usr/bin 65 34 66 - ln -s ${gperf}/bin/gperf 67 - ln -s ${indent}/bin/indent 68 - ln -s ${ctags}/bin/ctags 69 - '' + stdenv.lib.optionalString stdenv.isDarwin '' 70 - ln -s ${bootstrap_cmds}/bin/mig 71 - ln -s ${binutils}/bin/lipo 35 + for bin in ${getBin stdenv.cc}/bin/*; do 36 + ln -s $bin $out/usr/bin 37 + done 72 38 73 - ln -s ${cctools}/bin/ar 74 - ln -s ${cctools}/bin/as 75 - ln -s ${cctools}/bin/nm 76 - ln -s ${cctools}/bin/nmedit 77 - ln -s ${cctools}/bin/ld 78 - ln -s ${cctools}/bin/libtool 79 - ln -s ${cctools}/bin/strings 80 - ln -s ${cctools}/bin/strip 81 - ln -s ${cctools}/bin/install_name_tool 82 - ln -s ${cctools}/bin/bitcode_strip 83 - ln -s ${cctools}/bin/codesign_allocate 84 - ln -s ${cctools}/bin/dsymutil 85 - ln -s ${cctools}/bin/dyldinfo 86 - ln -s ${cctools}/bin/otool 87 - ln -s ${cctools}/bin/unwinddump 88 - ln -s ${cctools}/bin/size 89 - ln -s ${cctools}/bin/segedit 90 - ln -s ${cctools}/bin/pagestuff 91 - ln -s ${cctools}/bin/ranlib 92 - ln -s ${cctools}/bin/redo_prebinding 39 + for bin in ${getBin stdenv.cc.bintools.bintools}/bin/*; do 40 + if ! [ -e "$out/usr/bin/$(basename $bin)" ]; then 41 + ln -s $bin $out/usr/bin 42 + fi 43 + done 93 44 94 - ln -s ${xib2nib}/bin/ibtool 95 - '' + 96 - # No point including the entire gcc closure if we don't already have it 97 - (if stdenv.cc.isClang then '' 98 - ln -s ${stdenv.cc.cc.llvm}/bin/llvm-cov gcov 99 - ln -s ${mkdep-darwin-src} mkdep 100 - '' else '' 101 - ln -s ${gcc}/bin/gcov 102 - ln -s ${gcc}/bin/mkdep 103 - ''); 104 - } 45 + ln -s ${buildPackages.yacc}/bin/yacc $out/usr/bin/yacc 46 + ln -s ${buildPackages.yacc}/bin/bison $out/usr/bin/bison 47 + ln -s ${buildPackages.flex}/bin/flex $out/usr/bin/flex 48 + ln -s ${buildPackages.flex}/bin/flex++ $out/usr/bin/flex++ 49 + ln -s $out/bin/flex $out/usr/bin/lex 105 50 106 - # other commands in /bin/ 107 - # asa 108 - # cmpdylib (in cctools) 109 - # ctf_insert (in cctools) 110 - # dwarfdump 111 - # lorder 112 - # rebase 113 - # rpcgen (in developer_cmds) 114 - # what 51 + ln -s ${buildPackages.m4}/bin/m4 $out/usr/bin/m4 52 + ln -s $out/usr/bin/m4 $out/usr/bin/gm4 115 53 54 + ln -s ${buildPackages.unifdef}/bin/unifdef $out/usr/bin/unifdef 55 + ln -s ${buildPackages.unifdef}/bin/unifdefall $out/usr/bin/unifdefall 116 56 117 - # swift: see #11463 118 - # swift 119 - # swift-compress 120 - # swift-demangle 121 - # swift-stdlib-tool 122 - # swift-update 123 - # swiftc 57 + ln -s ${buildPackages.gperf}/bin/gperf $out/usr/bin/gperf 58 + ln -s ${buildPackages.indent}/bin/indent $out/usr/bin/indent 59 + ln -s ${buildPackages.ctags}/bin/ctags $out/usr/bin/ctags 60 + '' + optionalString stdenv.isDarwin '' 61 + ln -s ${buildPackages.darwin.bootstrap_cmds}/bin/mig $out/usr/bin 62 + ln -s ${mkdep-darwin-src} $out/usr/bin/mkdep 63 + '')
+15 -16
pkgs/development/tools/xcbuild/wrapper.nix
··· 1 - { stdenv, callPackage, makeWrapper, writeText, CoreServices, ImageIO, CoreGraphics 2 - , cctools, bootstrap_cmds, binutils}: 1 + { stdenv, buildPackages, makeWrapper, writeText, runCommand 2 + , CoreServices, ImageIO, CoreGraphics }: 3 3 4 4 let 5 5 ··· 7 7 platformName = "com.apple.platform.macosx"; 8 8 sdkName = "macosx10.10"; 9 9 10 - xcbuild = callPackage ./default.nix { 10 + xcbuild = buildPackages.callPackage ./default.nix { 11 11 inherit CoreServices ImageIO CoreGraphics; 12 12 }; 13 13 14 - toolchain = callPackage ./toolchain.nix { 15 - inherit cctools bootstrap_cmds toolchainName xcbuild binutils stdenv; 14 + toolchain = buildPackages.callPackage ./toolchain.nix { 15 + inherit toolchainName; 16 16 }; 17 17 18 - sdk = callPackage ./sdk.nix { 19 - inherit toolchainName sdkName xcbuild; 18 + sdk = buildPackages.callPackage ./sdk.nix { 19 + inherit toolchainName sdkName; 20 20 }; 21 21 22 - platform = callPackage ./platform.nix { 23 - inherit sdk platformName xcbuild; 22 + platform = buildPackages.callPackage ./platform.nix { 23 + inherit sdk platformName; 24 24 }; 25 25 26 26 xcconfig = writeText "nix.xcconfig" '' ··· 32 32 stdenv.mkDerivation { 33 33 name = "xcbuild-wrapper-${xcbuild.version}"; 34 34 35 - buildInputs = [ xcbuild makeWrapper ]; 35 + nativeBuildInputs = [ makeWrapper ]; 36 36 37 37 setupHook = ./setup-hook.sh; 38 38 ··· 40 40 41 41 installPhase = '' 42 42 mkdir -p $out/bin 43 - cd $out/bin/ 44 43 45 44 for file in ${xcbuild}/bin/*; do 46 - ln -s $file 45 + ln -s $file $out/bin 47 46 done 48 47 49 - mkdir $out/usr 48 + mkdir -p $out/usr 50 49 ln -s $out/bin $out/usr/bin 51 50 52 - mkdir -p $out/Library/Xcode/ 51 + mkdir -p $out/Library/Xcode 53 52 ln -s ${xcbuild}/Library/Xcode/Specifications $out/Library/Xcode/Specifications 54 53 55 - mkdir -p $out/Platforms/ 54 + mkdir -p $out/Platforms 56 55 ln -s ${platform} $out/Platforms/nixpkgs.platform 57 56 58 - mkdir -p $out/Toolchains/ 57 + mkdir -p $out/Toolchains 59 58 ln -s ${toolchain} $out/Toolchains/nixpkgs.xctoolchain 60 59 61 60 wrapProgram $out/bin/xcodebuild \
+1 -2
pkgs/top-level/all-packages.nix
··· 8570 8570 8571 8571 xcbuild = callPackage ../development/tools/xcbuild/wrapper.nix { 8572 8572 inherit (darwin.apple_sdk.frameworks) CoreServices CoreGraphics ImageIO; 8573 - inherit (darwin) cctools bootstrap_cmds binutils; 8574 - stdenv = clangStdenv; 8573 + stdenv = buildPackages.clangStdenv; 8575 8574 }; 8576 8575 8577 8576 xmlindent = callPackage ../development/web/xmlindent {};