diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 73da775f7f56..bce5436353c3 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 d5eaa24c1675..e641e69bae6d 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 + #include + #include + #include + + 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 718041ee753b..94ebd20a0f5b 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;