Skip to content

Commit 2697c4e

Browse files
committed
Auto merge of #156971 - sgasho:playground-dynamic-linking-llvm-test-2, r=<try>
aarch64-apple-distcheck: symlink LLVM dylib try-job: aarch64-apple-distcheck-ci-llvm
2 parents 6eda741 + 63c7730 commit 2697c4e

7 files changed

Lines changed: 202 additions & 76 deletions

File tree

compiler/rustc_llvm/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ fn main() {
411411
continue;
412412
}
413413

414+
// On apple-darwin, llvm-config reports the versioned shared library name such as LLVM-22-..., but
415+
// the distributed toolchain ships libLLVM.dylib. Normalize the link name here.
416+
let name =
417+
if target.contains("apple-darwin") && llvm_kind == "dylib" && name.starts_with("LLVM-")
418+
{
419+
"LLVM"
420+
} else {
421+
name
422+
};
423+
414424
let kind = if name.starts_with("LLVM") {
415425
llvm_kind
416426
} else if is_static {

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ pub fn walk_native_lib_search_dirs<R>(
6262
f(&sess.target_tlib_path.dir.join("self-contained"), false)?;
6363
}
6464

65+
let has_shared_llvm_apple_darwin =
66+
sess.target.is_like_darwin && sess.target_tlib_path.dir.join("libLLVM.dylib").exists();
67+
6568
// Toolchains for some targets may ship `libunwind.a`, but place it into the main sysroot
6669
// library directory instead of the self-contained directories.
6770
// Sanitizer libraries have the same issue and are also linked by name on Apple targets.
6871
// The targets here should be in sync with `copy_third_party_objects` in bootstrap.
69-
// Finally there is shared LLVM library, which unlike compiler libraries, is linked by the name,
70-
// therefore requiring the search path for the linker.
72+
// On Apple targets, shared LLVM is linked by name, so when `libLLVM.dylib` is
73+
// present in the target libdir, add that directory to the linker search path.
7174
// FIXME: implement `-Clink-self-contained=+/-unwind,+/-sanitizers`, move the shipped libunwind
7275
// and sanitizers to self-contained directory, and stop adding this search path.
7376
// FIXME: On AIX this also has the side-effect of making the list of library search paths
@@ -77,7 +80,8 @@ pub fn walk_native_lib_search_dirs<R>(
7780
|| sess.target.os == Os::Linux
7881
|| sess.target.os == Os::Fuchsia
7982
|| sess.target.is_like_aix
80-
|| sess.target.is_like_darwin && !sess.sanitizers().is_empty()
83+
|| sess.target.is_like_darwin
84+
&& (!sess.sanitizers().is_empty() || has_shared_llvm_apple_darwin)
8185
|| sess.target.os == Os::Windows
8286
&& sess.target.env == Env::Gnu
8387
&& sess.target.cfg_abi == CfgAbi::Llvm
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Change this file to make users of the `download-ci-llvm` configuration download
22
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
33

4-
Last change is for: https://github.com/rust-lang/rust/pull/154485
4+
Last change is for: https://github.com/rust-lang/rust/pull/156880

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,25 @@ fn maybe_install_llvm(
25132513
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
25142514
if llvm_dylib_path.exists() {
25152515
builder.install(&llvm_dylib_path, dst_libdir, FileType::NativeLibrary);
2516+
2517+
if install_symlink && let Some(llvm_config_path) = &builder.llvm_config(target) {
2518+
let major = llvm::get_llvm_version_major(builder, llvm_config_path);
2519+
let versioned_name = match &builder.config.llvm_version_suffix {
2520+
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.dylib"),
2521+
None => {
2522+
// same logic as ./llvm.rs
2523+
if builder.config.channel == "dev" {
2524+
format!("libLLVM-{major}-rust-dev.dylib")
2525+
} else {
2526+
format!(
2527+
"libLLVM-{major}-rust-{}-{}.dylib",
2528+
builder.version, builder.config.channel
2529+
)
2530+
}
2531+
}
2532+
};
2533+
t!(builder.symlink_file("libLLVM.dylib", dst_libdir.join(versioned_name)));
2534+
}
25162535
}
25172536
!builder.config.dry_run()
25182537
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult {
@@ -2858,7 +2877,8 @@ impl Step for RustDev {
28582877
if src_bindir.exists() {
28592878
for entry in walkdir::WalkDir::new(&src_bindir) {
28602879
let entry = t!(entry);
2861-
if entry.file_type().is_file() && !entry.path_is_symlink() {
2880+
//if entry.file_type().is_file() && !entry.path_is_symlink() {
2881+
if entry.path().is_file() {
28622882
let name = entry.file_name().to_str().unwrap();
28632883
tarball.add_file(src_bindir.join(name), "bin", FileType::Executable);
28642884
}

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 131 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,101 +3467,161 @@ impl Step for Distcheck {
34673467
// local source code, built artifacts or configuration by accident
34683468
let root_dir = std::env::temp_dir().join("distcheck");
34693469

3470-
distcheck_plain_source_tarball(builder, &root_dir.join("distcheck-rustc-src"));
3471-
distcheck_rust_src(builder, &root_dir.join("distcheck-rust-src"));
3472-
distcheck_rustc_dev(builder, &root_dir.join("distcheck-rustc-dev"));
3470+
distcheck_rust_dev_ci_llvm(builder, &root_dir.join("distcheck_rust_dev"));
3471+
// distcheck_plain_source_tarball(builder, &root_dir.join("distcheck-rustc-src"));
3472+
// distcheck_rust_src(builder, &root_dir.join("distcheck-rust-src"));
3473+
// distcheck_rustc_dev(builder, &root_dir.join("distcheck-rustc-dev"));
34733474
}
34743475
}
34753476

3476-
/// Check that we can build some basic things from the plain source tarball
3477-
fn distcheck_plain_source_tarball(builder: &Builder<'_>, plain_src_dir: &Path) {
3478-
builder.info("Distcheck plain source tarball");
3479-
let plain_src_tarball = builder.ensure(dist::PlainSourceTarball);
3480-
builder.clear_dir(plain_src_dir);
3477+
fn distcheck_rust_dev_ci_llvm(builder: &Builder<'_>, dir: &Path) {
3478+
builder.info("Distcheck rust dev");
3479+
let Some(rust_dev) = builder.ensure(dist::RustDev { target: builder.host_target }) else {
3480+
return;
3481+
};
3482+
builder.clear_dir(dir);
34813483

3482-
let configure_args: Vec<String> = std::env::var("DISTCHECK_CONFIGURE_ARGS")
3483-
.map(|args| args.split(" ").map(|s| s.to_string()).collect::<Vec<String>>())
3484-
.unwrap_or_default();
3484+
let ci_llvm_dir = dir.join("ci-llvm");
3485+
builder.clear_dir(&ci_llvm_dir);
34853486

34863487
command("tar")
34873488
.arg("-xf")
3488-
.arg(plain_src_tarball.tarball())
3489+
.arg(rust_dev.tarball())
34893490
.arg("--strip-components=1")
3490-
.current_dir(plain_src_dir)
3491-
.run(builder);
3492-
command("./configure")
3493-
.arg("--set")
3494-
.arg("rust.omit-git-hash=false")
3495-
.arg("--set")
3496-
.arg("rust.remap-debuginfo=false")
3497-
.args(&configure_args)
3498-
.arg("--enable-vendor")
3499-
.current_dir(plain_src_dir)
3500-
.run(builder);
3501-
command(helpers::make(&builder.config.host_target.triple))
3502-
.arg("check")
3503-
// Do not run the build as if we were in CI, otherwise git would be assumed to be
3504-
// present, but we build from a tarball here
3505-
.env("GITHUB_ACTIONS", "0")
3506-
.current_dir(plain_src_dir)
3491+
.current_dir(&ci_llvm_dir)
35073492
.run(builder);
3508-
// Mitigate pressure on small-capacity disks.
3509-
builder.remove_dir(plain_src_dir);
3510-
}
35113493

3512-
/// Check that rust-src has all of libstd's dependencies
3513-
fn distcheck_rust_src(builder: &Builder<'_>, src_dir: &Path) {
3514-
builder.info("Distcheck rust-src");
3515-
let src_tarball = builder.ensure(dist::Src);
3516-
builder.clear_dir(src_dir);
3494+
let llvm_config = ci_llvm_dir
3495+
.join("rust-dev")
3496+
.join("bin")
3497+
.join(helpers::exe("llvm-config", builder.host_target));
3498+
3499+
let plain_source_dir = dir.join("plain_source_dir");
3500+
let plain_src_tarball = builder.ensure(dist::PlainSourceTarball);
3501+
builder.clear_dir(&plain_source_dir);
35173502

35183503
command("tar")
35193504
.arg("-xf")
3520-
.arg(src_tarball.tarball())
3505+
.arg(plain_src_tarball.tarball())
35213506
.arg("--strip-components=1")
3522-
.current_dir(src_dir)
3507+
.current_dir(&plain_source_dir)
35233508
.run(builder);
35243509

3525-
let toml = src_dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
3526-
command(&builder.initial_cargo)
3527-
// Will read the libstd Cargo.toml
3528-
// which uses the unstable `public-dependency` feature.
3529-
.env("RUSTC_BOOTSTRAP", "1")
3530-
.arg("generate-lockfile")
3531-
.arg("--manifest-path")
3532-
.arg(&toml)
3533-
.current_dir(src_dir)
3510+
command("./configure")
3511+
.arg("--set")
3512+
.arg("rust.omit-git-hash=false")
3513+
.arg("--set")
3514+
.arg("rust.remap-debuginfo=false")
3515+
.arg("--set")
3516+
.arg(format!("target.{}.llvm-config={}", builder.host_target.triple, llvm_config.display()))
3517+
.arg("--set")
3518+
.arg("llvm.link-shared=true")
3519+
.arg("--enable-vendor")
3520+
.current_dir(&plain_source_dir)
35343521
.run(builder);
3535-
// Mitigate pressure on small-capacity disks.
3536-
builder.remove_dir(src_dir);
3537-
}
35383522

3539-
/// Check that rustc-dev's compiler crate source code can be loaded with `cargo metadata`
3540-
fn distcheck_rustc_dev(builder: &Builder<'_>, dir: &Path) {
3541-
builder.info("Distcheck rustc-dev");
3542-
let tarball = builder.ensure(dist::RustcDev::new(builder, builder.host_target)).unwrap();
3543-
builder.clear_dir(dir);
3523+
let llvm_lib_dir = ci_llvm_dir.join("rust-dev").join("lib");
3524+
let llvm_rpath = format!("-Clink-arg=-Wl,-rpath,{}", llvm_lib_dir.display());
35443525

3545-
command("tar")
3546-
.arg("-xf")
3547-
.arg(tarball.tarball())
3548-
.arg("--strip-components=1")
3549-
.current_dir(dir)
3526+
command("./x.py")
3527+
.arg("build")
3528+
.arg("library")
3529+
.env("RUSTFLAGS_BOOTSTRAP", llvm_rpath)
3530+
.current_dir(&plain_source_dir)
35503531
.run(builder);
35513532

3552-
command(&builder.initial_cargo)
3553-
.arg("metadata")
3554-
.arg("--manifest-path")
3555-
.arg("rustc-dev/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml")
3556-
.env("RUSTC_BOOTSTRAP", "1")
3557-
// We might not have a globally available `rustc` binary on CI
3558-
.env("RUSTC", &builder.initial_rustc)
3559-
.current_dir(dir)
3560-
.run(builder);
3561-
// Mitigate pressure on small-capacity disks.
35623533
builder.remove_dir(dir);
35633534
}
35643535

3536+
// /// Check that we can build some basic things from the plain source tarball
3537+
// fn distcheck_plain_source_tarball(builder: &Builder<'_>, plain_src_dir: &Path) {
3538+
// builder.info("Distcheck plain source tarball");
3539+
// let plain_src_tarball = builder.ensure(dist::PlainSourceTarball);
3540+
// builder.clear_dir(plain_src_dir);
3541+
3542+
// let configure_args: Vec<String> = std::env::var("DISTCHECK_CONFIGURE_ARGS")
3543+
// .map(|args| args.split(" ").map(|s| s.to_string()).collect::<Vec<String>>())
3544+
// .unwrap_or_default();
3545+
3546+
// command("tar")
3547+
// .arg("-xf")
3548+
// .arg(plain_src_tarball.tarball())
3549+
// .arg("--strip-components=1")
3550+
// .current_dir(plain_src_dir)
3551+
// .run(builder);
3552+
// command("./configure")
3553+
// .arg("--set")
3554+
// .arg("rust.omit-git-hash=false")
3555+
// .arg("--set")
3556+
// .arg("rust.remap-debuginfo=false")
3557+
// .args(&configure_args)
3558+
// .arg("--enable-vendor")
3559+
// .current_dir(plain_src_dir)
3560+
// .run(builder);
3561+
// command(helpers::make(&builder.config.host_target.triple))
3562+
// .arg("check")
3563+
// // Do not run the build as if we were in CI, otherwise git would be assumed to be
3564+
// // present, but we build from a tarball here
3565+
// .env("GITHUB_ACTIONS", "0")
3566+
// .current_dir(plain_src_dir)
3567+
// .run(builder);
3568+
// // Mitigate pressure on small-capacity disks.
3569+
// builder.remove_dir(plain_src_dir);
3570+
// }
3571+
3572+
// /// Check that rust-src has all of libstd's dependencies
3573+
// fn distcheck_rust_src(builder: &Builder<'_>, src_dir: &Path) {
3574+
// builder.info("Distcheck rust-src");
3575+
// let src_tarball = builder.ensure(dist::Src);
3576+
// builder.clear_dir(src_dir);
3577+
3578+
// command("tar")
3579+
// .arg("-xf")
3580+
// .arg(src_tarball.tarball())
3581+
// .arg("--strip-components=1")
3582+
// .current_dir(src_dir)
3583+
// .run(builder);
3584+
3585+
// let toml = src_dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
3586+
// command(&builder.initial_cargo)
3587+
// // Will read the libstd Cargo.toml
3588+
// // which uses the unstable `public-dependency` feature.
3589+
// .env("RUSTC_BOOTSTRAP", "1")
3590+
// .arg("generate-lockfile")
3591+
// .arg("--manifest-path")
3592+
// .arg(&toml)
3593+
// .current_dir(src_dir)
3594+
// .run(builder);
3595+
// // Mitigate pressure on small-capacity disks.
3596+
// builder.remove_dir(src_dir);
3597+
// }
3598+
3599+
// /// Check that rustc-dev's compiler crate source code can be loaded with `cargo metadata`
3600+
// fn distcheck_rustc_dev(builder: &Builder<'_>, dir: &Path) {
3601+
// builder.info("Distcheck rustc-dev");
3602+
// let tarball = builder.ensure(dist::RustcDev::new(builder, builder.host_target)).unwrap();
3603+
// builder.clear_dir(dir);
3604+
3605+
// command("tar")
3606+
// .arg("-xf")
3607+
// .arg(tarball.tarball())
3608+
// .arg("--strip-components=1")
3609+
// .current_dir(dir)
3610+
// .run(builder);
3611+
3612+
// command(&builder.initial_cargo)
3613+
// .arg("metadata")
3614+
// .arg("--manifest-path")
3615+
// .arg("rustc-dev/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml")
3616+
// .env("RUSTC_BOOTSTRAP", "1")
3617+
// // We might not have a globally available `rustc` binary on CI
3618+
// .env("RUSTC", &builder.initial_rustc)
3619+
// .current_dir(dir)
3620+
// .run(builder);
3621+
// // Mitigate pressure on small-capacity disks.
3622+
// builder.remove_dir(dir);
3623+
// }
3624+
35653625
/// Runs unit tests in `bootstrap_test.py`, which test the Python parts of bootstrap.
35663626
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
35673627
pub(crate) struct BootstrapPy;

src/bootstrap/src/utils/helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
285285
}
286286
}
287287

288+
#[allow(dead_code)]
288289
pub fn make(host: &str) -> PathBuf {
289290
if host.contains("dragonfly")
290291
|| host.contains("freebsd")

src/ci/github-actions/jobs.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ auto:
526526
--enable-sanitizers
527527
--enable-profiler
528528
--set rust.jemalloc
529+
--set llvm.link-shared=true
529530
--set rust.lto=thin
530531
--set rust.codegen-units=1
531532
# Aarch64 tooling only needs to support macOS 11.0 and up as nothing else
@@ -537,6 +538,36 @@ auto:
537538
CODEGEN_BACKENDS: llvm,cranelift
538539
<<: *job-macos
539540

541+
- name: aarch64-apple-distcheck
542+
env:
543+
SCRIPT: >-
544+
./x.py test distcheck
545+
--host=aarch64-apple-darwin
546+
--target=aarch64-apple-darwin
547+
DISTCHECK_CONFIGURE_ARGS: >-
548+
--set llvm.link-shared=true
549+
# Aarch64 tooling only needs to support macOS 11.0 and up as nothing else
550+
# supports the hardware.
551+
MACOSX_DEPLOYMENT_TARGET: 11.0
552+
MACOSX_STD_DEPLOYMENT_TARGET: 11.0
553+
DEVELOPER_DIR: /Applications/Xcode_26.2.app/Contents/Developer
554+
<<: *job-macos
555+
556+
- name: aarch64-apple-distcheck-ci-llvm
557+
env:
558+
SCRIPT: >-
559+
./x.py test distcheck
560+
--host=aarch64-apple-darwin
561+
--target=aarch64-apple-darwin
562+
RUST_CONFIGURE_ARGS: >-
563+
--set llvm.link-shared=true
564+
# Aarch64 tooling only needs to support macOS 11.0 and up as nothing else
565+
# supports the hardware.
566+
MACOSX_DEPLOYMENT_TARGET: 11.0
567+
MACOSX_STD_DEPLOYMENT_TARGET: 11.0
568+
DEVELOPER_DIR: /Applications/Xcode_26.2.app/Contents/Developer
569+
<<: *job-macos
570+
540571
- name: aarch64-apple
541572
env:
542573
SCRIPT: >

0 commit comments

Comments
 (0)