bazelbuild / bazelbuild/rules_cc

BAZEL_USE_CPP_ONLY_TOOLCHAIN doesn't work without Xcode / Xcode CLT installed.

Closed
#134 0 comments 0 reactions 0 assignees View on GitHub
P3
Dominant language
Starlark
Stars
247
Forks
196
PR merge metrics
No merged PRs in 30d

Description

### Description of the bug:

Equivalent to Bazel issue: https://github.com/bazelbuild/bazel/issues/16009

`BAZEL_USE_CPP_ONLY_TOOLCHAIN` on Darwin is meant to disable the Xcode toolchain resolution and use the common Unix toolchain resolution based on what binaries are available on the `PATH` and set with environment variables. However it will still hardcode several apple tools, like `/usr/bin/libtool`, `/usr/bin/gcc` and `/usr/bin/install_name_tool` (in `cc_wrapper.sh`).

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

```
# Either have an install of macOS without Xcode or Xcode CLT installed, or:
ln -s $(xcode-select -p) invalid
sudo xcode-select -s invalid
rm invalid

# try building a cc target with BAZEL_USE_CPP_ONLY_TOOLCHAIN having `libtool`, `install_name_tool` and `gcc` on your `PATH`:
BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 bazel build //tools/cpp/runfiles
```

Expected output: successful build using the binaries on your `PATH`.
Actual output:

```
ERROR: /Users/uri/github/bazelbuild/bazel/tools/cpp/runfiles/BUILD:51:11: Compiling tools/cpp/runfiles/runfiles_src.cc failed: (Exit 1): cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics ... (remaining 20 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
xcrun: error: active developer path ("/Users/uri/github/bazelbuild/bazel/invalid") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.
Target //tools/cpp/runfiles:runfiles failed to build
```

### Which operating system are you running Bazel on?

macOS 12.5 21G72

### What is the output of `bazel info release`?

release 5.2.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

```text
git@github.com:bazelbuild/bazel.git
c282526c071389cd6f88cb77565283b257316267
2e8458b7810eab7829fc7d28af5c45b9af91ed7c
```

### What version of rules_cc do you use? Can you paste the workspace rule used to fetch rules_cc? What other relevant dependencies does your project have?

From: https://sourcegraph.com/github.com/tensorflow/runtime@021b5f0d3daea2d1666599d7d9c471a426c35f65/-/blob/third_party/rules_cuda/cuda/dependencies.bzl?L35-44

```
http_archive(
name = "rules_cc",
sha256 = "ff7876d80cd3f6b8c7a064bd9aa42a78e02096544cca2b22a9cf390a4397a53e",
strip_prefix = "rules_cc-081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e",
patches = [Label("//private:rules_cc.patch")],
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz",
"https://github.com/bazelbuild/rules_cc/archive/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz",
],
```

### What Bazel options do you use to trigger the issue? What C++ toolchain do you use?

See repro.

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in tools/cpp/runfiles/BUILD and inspect the generated external/local_config_cc/cc_wrapper.sh path. Run the shown BAZEL_USE_CPP_ONLY_TOOLCHAIN build on macOS without an active Xcode or Xcode CLT installation, then verify that the build succeeds using libtool, install_name_tool, and gcc from PATH.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.