Add libraries to allowed macOS include directories

This adds macOS `/Library` and `/Users/$USER/Library` to allowed include
paths. In macOS workflows most system headers are included in the Xcode
toolchains, which were already covered in this logic. The only exception
is custom `xctoolchains`, which can be used for custom Swift compilers
(among other things). These toolchains are either installed globally in
`/Library`, or without root they can be installed in the user's
`~/Library`. This adds those paths since they can safely be referenced
by passing `--action_env=TOOLCHAINS=toolchain_id` which will be picked
up by invocations of `xcrun`.

Closes #12328.

PiperOrigin-RevId: 340817483
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index 7d010d3..406425c 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -172,6 +172,7 @@
         "GCOV",
         "HOMEBREW_RUBY_PATH",
         "SYSTEMROOT",
+        "USER",
     ] + MSVC_ENVVARS,
     implementation = cc_autoconf_impl,
     configure = True,
diff --git a/tools/cpp/osx_cc_configure.bzl b/tools/cpp/osx_cc_configure.bzl
index bcca732..d2a82e2 100644
--- a/tools/cpp/osx_cc_configure.bzl
+++ b/tools/cpp/osx_cc_configure.bzl
@@ -37,12 +37,20 @@
       include_paths: A list of builtin include paths.
     """
 
-    include_dirs = []
+    # Assume that everything is managed by Xcode / toolchain installations
+    include_dirs = [
+        "/Applications/",
+        "/Library/",
+    ]
+
+    user = repository_ctx.os.environ.get("USER")
+    if user:
+        include_dirs.append("/Users/{}/Library/".format(user))
+
+    # Include extra Xcode paths in case they're installed on other volumes
     for toolchain in xcode_toolchains:
         include_dirs.append(escape_string(toolchain.developer_dir))
 
-    # Assume that all paths that point to /Applications/ are built in include paths
-    include_dirs.append("/Applications/")
     return include_dirs
 
 def _compile_cc_file(repository_ctx, src_name, out_name):