bazel_6: Add patch for system sleep on Darwin

This re-uses the same patch as bazel_7 which indeed is also necessary here, since
otherwise building bazel_6 failed with

```
FATAL: CHECK failed: (success) == (0):
```

at d839db66ee/src/main/native/darwin/sleep_prevention_jni.cc (L39)
This commit is contained in:
Claudio 2024-02-19 13:56:27 +01:00 committed by Claudio Bley
parent bccdc6751f
commit bb8574ddb8
3 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,56 @@
diff --git a/src/main/native/darwin/sleep_prevention_jni.cc b/src/main/native/darwin/sleep_prevention_jni.cc
index 67c35b201e..e50a58320e 100644
--- a/src/main/native/darwin/sleep_prevention_jni.cc
+++ b/src/main/native/darwin/sleep_prevention_jni.cc
@@ -33,31 +33,13 @@ static int g_sleep_state_stack = 0;
static IOPMAssertionID g_sleep_state_assertion = kIOPMNullAssertionID;
int portable_push_disable_sleep() {
- std::lock_guard<std::mutex> lock(g_sleep_state_mutex);
- BAZEL_CHECK_GE(g_sleep_state_stack, 0);
- if (g_sleep_state_stack == 0) {
- BAZEL_CHECK_EQ(g_sleep_state_assertion, kIOPMNullAssertionID);
- CFStringRef reasonForActivity = CFSTR("build.bazel");
- IOReturn success = IOPMAssertionCreateWithName(
- kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity,
- &g_sleep_state_assertion);
- BAZEL_CHECK_EQ(success, kIOReturnSuccess);
- }
- g_sleep_state_stack += 1;
- return 0;
+ // Unreliable, disable for now
+ return -1;
}
int portable_pop_disable_sleep() {
- std::lock_guard<std::mutex> lock(g_sleep_state_mutex);
- BAZEL_CHECK_GT(g_sleep_state_stack, 0);
- g_sleep_state_stack -= 1;
- if (g_sleep_state_stack == 0) {
- BAZEL_CHECK_NE(g_sleep_state_assertion, kIOPMNullAssertionID);
- IOReturn success = IOPMAssertionRelease(g_sleep_state_assertion);
- BAZEL_CHECK_EQ(success, kIOReturnSuccess);
- g_sleep_state_assertion = kIOPMNullAssertionID;
- }
- return 0;
+ // Unreliable, disable for now
+ return -1;
}
} // namespace blaze_jni
diff --git a/src/main/native/darwin/system_suspension_monitor_jni.cc b/src/main/native/darwin/system_suspension_monitor_jni.cc
index 3483aa7935..51782986ec 100644
--- a/src/main/native/darwin/system_suspension_monitor_jni.cc
+++ b/src/main/native/darwin/system_suspension_monitor_jni.cc
@@ -83,10 +83,7 @@ void portable_start_suspend_monitoring() {
// Register to receive system sleep notifications.
// Testing needs to be done manually. Use the logging to verify
// that sleeps are being caught here.
- suspend_state.connect_port = IORegisterForSystemPower(
- &suspend_state, &notifyPortRef, SleepCallBack, &notifierObject);
- BAZEL_CHECK_NE(suspend_state.connect_port, MACH_PORT_NULL);
- IONotificationPortSetDispatchQueue(notifyPortRef, queue);
+ // XXX: Unreliable, disable for now
// Register to deal with SIGCONT.
// We register for SIGCONT because we can't catch SIGSTOP.

View File

@ -205,6 +205,27 @@ stdenv.mkDerivation rec {
# the prebuilt one does not work in nix world.
./java_toolchain.patch
# Bazel integrates with apple IOKit to inhibit and track system sleep.
# Inside the darwin sandbox, these API calls are blocked, and bazel
# crashes. It seems possible to allow these APIs inside the sandbox, but it
# feels simpler to patch bazel not to use it at all. So our bazel is
# incapable of preventing system sleep, which is a small price to pay to
# guarantee that it will always run in any nix context.
#
# See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
# NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
# sandbox.
#
# If you want to investigate the sandbox profile path,
# IORegisterForSystemPower can be allowed with
#
# propagatedSandboxProfile = ''
# (allow iokit-open (iokit-user-client-class "RootDomainUserClient"))
# '';
#
# I do not know yet how to allow IOPMAssertion{CreateWithName,Release}
./darwin_sleep.patch
# 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.

View File

@ -213,7 +213,7 @@ stdenv.mkDerivation rec {
#
# See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
# NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
# sandbox. Oddly, bazel_6 does not need that patch :-/.
# sandbox.
#
# If you want to investigate the sandbox profile path,
# IORegisterForSystemPower can be allowed with