Auto merge of #157205 - sgasho:link_llvm_dynamically_on_mac, r=ZuseZ4

Link LLVM dynamically on aarch64-apple-darwin

--set llvm.link-shared=true on dist-aarch64-apple to link LLVM dynamically on MacOS. 
Also, I fixed some link problems, by normalizing the libLLVM.dylib name, and creating a symlink(On Linux, we use linker script, but we can not use it for MacOS. ld64 does not recognize linker scripts) from versioned dylib to unversioned libLLVM.dylib to build successfully.

## How I verified on my Mac

1. remove the old build dir

```shell
rm -rf build/
```

2. configure for rust-dev dist

```shell
./configure \
    --set llvm.download-ci-llvm=false \
    --set llvm.link-shared=true \
    --release-channel=nightly
```

3. dist

```shell
./x dist rust-dev --host=aarch64-apple-darwin --target=aarch64-apple-darwin
```

4. move tarball to /tmp(or, wherever else except for inside build/) and delete the current build dir

We create build/ for both rust-dev dist, and local build tests. Once dist finished, we have to clear the directory so we can use it for build tests

```shell
cp build/dist/rust-dev-nightly-aarch64-apple-darwin.tar.xz /tmp/

rm -rf build
```

I saw a symlink created as expected

<img width="652" height="406" alt="rust-dev artifacts" src="https://github.com/user-attachments/assets/dc49a637-8a1f-45c8-84f2-2ef101faae51" />


6. modify download.rs temporary so it gets the locally built tarball at step3

```rust
    #[cfg(not(test))]
    fn download_ci_llvm(&self, _llvm_sha: &str) {
        let tarball = PathBuf::from("/tmp/rust-dev-nightly-aarch64-apple-darwin.tar.xz");
        let llvm_root = self.ci_llvm_root();
        self.unpack(&tarball, &llvm_root, "rust-dev");
    //     let llvm_assertions = self.llvm_assertions;

    //     let cache_prefix = format!("llvm-{llvm_sha}-{llvm_assertions}");
    //     let cache_dst =
    //         self.bootstrap_cache_path.as_ref().cloned().unwrap_or_else(|| self.out.join("cache"));

    //     let rustc_cache = cache_dst.join(cache_prefix);
    //     if !rustc_cache.exists() {
    //         t!(fs::create_dir_all(&rustc_cache));
    //     }
    //     let base = if llvm_assertions {
    //         &self.stage0_metadata.config.artifacts_with_llvm_assertions_server
    //     } else {
    //         &self.stage0_metadata.config.artifacts_server
    //     };
    //     let version = self.artifact_version_part(llvm_sha);
    //     let filename = format!("rust-dev-{}-{}.tar.xz", version, self.host_target.triple);
    //     let tarball = rustc_cache.join(&filename);
    //     if !tarball.exists() {
    //         let help_on_error = "ERROR: failed to download llvm from ci

    // HELP: There could be two reasons behind this:
    //     1) The host triple is not supported for `download-ci-llvm`.
    //     2) Old builds get deleted after a certain time.
    // HELP: In either case, disable `download-ci-llvm` in your bootstrap.toml:

    // [llvm]
    // download-ci-llvm = false
    // ";
    //         self.download_file(&format!("{base}/{llvm_sha}/{filename}"), &tarball, help_on_error);
    //     }
    //     let llvm_root = self.ci_llvm_root();
    //     self.unpack(&tarball, &llvm_root, "rust-dev");
    }
```

7. configure for ./x build

```shell
rm -rf bootstrap.toml // delete existing config of rust-dev dist

// maybe we don't need to specify llvm.download-ci-llvm=true, since I bumped download-ci-llvm-stamp.
// but anyway, I explicitly specified it when I tested it

./configure \
    --set llvm.download-ci-llvm=true \
    --set llvm.link-shared=true \
    --release-channel=nightly
```

8. ./x build

```shell
./x build (library)
```

Result: build completed successfully

<img width="861" height="763" alt="スクリーンショット 2026-06-01 0 38 21" src="https://github.com/user-attachments/assets/9660ac43-c275-4174-b80a-3483b4acfd40" />

r? @Kobzol 

cc: @ZuseZ4 
tree: 54784206000cbb37a0a12f10978b2caeb72a806e
  1. .github/
  2. compiler/
  3. library/
  4. LICENSES/
  5. src/
  6. tests/
  7. .clang-format
  8. .editorconfig
  9. .git-blame-ignore-revs
  10. .gitattributes
  11. .gitignore
  12. .gitmodules
  13. .ignore
  14. .mailmap
  15. bootstrap.example.toml
  16. Cargo.lock
  17. Cargo.toml
  18. CODE_OF_CONDUCT.md
  19. configure
  20. CONTRIBUTING.md
  21. COPYRIGHT
  22. INSTALL.md
  23. LICENSE-APACHE
  24. license-metadata.json
  25. LICENSE-MIT
  26. package.json
  27. README.md
  28. RELEASES.md
  29. REUSE.toml
  30. rust-bors.toml
  31. rustfmt.toml
  32. triagebot.toml
  33. typos.toml
  34. x
  35. x.ps1
  36. x.py
  37. yarn.lock
README.md

Website | Getting started | Learn | Documentation | Contributing

This is the main source code repository for Rust. It contains the compiler, standard library, and documentation.

Why Rust?

  • Performance: Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrated with other languages.

  • Reliability: Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.

  • Productivity: Comprehensive documentation, a compiler committed to providing great diagnostics, and advanced tooling including package manager and build tool (Cargo), auto-formatter (rustfmt), linter (Clippy) and editor support (rust-analyzer).

Quick Start

Read “Installation” from The Book.

Installing from Source

If you really want to install from source (though this is not recommended), see INSTALL.md.

Getting Help

See https://www.rust-lang.org/community for a list of chat platforms and forums.

Contributing

See CONTRIBUTING.md.

For a detailed explanation of the compiler's architecture and how to begin contributing, see the rustc-dev-guide.

License

Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.

Trademark

The Rust Foundation owns and protects the Rust and Cargo trademarks and logos (the “Rust Trademarks”).

If you want to use these names or brands, please read the Rust language trademark policy.

Third-party logos may be subject to third-party copyrights and trademarks. See Licenses for details.