bazel: add darwin support

This commit is contained in:
Uri Baghin 2018-05-23 17:18:44 +10:00 committed by Matthew Bauer
parent 0acad472a4
commit 274bb96073
3 changed files with 50 additions and 7 deletions

View file

@ -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

View file

@ -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).

View file

@ -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;