bazelbuild / bazelbuild/bazel

Swift toolchain doesn't respect DEVELOPER_DIR

Open
#27,238 0 comments 0 reactions 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

Ability to build swift code by xcode from user defined DEVELOPER_DIR was significant feature of [bazel 8.3.0](https://github.com/bazelbuild/bazel/releases/tag/8.3.0)

However, if doesn't work fully.

swiftc compiler doesn't run directly in build action. It is launched through [xcode_locator](https://github.com/bazelbuild/bazel/blob/master/tools/osx/xcode_locator.m), which set DEVELOPER_DIR before swiftc call.

Problems are:
- xcode_locator doesn't respect DEVELOPER_DIR (defined by me).
- xcode_locator selects installed xcodes only.

First problem looks even worse, because [xcode_swift_toolchain](https://github.com/bazelbuild/rules_swift/blob/master/swift/toolchains/xcode_swift_toolchain.bzl) determines "my" xcode and plans to use it (xcode_swift_toolchain analyzes DEVELOPER_DIR), but it doesn't guarantee "my" xcode usage (because of xcode_locator as intermediate lawyer).

As feature user I want to say, that if I set DEVELOPER_DIR, I know better what xcode should be chosen and accept all risks.
This is very important when you try to build swift code on newest MacOS by old xcode. You can't install it due to OS policies, but you would like (and actually can) to use it still by extracting .xip archive.

I propose fix of this problem [here](https://github.com/bazelbuild/bazel/commit/02c21f19849fef2d822a7c981b58c70ed48e6c40)

### Which category does this issue belong to?

Core

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

- Download old xcode .xip archive (non compatible with current MacOS)
- Extract archive to specific place
- Create target
```
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")

swift_binary(
name = "swift_binary",
srcs = ["main.swift"],
copts = ["-v"],
)
```

- Build this target with --repo_env=DEVELOPER_DIR=your_path

xcode_swift_toolchain identifies "your" xcode, but
swift compilation will fail (if you don't have any installed xcode)
OR
swiftc log shows `usr/bin/swift-frontend` call not from predefined DEVELOPER_DIR

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

Macos

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

8.3.1

### 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 HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

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

_No response_

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

please permit [my fix](https://github.com/bazelbuild/bazel/commit/02c21f19849fef2d822a7c981b58c70ed48e6c40)

Contributor guide

Open the contributing guide

Research direction

Start with tools/osx/xcode_locator.m and compare its selection logic with rules_swift/swift/toolchains/xcode_swift_toolchain.bzl, which already analyzes DEVELOPER_DIR. Reproduce the issue using an extracted older Xcode and --repo_env=DEVELOPER_DIR=your_path. Done means swiftc uses the specified Xcode, including when no compatible installed Xcode is present.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, swift
Domain
build-system
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.