Raise the maximum number of processes and open files to their maximum.

Under macOS, the default soft resource limits for open files and concurrent
processes are pretty low, but their corresponding hard defaults are
reasonable.  Because the soft limits are low, Bazel sometimes fails during
large builds -- not because of Bazel itself, but because the executed
actions do "too much work" or because the --jobs setting was high enough
to cause all parallel tasks to exceed the limits.

Instead of trying to fix the actions themselves, start by trying to raise
the system limits as a best-effort operation.  And, given that this code
is fairly portable, try to do it on all POSIX systems and not just macOS.
Note that, for non-macOS systems, this might still not do what's promised
in all circumstances because I'm currently only implementing
GetExplicitSystemLimit on macOS.

RELNOTES: None.
PiperOrigin-RevId: 161401482
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 310ce21..f9acc8a 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1334,6 +1334,12 @@
   globals = new GlobalVariables(option_processor);
   blaze::SetupStdStreams();
 
+  // Best-effort operation to raise the resource limits from soft to hard.  We
+  // do this early during the main program instead of just before execing the
+  // Blaze server binary, because it's easier (for testing purposes) and because
+  // the Blaze client also benefits from this (e.g. during installation).
+  UnlimitResources();
+
   // Must be done before command line parsing.
   ComputeWorkspace(workspace_layout);
   globals->binary_path = CheckAndGetBinaryPath(argv[0]);