From da169dc09733d36a917e8bf96b79618a708a926a Mon Sep 17 00:00:00 2001 From: Noah S-C Date: Wed, 24 Jan 2024 10:35:53 -0800 Subject: [PATCH] nix: use clang11Stdenv for shell and host clang for bazel on macos (#59825) Host clang for bazel reason: ``` ERROR: /Users/noah/Sourcegraph/sourcegraph/BUILD.bazel:305:5: GoLink sg_nogo_actual_/sg_nogo_actual [for tool] failed: (Exit 1): builder failed: error executing GoLink command (from target //:sg_nogo_actual) bazel-out/darwin_arm64-opt-exec-ST-1a88b5d644a4/bin/external/go_sdk/builder_reset/builder '-param=bazel-out/darwin_arm64-opt-exec-ST-1a88b5d644a4/bin/sg_nogo_actual_/sg_nogo_actual-0.params' -- -extld ... (remaining 6 arguments skipped) Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging external/go_sdk/pkg/tool/darwin_arm64/link: running external/local_config_cc/cc_wrapper.sh failed: exit status 1 ld: framework not found CoreFoundation clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` clang 11 for shell reason: https://github.com/NixOS/nixpkgs/issues/166205 ## Test plan `./dev/scip-ctags-install.sh` and `bazel build //:gazelle` --- shell.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/shell.nix b/shell.nix index 40605a2027a6b..7374db671102c 100644 --- a/shell.nix +++ b/shell.nix @@ -23,7 +23,7 @@ let # Additionally bazel seems to break when CC and CXX is set to a nix managed # compiler on darwin. So the script unsets those. bazel-wrapper = writeShellScriptBin "bazel" (if hostPlatform.isMacOS then '' - unset CC CXX + export CC=/usr/bin/clang exec ${pkgs.bazelisk}/bin/bazelisk "$@" '' else '' unset TMPDIR TMP @@ -33,7 +33,7 @@ let exec ${pkgs.bazel_7}/bin/bazel "$@" ''); bazel-watcher = writeShellScriptBin "ibazel" '' - ${lib.optionalString hostPlatform.isMacOS "unset CC CXX"} + ${lib.optionalString hostPlatform.isMacOS "export CC=/usr/bin/clang"} exec ${pkgs.bazel-watcher}/bin/ibazel \ ${lib.optionalString hostPlatform.isLinux "-bazel_path=${bazel-fhs}/bin/bazel"} "$@" ''; @@ -65,7 +65,7 @@ let # the binary for GNU sed. gsed = pkgs.writeShellScriptBin "gsed" ''exec ${pkgs.gnused}/bin/sed "$@"''; in -mkShell { +mkShell.override { stdenv = if hostPlatform.isMacOS then pkgs.clang11Stdenv else pkgs.stdenv; } { name = "sourcegraph-dev"; # The packages in the `buildInputs` list will be added to the PATH in our shell @@ -118,7 +118,7 @@ mkShell { bazel-fhs bazel-watcher bazel-buildtools - ]); + ]) ++ lib.optional hostPlatform.isMacOS [ bazel-wrapper ]; # Startup postgres, redis & set nixos specific stuff shellHook = '' @@ -143,6 +143,7 @@ mkShell { # bazel complains when the bazel version differs even by a patch version to whats defined in .bazelversion, # so we tell it to h*ck off here. # https://sourcegraph.com/github.com/bazelbuild/bazel@1a4da7f331c753c92e2c91efcad434dc29d10d43/-/blob/scripts/packages/bazel.sh?L23-28 - USE_BAZEL_VERSION = - if hostPlatform.isMacOS then "" else pkgs.bazel_7.version; + USE_BAZEL_VERSION = if hostPlatform.isMacOS then "" else pkgs.bazel_7.version; + + LIBTOOL = if hostPlatform.isMacOS then "${pkgs.libtool}" else ""; }