diff options
author | Uri Baghin <uri@canva.com> | 2018-05-23 17:18:44 +1000 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2018-06-12 23:23:51 -0400 |
commit | 274bb96073d9b263821dc68a1d2d65bec24b99f2 (patch) | |
tree | 88fe22d0d7d6626b7735a4a4e606215b951ad267 /pkgs | |
parent | 0acad472a4bf33ecadbdf3083f7b4745b218d44a (diff) | |
download | nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.tar nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.tar.gz nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.tar.bz2 nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.tar.lz nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.tar.xz nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.tar.zst nixpkgs-274bb96073d9b263821dc68a1d2d65bec24b99f2.zip |
bazel: add darwin support
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/build-support/trivial-builders.nix | 18 | ||||
-rw-r--r-- | pkgs/development/tools/build-managers/bazel/default.nix | 35 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 4 |
3 files changed, 50 insertions, 7 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 73da775f7f5..bce5436353c 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -72,6 +72,24 @@ rec { ''; }; + # Create a C binary + writeCBin = name: code: + runCommandCC name + { + inherit name code; + executable = true; + passAsFile = ["code"]; + # Pointless to do this on a remote machine. + preferLocalBuild = true; + allowSubstitutes = false; + } + '' + n=$out/bin/$name + mkdir -p "$(dirname "$n")" + mv "$codePath" code.c + $CC -x c code.c -o "$n" + ''; + # Create a forest of symlinks to the files in `paths'. symlinkJoin = args_@{ name diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix index d5eaa24c167..e641e69bae6 100644 --- a/pkgs/development/tools/build-managers/bazel/default.nix +++ b/pkgs/development/tools/build-managers/bazel/default.nix @@ -1,7 +1,9 @@ -{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, writeScriptBin, coreutils, makeWrapper, which, python +{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, writeCBin, coreutils, makeWrapper, which, python # Always assume all markers valid (don't redownload dependencies). # Also, don't clean up environment variables. , enableNixHacks ? false +# Apple dependencies +, libcxx, CoreFoundation, CoreServices, Foundation }: stdenv.mkDerivation rec { @@ -13,7 +15,7 @@ stdenv.mkDerivation rec { description = "Build tool that builds code quickly and reliably"; license = licenses.asl20; maintainers = [ maintainers.philandstuff ]; - platforms = platforms.linux; + platforms = platforms.linux ++ platforms.darwin; }; name = "bazel-${version}"; @@ -29,9 +31,30 @@ stdenv.mkDerivation rec { # Bazel expects several utils to be available in Bash even without PATH. Hence this hack. - customBash = writeScriptBin "bash" '' - #!${stdenv.shell} - PATH="$PATH:${lib.makeBinPath [ coreutils ]}" exec ${bash}/bin/bash "$@" + customBash = writeCBin "bash" '' + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include <unistd.h> + + extern char **environ; + + int main(int argc, char *argv[]) { + printf("environ: %s\n", environ[0]); + char *path = getenv("PATH"); + char *pathToAppend = "${lib.makeBinPath [ coreutils ]}"; + char *newPath; + if (path != NULL) { + int length = strlen(path) + 1 + strlen(pathToAppend) + 1; + newPath = malloc(length * sizeof(char)); + snprintf(newPath, length, "%s:%s", path, pathToAppend); + } else { + newPath = pathToAppend; + } + setenv("PATH", newPath, 1); + execve("${bash}/bin/bash", argv, environ); + return 0; + } ''; postPatch = '' @@ -54,7 +77,7 @@ stdenv.mkDerivation rec { makeWrapper which customBash - ]; + ] ++ lib.optionals (stdenv.isDarwin) [ libcxx CoreFoundation CoreServices Foundation ]; # If TMPDIR is in the unpack dir we run afoul of blaze's infinite symlink # detector (see com.google.devtools.build.lib.skyframe.FileFunction). diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 718041ee753..94ebd20a0f5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7711,7 +7711,9 @@ with pkgs; bam = callPackage ../development/tools/build-managers/bam {}; bazel_0_4 = callPackage ../development/tools/build-managers/bazel/0.4.nix { }; - bazel = callPackage ../development/tools/build-managers/bazel { }; + bazel = callPackage ../development/tools/build-managers/bazel { + inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Foundation; + }; bazel-buildtools = callPackage ../development/tools/build-managers/bazel/buildtools { }; buildifier = bazel-buildtools; |