fix(build): pair Darwin SDKs with the native Apple linker (#7460)
* fix(build): use native Darwin linker (wy-6fric6) Keep pinned LLVM Clang and Linux toolchain inputs; pair Darwin SDKs with the native Apple linker to support macOS 27 TAPI targets. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Steve Yegge * fix(build): canonicalize LLVM attributes (wy-6fric6) Apply bazel mod tidy ordering; linker/compiler settings are unchanged. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Steve Yegge
This commit is contained in:
parent
22c0faaaf9
commit
43b1fb2e4f
3 changed files with 78 additions and 0 deletions
|
|
@ -165,6 +165,13 @@ llvm_host_dist(
|
|||
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
|
||||
llvm.toolchain(
|
||||
name = "llvm_toolchain",
|
||||
# Pair Darwin's host SDK with its native linker. LLVM 22.1.8's ld64.lld
|
||||
# cannot parse the arm64e.x1 TAPI targets in the macOS 27 SDK. Keep the
|
||||
# pinned Clang compiler; Linux keeps the bundled LLD and pinned sysroot.
|
||||
linker = {
|
||||
"darwin-aarch64": "auto",
|
||||
"darwin-x86_64": "auto",
|
||||
},
|
||||
llvm_version = LLVM_VERSION,
|
||||
# The sysroot's libstdc++, linked dynamically as host-gcc builds did.
|
||||
stdlib = {"linux-x86_64": "dynamic-stdc++"},
|
||||
|
|
|
|||
|
|
@ -57,6 +57,30 @@ offline and without Bazel, but they are not what CI enforces. GitHub Actions
|
|||
jobs that still run Go-native suites call the `-go` names, never `make test`
|
||||
(`TestWorkflowsNameTheirTestEngine`).
|
||||
|
||||
### Native macOS C/C++ toolchain
|
||||
|
||||
Bazel uses pinned LLVM 22.1.8 Clang on macOS, with the installed Apple SDK
|
||||
and its native linker (`xcrun --find ld`). `MODULE.bazel` selects
|
||||
`linker = "auto"` only for Darwin arm64 and x86_64. The macOS 27 SDK contains
|
||||
`arm64e.x1` TAPI targets that the bundled LLVM 22.1.8 `ld64.lld` cannot parse;
|
||||
pairing the SDK with Apple's linker avoids that incompatibility without
|
||||
changing the shared SDK, Xcode selection, or installed compiler. Darwin's
|
||||
SDK/linker are host dependencies, so this is not a hermetic macOS build.
|
||||
|
||||
Linux x86_64 still uses the SHA-pinned LLVM compiler and bundled LLD with
|
||||
the pinned Ubuntu 24.04 sysroot. Host C/C++ toolchain detection stays disabled
|
||||
on every platform; the Darwin override does not select `local_config_cc`.
|
||||
`scripts/bazel_hermetic_cc_test.go` guards both contracts. A focused local
|
||||
race build exercises the native cgo link through Go's race standard library:
|
||||
|
||||
```bash
|
||||
bazel test //scripts:scripts_test --config=ci --test_filter='^TestBazelHermetic'
|
||||
```
|
||||
|
||||
This link check is separate from full macOS gate portability: the Linux-only
|
||||
timeout test backends remain tracked in upstream issue #7362. Run the full
|
||||
`make test` gate on its supported Linux platform as well.
|
||||
|
||||
## Choose the Smallest Useful Test
|
||||
|
||||
Test at the lowest seam that can fail for the user-visible reason. Add a
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ func checkHermeticCCModule(module string) []error {
|
|||
}
|
||||
}
|
||||
|
||||
errs = append(errs, checkDarwinLinker(module)...)
|
||||
|
||||
if sysroot, err := moduleCall(module, "llvm.sysroot", hermeticCCSysrootLabel); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else if !strings.Contains(sysroot, `targets = ["linux-x86_64"]`) {
|
||||
|
|
@ -128,6 +130,34 @@ func checkHermeticCCModule(module string) []error {
|
|||
return errs
|
||||
}
|
||||
|
||||
// Darwin already uses the installed SDK, so pair it with Apple's linker.
|
||||
// No default or Linux override is allowed: those must retain bundled LLD.
|
||||
func checkDarwinLinker(module string) []error {
|
||||
toolchain, err := moduleCall(stripStarlarkComments(module), "llvm.toolchain", `name = "llvm_toolchain"`)
|
||||
if err != nil {
|
||||
return []error{err}
|
||||
}
|
||||
linkers := regexp.MustCompile(`(?s)\blinker\s*=\s*\{([^}]*?)\}`).FindAllStringSubmatch(toolchain, -1)
|
||||
if len(linkers) != 1 {
|
||||
return []error{errors.New("llvm.toolchain must select native linkers only for Darwin")}
|
||||
}
|
||||
pairs := regexp.MustCompile(`"([^"]*)"\s*:\s*"([^"]*)"`)
|
||||
entries := pairs.FindAllStringSubmatch(linkers[0][1], -1)
|
||||
remaining := pairs.ReplaceAllString(linkers[0][1], "")
|
||||
seen := map[string]bool{}
|
||||
for _, entry := range entries {
|
||||
key := entry[1]
|
||||
if (key != "darwin-aarch64" && key != "darwin-x86_64") || entry[2] != "auto" || seen[key] {
|
||||
return []error{errors.New("linker overrides must be exactly Darwin aarch64 and x86_64 = auto; Linux must use bundled LLD")}
|
||||
}
|
||||
seen[key] = true
|
||||
}
|
||||
if len(seen) != 2 || strings.Trim(remaining, ", \t\r\n") != "" {
|
||||
return []error{errors.New("linker overrides must be exactly Darwin aarch64 and x86_64 = auto")}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkDebSysroot: every package is an amd64 pool .deb pinned by sha256 that
|
||||
// ships no ICU, and its URL templates give each package more than one host,
|
||||
// keep the snapshot the pins were taken from, and never start with a moving
|
||||
|
|
@ -331,6 +361,14 @@ llvm_host_dist(
|
|||
llvm_versions = {"": LLVM_VERSION},
|
||||
)
|
||||
|
||||
llvm.toolchain(
|
||||
name = "llvm_toolchain",
|
||||
linker = {
|
||||
"darwin-aarch64": "auto",
|
||||
"darwin-x86_64": "auto",
|
||||
},
|
||||
)
|
||||
|
||||
llvm.toolchain_root(
|
||||
name = "llvm_toolchain",
|
||||
label = "` + hermeticCCLLVMLabel + `",
|
||||
|
|
@ -351,6 +389,15 @@ llvm.sysroot(
|
|||
t.Fatalf("good MODULE.bazel fixture: %v", errs)
|
||||
}
|
||||
for name, bad := range map[string]string{
|
||||
"no linker selection": strings.Replace(module, "linker = {", "other = {", 1),
|
||||
"missing Darwin arm64": strings.Replace(module, `"darwin-aarch64": "auto",`, "", 1),
|
||||
"missing Darwin x86": strings.Replace(module, `"darwin-x86_64": "auto",`, "", 1),
|
||||
"bundled Darwin LLD": strings.Replace(module, `"darwin-aarch64": "auto"`, `"darwin-aarch64": ""`, 1),
|
||||
"global native linker": strings.Replace(module, `"darwin-aarch64": "auto"`, `"": "auto"`, 1),
|
||||
"Linux native linker": strings.Replace(module, `"darwin-aarch64": "auto"`, `"linux-x86_64": "auto"`, 1),
|
||||
"extra Linux override": strings.Replace(module, "linker = {", `linker = {"linux-aarch64": "auto",`, 1),
|
||||
"duplicate Darwin key": strings.Replace(module, "linker = {", `linker = {"darwin-aarch64": "auto",`, 1),
|
||||
"commented linker": strings.Replace(module, " linker = {", " # linker = {", 1),
|
||||
"no toolchains_llvm": strings.Replace(module, `bazel_dep(name = "toolchains_llvm", version = "1.11.0")`, "", 1),
|
||||
"no registration": strings.Replace(module, hermeticCCToolchains, "", 1),
|
||||
"second registration": module + `register_toolchains("@local_config_cc//:all")` + "\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue