turborepo
88efe65a - fix: Make rust-lld work with managed Rust on macOS (#15080)

Commit
1 day ago
fix: Make rust-lld work with managed Rust on macOS (#15080) ### Description On macOS, a managed Rust task that links with `rust-lld` failed: ```text error: linking with `rust-lld` failed: signal: 6 (SIGABRT) dyld: Library not loaded: @rpath/libLLVM.dylib ``` The launchers that `turbo setup` writes for Rust on macOS now put the toolchain's `lib` directory in `DYLD_FALLBACK_LIBRARY_PATH`. ```diff #!/bin/sh case "$0" in */*) ;; *) exit 126;; esac store=$(CDPATH= cd -P -- "${0%/*}/../../.." && pwd) || exit 126 RUSTUP_HOME="$store"'/trees/<key>/root' RUSTUP_TOOLCHAIN='<toolchain>' export RUSTUP_HOME RUSTUP_TOOLCHAIN +case "$store" in *:*) ;; *) +case "${HOME:-}" in ''|*:*) fallback=/usr/local/lib:/usr/lib;; *) fallback="$HOME/lib:/usr/local/lib:/usr/lib";; esac +DYLD_FALLBACK_LIBRARY_PATH="$store"'/trees/<key>/root/toolchains/<toolchain>/lib'":${DYLD_FALLBACK_LIBRARY_PATH:-$fallback}" +export DYLD_FALLBACK_LIBRARY_PATH;; esac exec "$store"'/trees/<key>/root/toolchains/<toolchain>/bin/cargo' "$@" ``` The macOS `rust-lld` loads `libLLVM.dylib` through the rpath `@loader_path/../lib`, a directory that the toolchain does not have. The library is in the toolchain's `lib`. With rustup, the proxy puts that directory in `DYLD_FALLBACK_LIBRARY_PATH`. The launchers run the toolchain's programs without the proxy, so nothing set it. This repository sets `linker = "rust-lld"` for macOS in `.cargo/config.toml`, so the Rust tests failed in [this job on #15076](https://github.com/vercel/turborepo/actions/runs/44409661993/job/135174588293). dyld searches its default directories only while the variable is unset. The launcher names them after the toolchain's directory, as the rustup proxy does. The value is a list separated by colons. If the tool store's path has a colon, the launcher does not set the variable, and if `HOME` has one, the launcher leaves `$HOME/lib` out. Either would otherwise name a directory that is not the store or the home. #### Why the launcher, and why only macOS - The value cannot be a managed variable. Activation gives managed variables to every task and to the shell hook. macOS also removes `DYLD_*` variables whenever a system program such as `/bin/sh` starts, so the variable would not reach the toolchain. - Linux does not need it. The `rust-lld` in the pinned `nightly-2026-07-03` for `x86_64-unknown-linux-gnu` has `$ORIGIN/../../../` in its rpath, which is the toolchain's `lib`. - Windows runs Rust through the rustup proxies. #### After you upgrade - On macOS, in a repository with managed Rust, run `turbo setup` once. The launchers changed, so the environment has a new key, and `turbo run` reports `managed tools have no matching trusted setup record; run turbo setup` until then. Setup reuses the installed tools and downloads nothing. - Every other environment keeps its key. A launcher without the new field serializes as before. ### Testing Instructions On macOS arm64, I built `turbo` from this PR's parent commit and from this PR. I ran both in a checkout of #15076, each with an empty tool store. | Step | Parent commit | This PR | | --- | --- | --- | | `turbo exec -- cargo build -p turbopath` | exit 101, `Library not loaded: @rpath/libLLVM.dylib` | exit 0 | | `turbo run build --filter=turbopath` | exit 101, `wax#build` failed with the same error | exit 0, 3 tasks | For the upgrade, I ran this PR's `turbo` against the store that the parent commit's `turbo` had set up: 1. `turbo exec` failed with the `turbo setup` message above. 2. `turbo setup --tools-only --frozen` reused the four tools and added one environment. 3. `turbo exec -- cargo build -p turbopath` exited 0.
Author
Parents
Loading