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 https://github.com/bazelbuild/bazel/blob/d839db66ee86bc906a9789e99d11e0b85aba20be/src/main/native/darwin/sleep_prevention_jni.cc#L39

authored by Claudio and committed by Claudio Bley bb8574dd bccdc675

+78 -1
+56
pkgs/development/tools/build-managers/bazel/bazel_6/darwin_sleep.patch
··· 1 + diff --git a/src/main/native/darwin/sleep_prevention_jni.cc b/src/main/native/darwin/sleep_prevention_jni.cc 2 + index 67c35b201e..e50a58320e 100644 3 + --- a/src/main/native/darwin/sleep_prevention_jni.cc 4 + +++ b/src/main/native/darwin/sleep_prevention_jni.cc 5 + @@ -33,31 +33,13 @@ static int g_sleep_state_stack = 0; 6 + static IOPMAssertionID g_sleep_state_assertion = kIOPMNullAssertionID; 7 + 8 + int portable_push_disable_sleep() { 9 + - std::lock_guard<std::mutex> lock(g_sleep_state_mutex); 10 + - BAZEL_CHECK_GE(g_sleep_state_stack, 0); 11 + - if (g_sleep_state_stack == 0) { 12 + - BAZEL_CHECK_EQ(g_sleep_state_assertion, kIOPMNullAssertionID); 13 + - CFStringRef reasonForActivity = CFSTR("build.bazel"); 14 + - IOReturn success = IOPMAssertionCreateWithName( 15 + - kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, 16 + - &g_sleep_state_assertion); 17 + - BAZEL_CHECK_EQ(success, kIOReturnSuccess); 18 + - } 19 + - g_sleep_state_stack += 1; 20 + - return 0; 21 + + // Unreliable, disable for now 22 + + return -1; 23 + } 24 + 25 + int portable_pop_disable_sleep() { 26 + - std::lock_guard<std::mutex> lock(g_sleep_state_mutex); 27 + - BAZEL_CHECK_GT(g_sleep_state_stack, 0); 28 + - g_sleep_state_stack -= 1; 29 + - if (g_sleep_state_stack == 0) { 30 + - BAZEL_CHECK_NE(g_sleep_state_assertion, kIOPMNullAssertionID); 31 + - IOReturn success = IOPMAssertionRelease(g_sleep_state_assertion); 32 + - BAZEL_CHECK_EQ(success, kIOReturnSuccess); 33 + - g_sleep_state_assertion = kIOPMNullAssertionID; 34 + - } 35 + - return 0; 36 + + // Unreliable, disable for now 37 + + return -1; 38 + } 39 + 40 + } // namespace blaze_jni 41 + diff --git a/src/main/native/darwin/system_suspension_monitor_jni.cc b/src/main/native/darwin/system_suspension_monitor_jni.cc 42 + index 3483aa7935..51782986ec 100644 43 + --- a/src/main/native/darwin/system_suspension_monitor_jni.cc 44 + +++ b/src/main/native/darwin/system_suspension_monitor_jni.cc 45 + @@ -83,10 +83,7 @@ void portable_start_suspend_monitoring() { 46 + // Register to receive system sleep notifications. 47 + // Testing needs to be done manually. Use the logging to verify 48 + // that sleeps are being caught here. 49 + - suspend_state.connect_port = IORegisterForSystemPower( 50 + - &suspend_state, &notifyPortRef, SleepCallBack, &notifierObject); 51 + - BAZEL_CHECK_NE(suspend_state.connect_port, MACH_PORT_NULL); 52 + - IONotificationPortSetDispatchQueue(notifyPortRef, queue); 53 + + // XXX: Unreliable, disable for now 54 + 55 + // Register to deal with SIGCONT. 56 + // We register for SIGCONT because we can't catch SIGSTOP.
+21
pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
··· 205 205 # the prebuilt one does not work in nix world. 206 206 ./java_toolchain.patch 207 207 208 + # Bazel integrates with apple IOKit to inhibit and track system sleep. 209 + # Inside the darwin sandbox, these API calls are blocked, and bazel 210 + # crashes. It seems possible to allow these APIs inside the sandbox, but it 211 + # feels simpler to patch bazel not to use it at all. So our bazel is 212 + # incapable of preventing system sleep, which is a small price to pay to 213 + # guarantee that it will always run in any nix context. 214 + # 215 + # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses 216 + # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the 217 + # sandbox. 218 + # 219 + # If you want to investigate the sandbox profile path, 220 + # IORegisterForSystemPower can be allowed with 221 + # 222 + # propagatedSandboxProfile = '' 223 + # (allow iokit-open (iokit-user-client-class "RootDomainUserClient")) 224 + # ''; 225 + # 226 + # I do not know yet how to allow IOPMAssertion{CreateWithName,Release} 227 + ./darwin_sleep.patch 228 + 208 229 # On Darwin, the last argument to gcc is coming up as an empty string. i.e: '' 209 230 # This is breaking the build of any C target. This patch removes the last 210 231 # argument if it's found to be an empty string.
+1 -1
pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
··· 213 213 # 214 214 # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses 215 215 # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the 216 - # sandbox. Oddly, bazel_6 does not need that patch :-/. 216 + # sandbox. 217 217 # 218 218 # If you want to investigate the sandbox profile path, 219 219 # IORegisterForSystemPower can be allowed with