From 9fae79b1231ae84e3a71f624850c40d907ee318f Mon Sep 17 00:00:00 2001 From: sgasho Date: Fri, 10 Jul 2026 10:08:46 +0000 Subject: [PATCH 1/3] Build offload in CI --- src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile index b168c739c9793..18fccdbd368e1 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile @@ -65,7 +65,7 @@ RUN ./cmake.sh # Now build LLVM+Clang, afterwards configuring further compilations to use the # clang/clang++ compilers. COPY scripts/build-clang.sh /tmp/ -ENV LLVM_BUILD_TARGETS=X86 +ENV LLVM_BUILD_TARGETS="X86;AMDGPU;NVPTX" RUN ./build-clang.sh ENV CC=clang CXX=clang++ @@ -90,6 +90,8 @@ ENV RUST_CONFIGURE_ARGS="--enable-full-tools \ --set llvm.thin-lto=true \ --set llvm.ninja=false \ --set llvm.libzstd=true \ + --set llvm.offload=true \ + --set llvm.offload-clang-dir="/rustroot/lib/cmake/clang" \ --set rust.jemalloc \ --set rust.bootstrap-override-lld=true \ --set rust.lto=thin \ From c90fad197872db0694d690e55bcc906e7b5085a0 Mon Sep 17 00:00:00 2001 From: sgasho Date: Sun, 12 Jul 2026 14:35:50 +0000 Subject: [PATCH 2/3] ship amd and nvidia libs to rustc tarball --- src/bootstrap/src/core/build_steps/compile.rs | 12 ++++----- src/bootstrap/src/core/build_steps/dist.rs | 13 ++++++++++ src/bootstrap/src/core/build_steps/llvm.rs | 26 +++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 3216fd671c3f8..64929524d347a 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2309,15 +2309,15 @@ impl Step for Assemble { if let Some(_llvm_config) = builder.llvm_config(builder.config.host_target) { let target_libdir = builder.sysroot_target_libdir(target_compiler, target_compiler.host); + + let offload_libdir = builder.offload_out(build_compiler.host).join("lib"); + for p in offload_install.offload_paths() { - let libname = p.file_name().unwrap(); - let dst_lib = target_libdir.join(libname); + let relative = t!(p.strip_prefix(&offload_libdir)); + let dst_lib = target_libdir.join(relative); + t!(fs::create_dir_all(dst_lib.parent().unwrap())); builder.resolve_symlink_and_copy(&p, &dst_lib); } - // FIXME(offload): Add amdgcn-amd-amdhsa and nvptx64-nvidia-cuda folder - // This one is slightly more tricky, since we have the same file twice, in two - // subfolders for amdgcn and nvptx64. We'll likely find two more in the future, once - // Intel and Spir-V support lands in offload. } } diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 114387d963a6d..34ad7de794eeb 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -619,6 +619,19 @@ impl Step for Rustc { ); } + if builder.config.llvm_offload { + let src_dir = builder.sysroot_target_libdir(target_compiler, target); + let dst_dir = image.join("lib/rustlib").join(target).join("lib"); + + for offload_target in ["amdgcn-amd-amdhsa", "nvptx64-nvidia-cuda"] { + let src = src_dir.join(offload_target); + let dst = dst_dir.join(offload_target); + + t!(fs::create_dir_all(&dst)); + builder.cp_link_r(&src, &dst); + } + } + if builder.tool_enabled("wasm-component-ld") { let src_dir = builder.sysroot_target_bindir(target_compiler, target); let ld = exe("wasm-component-ld", target_compiler.host); diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 6f1b8532f031b..ff704043814a3 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -993,6 +993,31 @@ impl Step for OmpOffload { files.push(out_dir.join("lib").join("libomp").with_extension(lib_ext)); files.push(out_dir.join("lib").join("libomptarget").with_extension(lib_ext)); + files.push( + out_dir.join("lib").join("amdgcn-amd-amdhsa").join("libompdevice").with_extension("a"), + ); + files.push( + out_dir + .join("lib") + .join("amdgcn-amd-amdhsa") + .join("libomptarget-amdgpu") + .with_extension("bc"), + ); + files.push( + out_dir + .join("lib") + .join("nvptx64-nvidia-cuda") + .join("libompdevice") + .with_extension("a"), + ); + files.push( + out_dir + .join("lib") + .join("nvptx64-nvidia-cuda") + .join("libomptarget-nvptx") + .with_extension("bc"), + ); + // Offload/OpenMP are just subfolders of LLVM, so we can use the LLVM sha. static STAMP_HASH_MEMO: OnceLock = OnceLock::new(); let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| { @@ -1092,6 +1117,7 @@ impl Step for OmpOffload { cfg.define("LLVM_ENABLE_RUNTIMES", "openmp;offload"); } else { // OpenMP provides some device libraries, so we also compile it for all gpu targets. + cfg.define("OPENMP_INSTALL_LIBDIR", Path::new("lib").join(omp_target)); cfg.define("LLVM_USE_LINKER", "lld"); cfg.define("LLVM_ENABLE_RUNTIMES", "openmp"); cfg.define("CMAKE_C_COMPILER_TARGET", omp_target); From d2835ee4c1e1d95781f5dd4922657a92985774ef Mon Sep 17 00:00:00 2001 From: sgasho Date: Mon, 13 Jul 2026 14:47:06 +0000 Subject: [PATCH 3/3] modify copy_directory options --- src/tools/opt-dist/src/utils/io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/opt-dist/src/utils/io.rs b/src/tools/opt-dist/src/utils/io.rs index ce425bdfece2c..bad2b692fde6f 100644 --- a/src/tools/opt-dist/src/utils/io.rs +++ b/src/tools/opt-dist/src/utils/io.rs @@ -15,7 +15,7 @@ pub fn reset_directory(path: &Utf8Path) -> anyhow::Result<()> { pub fn copy_directory(src: &Utf8Path, dst: &Utf8Path) -> anyhow::Result<()> { log::info!("Copying directory {src} to {dst}"); - fs_extra::dir::copy(src, dst, &CopyOptions::default().copy_inside(true))?; + fs_extra::dir::copy(src, dst, &CopyOptions::default().content_only(true))?; Ok(()) }