From 4922ed06b0211ff6bd8844c0decb79914473526c Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Sat, 27 Nov 2021 22:14:09 -0500 Subject: [PATCH 1/3] bazel: patch to fix for darwin sandbox --- .../tools/build-managers/bazel/bazel_3/default.nix | 4 ++++ .../tools/build-managers/bazel/bazel_4/default.nix | 4 ++++ .../tools/build-managers/bazel/bazel_5/default.nix | 4 ++++ .../build-managers/bazel/bazel_darwin_sandbox.patch | 11 +++++++++++ 4 files changed, 23 insertions(+) create mode 100644 pkgs/development/tools/build-managers/bazel/bazel_darwin_sandbox.patch diff --git a/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix index 6544db85a7f3..9703590bd4a7 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix @@ -211,6 +211,10 @@ stdenv.mkDerivation rec { src = ../bazel_rc.patch; bazelSystemBazelRCPath = bazelRC; }) + + # disable suspend detection during a build inside Nix as this is + # not available inside the darwin sandbox + ../bazel_darwin_sandbox.patch ] ++ lib.optional enableNixHacks ../nix-hacks.patch; diff --git a/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix index 511234a1e595..99897364e6af 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix @@ -246,6 +246,10 @@ stdenv.mkDerivation rec { src = ../bazel_rc.patch; bazelSystemBazelRCPath = bazelRC; }) + + # disable suspend detection during a build inside Nix as this is + # not available inside the darwin sandbox + ../bazel_darwin_sandbox.patch ] ++ lib.optional enableNixHacks ../nix-hacks.patch; diff --git a/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix index 0c06d6128317..45ac1b14b17d 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix @@ -208,6 +208,10 @@ stdenv.mkDerivation rec { src = ../bazel_rc.patch; bazelSystemBazelRCPath = bazelRC; }) + + # disable suspend detection during a build inside Nix as this is + # not available inside the darwin sandbox + ../bazel_darwin_sandbox.patch ] ++ lib.optional enableNixHacks ../nix-hacks.patch; diff --git a/pkgs/development/tools/build-managers/bazel/bazel_darwin_sandbox.patch b/pkgs/development/tools/build-managers/bazel/bazel_darwin_sandbox.patch new file mode 100644 index 000000000000..87e6c99287fb --- /dev/null +++ b/pkgs/development/tools/build-managers/bazel/bazel_darwin_sandbox.patch @@ -0,0 +1,11 @@ +diff -ru a/src/main/native/unix_jni_darwin.cc b/src/main/native/unix_jni_darwin.cc +--- a/src/main/native/unix_jni_darwin.cc 1980-01-01 00:00:00.000000000 -0500 ++++ b/src/main/native/unix_jni_darwin.cc 2021-11-27 20:35:29.000000000 -0500 +@@ -270,6 +270,7 @@ + } + + int portable_suspend_count() { ++ if (getenv("NIX_BUILD_TOP")) return 0; + static dispatch_once_t once_token; + static SuspendState suspend_state; + dispatch_once(&once_token, ^{ From fe67982028f7841fb7d3a436dacb3ae24ceca7ca Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Sat, 27 Nov 2021 22:15:04 -0500 Subject: [PATCH 2/3] buildBazelPackage: run in batch mode to avoid requiring loopback networking --- pkgs/build-support/build-bazel-package/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/build-support/build-bazel-package/default.nix b/pkgs/build-support/build-bazel-package/default.nix index f379334786b6..d69fddaf03fa 100644 --- a/pkgs/build-support/build-bazel-package/default.nix +++ b/pkgs/build-support/build-bazel-package/default.nix @@ -90,6 +90,7 @@ in stdenv.mkDerivation (fBuildAttrs // { BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \ USER=homeless-shelter \ bazel \ + --batch \ --output_base="$bazelOut" \ --output_user_root="$bazelUserRoot" \ ${if fetchConfigured then "build --nobuild" else "fetch"} \ @@ -211,6 +212,7 @@ in stdenv.mkDerivation (fBuildAttrs // { BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \ USER=homeless-shelter \ bazel \ + --batch \ --output_base="$bazelOut" \ --output_user_root="$bazelUserRoot" \ build \ From 7ce637bc9989e5c4180bd6431f1acfa38b8c86bf Mon Sep 17 00:00:00 2001 From: Uri Baghin Date: Tue, 20 Sep 2022 14:01:39 +1000 Subject: [PATCH 3/3] bazel_5: fix sandbox --- .../bazel/bazel_5/bazel_darwin_sandbox.patch | 11 +++++++++++ .../tools/build-managers/bazel/bazel_5/default.nix | 6 +++--- pkgs/top-level/all-packages.nix | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/tools/build-managers/bazel/bazel_5/bazel_darwin_sandbox.patch diff --git a/pkgs/development/tools/build-managers/bazel/bazel_5/bazel_darwin_sandbox.patch b/pkgs/development/tools/build-managers/bazel/bazel_5/bazel_darwin_sandbox.patch new file mode 100644 index 000000000000..725b901f893e --- /dev/null +++ b/pkgs/development/tools/build-managers/bazel/bazel_5/bazel_darwin_sandbox.patch @@ -0,0 +1,11 @@ +diff -ru a/src/main/native/unix_jni_darwin.cc b/src/main/native/unix_jni_darwin.cc +--- a/src/main/native/unix_jni_darwin.cc 1980-01-01 00:00:00.000000000 -0500 ++++ b/src/main/native/unix_jni_darwin.cc 2021-11-27 20:35:29.000000000 -0500 +@@ -270,6 +270,7 @@ + } + + void portable_start_suspend_monitoring() { ++ if (getenv("NIX_BUILD_TOP")) return; + static dispatch_once_t once_token; + static SuspendState suspend_state; + dispatch_once(&once_token, ^{ diff --git a/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix index 45ac1b14b17d..491a02d74d0d 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix @@ -9,7 +9,7 @@ # updater , python27, python3, writeScript # Apple dependencies -, cctools, libcxx, CoreFoundation, CoreServices, Foundation +, cctools, libcxx, sigtool, CoreFoundation, CoreServices, Foundation # Allow to independently override the jdks used to build and run respectively , buildJdk, runJdk , runtimeShell @@ -211,7 +211,7 @@ stdenv.mkDerivation rec { # disable suspend detection during a build inside Nix as this is # not available inside the darwin sandbox - ../bazel_darwin_sandbox.patch + ./bazel_darwin_sandbox.patch ] ++ lib.optional enableNixHacks ../nix-hacks.patch; @@ -382,7 +382,7 @@ stdenv.mkDerivation rec { # clang installed from Xcode has a compatibility wrapper that forwards # invocations of gcc to clang, but vanilla clang doesn't sed -i -e 's;_find_generic(repository_ctx, "gcc", "CC", overriden_tools);_find_generic(repository_ctx, "clang", "CC", overriden_tools);g' tools/cpp/unix_cc_configure.bzl - + sed -i -e 's;env -i codesign --identifier $@ --force --sign;env -i CODESIGN_ALLOCATE=${cctools}/bin/${cctools.targetPrefix}codesign_allocate ${sigtool}/bin/codesign --identifier $@ --force -s;g' tools/osx/BUILD sed -i -e 's;"/usr/bin/libtool";_find_generic(repository_ctx, "libtool", "LIBTOOL", overriden_tools);g' tools/cpp/unix_cc_configure.bzl wrappers=( tools/cpp/osx_cc_wrapper.sh tools/cpp/osx_cc_wrapper.sh.tpl ) for wrapper in "''${wrappers[@]}"; do diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8feb5a821170..83e2f0b32bca 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15746,7 +15746,7 @@ with pkgs; }; bazel_5 = callPackage ../development/tools/build-managers/bazel/bazel_5 { - inherit (darwin) cctools; + inherit (darwin) cctools sigtool; inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Foundation; buildJdk = jdk11_headless; runJdk = jdk11_headless;