bazel: add darwin support

This commit is contained in:
Uri Baghin
2018-06-12 23:23:51 -04:00
committed by Matthew Bauer
parent 0acad472a4
commit 274bb96073
3 changed files with 50 additions and 7 deletions
@@ -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).