Merge staging-next into staging

This commit is contained in:
Frederik Rietdijk
2019-07-03 08:59:42 +02:00
411 changed files with 4314 additions and 2253 deletions
@@ -0,0 +1,49 @@
{
bazel
, bazelTest
, bazel-examples
, gccStdenv
, lib
, runLocal
, runtimeShell
, writeScript
, writeText
}:
let
toolsBazel = writeScript "bazel" ''
#! ${runtimeShell}
export CXX='${gccStdenv.cc}/bin/g++'
export LD='${gccStdenv.cc}/bin/ld'
export CC='${gccStdenv.cc}/bin/gcc'
# XXX: hack for macosX, this flags disable bazel usage of xcode
# See: https://github.com/bazelbuild/bazel/issues/4231
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
exec "$BAZEL_REAL" "$@"
'';
workspaceDir = runLocal "our_workspace" {} (''
cp -r ${bazel-examples}/cpp-tutorial/stage3 $out
find $out -type d -exec chmod 755 {} \;
''
+ (lib.optionalString gccStdenv.isDarwin ''
mkdir $out/tools
cp ${toolsBazel} $out/tools/bazel
''));
testBazel = bazelTest {
name = "bazel-test-cpp";
inherit workspaceDir;
bazelPkg = bazel;
bazelScript = ''
${bazel}/bin/bazel \
build --verbose_failures \
//...
'';
};
in testBazel
@@ -1,4 +1,4 @@
{ stdenv, callPackage, lib, fetchurl, runCommand, runCommandCC, makeWrapper
{ stdenv, callPackage, lib, fetchurl, fetchFromGitHub, runCommand, runCommandCC, makeWrapper
# this package (through the fixpoint glass)
, bazel
, lr, xe, zip, unzip, bash, writeCBin, coreutils
@@ -94,8 +94,7 @@ let
# however it contains prebuilt java binaries, with wrong interpreter
# and libraries path.
# We prefetch it, patch it, and override it in a global bazelrc.
system = if stdenv.hostPlatform.isDarwin
then "darwin" else "linux";
system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";
remote_java_tools = stdenv.mkDerivation {
name = "remote_java_tools_${system}";
@@ -133,6 +132,11 @@ stdenv.mkDerivation rec {
sourceRoot = ".";
patches = [
# On Darwin, the last argument to gcc is coming up as an empty string. i.e: ''
# This is breaking the build of any C target. This patch removes the last
# argument if it's found to be an empty string.
./trim-last-argument-to-gcc-if-empty.patch
./python-stub-path-fix.patch
] ++ lib.optional enableNixHacks ./nix-hacks.patch;
@@ -144,11 +148,16 @@ stdenv.mkDerivation rec {
# in the nixpkgs checkout root to exercise them locally.
passthru.tests =
let
runLocal = name: attrs: script: runCommandCC name ({
runLocal = name: attrs: script:
let
attrs' = removeAttrs attrs [ "buildInputs" ];
buildInputs = [ python3 ] ++ (attrs.buildInputs or []);
in
runCommandCC name ({
inherit buildInputs;
preferLocalBuild = true;
meta.platforms = platforms;
buildInputs = [ python3 ];
} // attrs) script;
} // attrs') script;
# bazel wants to extract itself into $install_dir/install every time it runs,
# so lets do that only once.
@@ -168,10 +177,10 @@ stdenv.mkDerivation rec {
cp -R ${install_dir} $out
'';
bazelTest = { name, bazelScript, workspaceDir, bazelPkg }:
bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
let
be = extracted bazelPkg;
in runLocal name {} (
in runLocal name { inherit buildInputs; } (
# skip extraction caching on Darwin, because nobody knows how Darwin works
(lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
# set up home with pre-unpacked bazel
@@ -198,12 +207,26 @@ stdenv.mkDerivation rec {
'');
bazelWithNixHacks = bazel.override { enableNixHacks = true; };
in {
pythonBinPathWithoutNixHacks = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; };
bashToolsWithoutNixHacks = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; };
pythonBinPathWithNixHacks = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
bazel-examples = fetchFromGitHub {
owner = "bazelbuild";
repo = "examples";
rev = "5d8c8961a2516ebf875787df35e98cadd08d43dc";
sha256 = "03c1bwlq5bs3hg96v4g4pg2vqwhqq6w538h66rcpw02f83yy7fs8";
};
in {
bashTools = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; };
cpp = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; };
java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples; };
protobuf = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; };
pythonBinPath = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; };
bashToolsWithNixHacks = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
cppWithNixHacks = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; bazel = bazelWithNixHacks; };
javaWithNixHacks = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples; bazel = bazelWithNixHacks; };
protobufWithNixHacks = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
pythonBinPathWithNixHacks = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
};
# update the list of workspace dependencies
@@ -220,7 +243,6 @@ stdenv.mkDerivation rec {
__darwinAllowLocalNetworking = true;
# Bazel expects several utils to be available in Bash even without PATH. Hence this hack.
customBash = writeCBin "bash" ''
#include <stdio.h>
#include <stdlib.h>
@@ -0,0 +1,56 @@
{
bazel
, bazelTest
, bazel-examples
, gccStdenv
, lib
, openjdk8
, runLocal
, runtimeShell
, writeScript
, writeText
}:
let
toolsBazel = writeScript "bazel" ''
#! ${runtimeShell}
export CXX='${gccStdenv.cc}/bin/g++'
export LD='${gccStdenv.cc}/bin/ld'
export CC='${gccStdenv.cc}/bin/gcc'
# XXX: hack for macosX, this flags disable bazel usage of xcode
# See: https://github.com/bazelbuild/bazel/issues/4231
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
exec "$BAZEL_REAL" "$@"
'';
workspaceDir = runLocal "our_workspace" {} (''
cp -r ${bazel-examples}/java-tutorial $out
find $out -type d -exec chmod 755 {} \;
''
+ (lib.optionalString gccStdenv.isDarwin ''
mkdir $out/tools
cp ${toolsBazel} $out/tools/bazel
''));
testBazel = bazelTest {
name = "bazel-test-cpp";
inherit workspaceDir;
bazelPkg = bazel;
buildInputs = [ openjdk8 ];
bazelScript = ''
${bazel}/bin/bazel \
run \
--host_javabase='@local_jdk//:jdk' \
--java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
--javabase='@local_jdk//:jdk' \
--verbose_failures \
//:ProjectRunner
'';
};
in testBazel
@@ -0,0 +1,152 @@
{
bazel
, bazelTest
, fetchFromGitHub
, fetchurl
, gccStdenv
, lib
, openjdk8
, runLocal
, runtimeShell
, writeScript
, writeText
}:
let
com_google_protobuf = fetchFromGitHub {
owner = "protocolbuffers";
repo = "protobuf";
rev = "v3.7.0";
sha256 = "0nlxif4cajqllsj2vdh7zp14ag48fb8lsa64zmq8625q9m2lcmdh";
};
bazel_skylib = fetchFromGitHub {
owner = "bazelbuild";
repo = "bazel-skylib";
rev = "f83cb8dd6f5658bc574ccd873e25197055265d1c";
sha256 = "091fb0ky0956wgv8gghy9ay3yfx6497mb72qvibf0y9dllmxyn9l";
};
net_zlib = fetchurl rec {
url = "https://zlib.net/zlib-1.2.11.tar.gz";
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1";
passthru.sha256 = sha256;
};
WORKSPACE = writeText "WORKSPACE" ''
workspace(name = "our_workspace")
load("//:proto-support.bzl", "protobuf_deps")
protobuf_deps()
'';
protoSupport = writeText "proto-support.bzl" ''
"""Load dependencies needed to compile the protobuf library as a 3rd-party consumer."""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def protobuf_deps():
"""Loads common dependencies needed to compile the protobuf library."""
if "zlib" not in native.existing_rules():
# proto_library, cc_proto_library, and java_proto_library rules implicitly
# depend on @com_google_protobuf for protoc and proto runtimes.
# This statement defines the @com_google_protobuf repo.
native.local_repository(
name = "com_google_protobuf",
path = "${com_google_protobuf}",
)
native.local_repository(
name = "bazel_skylib",
path = "${bazel_skylib}",
)
native.bind(
name = "zlib",
actual = "@net_zlib//:zlib",
)
http_archive(
name = "net_zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "${net_zlib.sha256}",
strip_prefix = "zlib-1.2.11",
urls = ["file://${net_zlib}"],
)
'';
personProto = writeText "person.proto" ''
syntax = "proto3";
package person;
message Person {
string name = 1;
int32 id = 2;
string email = 3;
}
'';
personBUILD = writeText "BUILD" ''
proto_library(
name = "person_proto",
srcs = ["person.proto"],
visibility = ["//visibility:public"],
)
java_proto_library(
name = "person_java_proto",
deps = [":person_proto"],
)
cc_proto_library(
name = "person_cc_proto",
deps = [":person_proto"],
)
'';
toolsBazel = writeScript "bazel" ''
#! ${runtimeShell}
export CXX='${gccStdenv.cc}/bin/g++'
export LD='${gccStdenv.cc}/bin/ld'
export CC='${gccStdenv.cc}/bin/gcc'
# XXX: hack for macosX, this flags disable bazel usage of xcode
# See: https://github.com/bazelbuild/bazel/issues/4231
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
exec "$BAZEL_REAL" "$@"
'';
workspaceDir = runLocal "our_workspace" {} (''
mkdir $out
cp ${WORKSPACE} $out/WORKSPACE
touch $out/BUILD.bazel
cp ${protoSupport} $out/proto-support.bzl
mkdir $out/person
cp ${personProto} $out/person/person.proto
cp ${personBUILD} $out/person/BUILD.bazel
''
+ (lib.optionalString gccStdenv.isDarwin ''
mkdir $out/tools
cp ${toolsBazel} $out/tools/bazel
''));
testBazel = bazelTest {
name = "bazel-test-protocol-buffers";
inherit workspaceDir;
bazelPkg = bazel;
buildInputs = [ openjdk8 ];
bazelScript = ''
${bazel}/bin/bazel \
build \
--host_javabase='@local_jdk//:jdk' \
--java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
--javabase='@local_jdk//:jdk' \
--verbose_failures \
//...
'';
};
in testBazel
@@ -45,7 +45,6 @@ let
bazelScript = ''
${bazel}/bin/bazel \
run \
--host_javabase='@local_jdk//:jdk' \
//python:bin
'';
};
@@ -0,0 +1,37 @@
From 177b4720d6fbaa7fdd17e5e11b2c79ac8f246786 Mon Sep 17 00:00:00 2001
From: "Wael M. Nasreddine" <wael.nasreddine@gmail.com>
Date: Thu, 27 Jun 2019 21:08:51 -0700
Subject: [PATCH] Trim last argument to gcc if empty, on Darwin
On Darwin, the last argument to GCC is coming up as an empty string.
This is breaking the build of proto_library targets. However, I was not
able to reproduce with the example cpp project[0].
This commit removes the last argument if it's an empty string. This is
not a problem on Linux.
[0]: https://github.com/bazelbuild/examples/tree/master/cpp-tutorial/stage3
---
tools/cpp/osx_cc_wrapper.sh.tpl | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/cpp/osx_cc_wrapper.sh.tpl b/tools/cpp/osx_cc_wrapper.sh.tpl
index 4c85cd9b6b..6c611e3d25 100644
--- a/tools/cpp/osx_cc_wrapper.sh.tpl
+++ b/tools/cpp/osx_cc_wrapper.sh.tpl
@@ -53,7 +53,11 @@ done
%{env}
# Call the C++ compiler
-%{cc} "$@"
+if [[ ${*: -1} = "" ]]; then
+ %{cc} "${@:0:$#}"
+else
+ %{cc} "$@"
+fi
function get_library_path() {
for libdir in ${LIB_DIRS}; do
--
2.19.2