git.iko.soy/typeable/nixpkgs
on master help sign in
bazel: add darwin support
commit274bb96073d9b263821dc68a1d2d65bec24b99f2 authorUri Baghin <uri@canva.com> dateWed 23 May 2018, 17:18 (9 years ago) parent0acad47
3 files changed+50−7
pkgs/build-support/trivial-builders.nix+18 pkgs/development/tools/build-managers/bazel/default.nix+29−6 pkgs/top-level/all-packages.nix+3−1
pkgs/build-support/trivial-builders.nix+18
@@ -72,6 +72,24 @@ rec {
7272 '';
7373 };
7474
75+ # Create a C binary
76+ writeCBin = name: code:
77+ runCommandCC name
78+ {
79+ inherit name code;
80+ executable = true;
81+ passAsFile = ["code"];
82+ # Pointless to do this on a remote machine.
83+ preferLocalBuild = true;
84+ allowSubstitutes = false;
85+ }
86+ ''
87+ n=$out/bin/$name
88+ mkdir -p "$(dirname "$n")"
89+ mv "$codePath" code.c
90+ $CC -x c code.c -o "$n"
91+ '';
92+
7593 # Create a forest of symlinks to the files in `paths'.
7694 symlinkJoin =
7795 args_@{ name
pkgs/development/tools/build-managers/bazel/default.nix+29−6
@@ -1,7 +1,9 @@
1−{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, writeScriptBin, coreutils, makeWrapper, which, python
1+{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, writeCBin, coreutils, makeWrapper, which, python
22# Always assume all markers valid (don't redownload dependencies).
33# Also, don't clean up environment variables.
44, enableNixHacks ? false
5+# Apple dependencies
6+, libcxx, CoreFoundation, CoreServices, Foundation
57}:
68
79stdenv.mkDerivation rec {
@@ -13,7 +15,7 @@ stdenv.mkDerivation rec {
1315 description = "Build tool that builds code quickly and reliably";
1416 license = licenses.asl20;
1517 maintainers = [ maintainers.philandstuff ];
16− platforms = platforms.linux;
18+ platforms = platforms.linux ++ platforms.darwin;
1719 };
1820
1921 name = "bazel-${version}";
@@ -29,9 +31,30 @@ stdenv.mkDerivation rec {
2931
3032 # Bazel expects several utils to be available in Bash even without PATH. Hence this hack.
3133
32− customBash = writeScriptBin "bash" ''
33− #!${stdenv.shell}
34− PATH="$PATH:${lib.makeBinPath [ coreutils ]}" exec ${bash}/bin/bash "$@"
34+ customBash = writeCBin "bash" ''
35+ #include <stdio.h>
36+ #include <stdlib.h>
37+ #include <string.h>
38+ #include <unistd.h>
39+
40+ extern char **environ;
41+
42+ int main(int argc, char *argv[]) {
43+ printf("environ: %s\n", environ[0]);
44+ char *path = getenv("PATH");
45+ char *pathToAppend = "${lib.makeBinPath [ coreutils ]}";
46+ char *newPath;
47+ if (path != NULL) {
48+ int length = strlen(path) + 1 + strlen(pathToAppend) + 1;
49+ newPath = malloc(length * sizeof(char));
50+ snprintf(newPath, length, "%s:%s", path, pathToAppend);
51+ } else {
52+ newPath = pathToAppend;
53+ }
54+ setenv("PATH", newPath, 1);
55+ execve("${bash}/bin/bash", argv, environ);
56+ return 0;
57+ }
3558 '';
3659
3760 postPatch = ''
@@ -54,7 +77,7 @@ stdenv.mkDerivation rec {
5477 makeWrapper
5578 which
5679 customBash
57− ];
80+ ] ++ lib.optionals (stdenv.isDarwin) [ libcxx CoreFoundation CoreServices Foundation ];
5881
5982 # If TMPDIR is in the unpack dir we run afoul of blaze's infinite symlink
6083 # detector (see com.google.devtools.build.lib.skyframe.FileFunction).
pkgs/top-level/all-packages.nix+3−1
@@ -7711,7 +7711,9 @@ with pkgs;
77117711 bam = callPackage ../development/tools/build-managers/bam {};
77127712
77137713 bazel_0_4 = callPackage ../development/tools/build-managers/bazel/0.4.nix { };
7714− bazel = callPackage ../development/tools/build-managers/bazel { };
7714+ bazel = callPackage ../development/tools/build-managers/bazel {
7715+ inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Foundation;
7716+ };
77157717
77167718 bazel-buildtools = callPackage ../development/tools/build-managers/bazel/buildtools { };
77177719 buildifier = bazel-buildtools;