bazelbuild / bazelbuild/bazel

$DEVELOPER_DIR stopped getting set on macOS when using C++ toolchain environment

Open
#20,638 8 comments 0 reactions 0 assignees View on GitHub
team-Rules-ObjC type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

When looking up action environments from a C++ toolchain, in Bazel 6.4.0 this would lead to `$XCODE_VERSION_OVERRIDE`, `$APPLE_SDK_VERSION_OVERRIDE` and `$APPLE_SDK_PLATFORM` getting set.

This would then lead to the `XcodeLocalEnvProvider` setting `$DEVELOPER_DIR` and `$SDKROOT` when running in a `DarwinSandboxedSpawnRunner`.

https://github.com/bazelbuild/bazel/commit/699e40373f95e42390a85f29dfa1098636336103 moved the C++ toolchain for Apple platforms out of Bazel, and has brought a regression because these variables are now not set automatically.

This is a significant break in the rules API - if there's some workaround that should be applied (e.g. a new attribute that needs setting), it would be good to document that.

As far as I can tell from searching around, any replacement ways of making this work involve manually setting env vars, and possibly registering new repository rules to do so, which feels like a significant regression. Hopefully there's some easy workaround or fix I just haven't found yet!

### Which category does this issue belong to?

C++/Objective-C Rules

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

Clone https://github.com/illicitonion/repro-bazel-cc-toolchain-xcode-vars on a macOS machine.

Run:
```console
% USE_BAZEL_VERSION=6.4.0 bazel build //:dd
```

To see it work.

Run:
```console
% USE_BAZEL_VERSION=7.0.0 bazel build //:dd
```

to see it fail.

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

macOS

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

release 7.0.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` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

https://github.com/bazelbuild/bazel/commit/699e40373f95e42390a85f29dfa1098636336103

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

_No response_

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

Note that this is the root cause of https://github.com/bazelbuild/rules_rust/issues/2207

Contributor guide

Open the contributing guide

Research direction

Start with the linked minimal reproduction and compare the Bazel 6.4.0 and 7.0.0 builds on macOS. Trace the environment lookup through XcodeLocalEnvProvider and DarwinSandboxedSpawnRunner, then inspect commit 699e40373f95e42390a85f29dfa1098636336103. Done means the reproduction again provides the expected Apple environment variables and sets DEVELOPER_DIR and SDKROOT without manual workarounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, macos
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.