Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
# Whether to build LLVM with support for it's gpu offload runtime.
#llvm.offload = false

# Absolute path to the directory containing ClangConfig.cmake
#llvm.offload-clang-dir = ""

# When true, link libstdc++ statically into the rustc_llvm.
# This is useful if you don't want to use the dynamic version of that
# library provided by LLVM.
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def v(*args):
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
o("llvm-enzyme", "llvm.enzyme", "build LLVM with enzyme")
o("llvm-offload", "llvm.offload", "build LLVM with gpu offload support")
o(
"llvm-offload-clang-dir",
"llvm.offload-clang-dir",
"pass the absolute directory of ClangConfig.cmake",
)
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
o(
Expand Down
22 changes: 21 additions & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,10 +1427,12 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
if builder.config.llvm_enzyme {
cargo.env("LLVM_ENZYME", "1");
}
let llvm::LlvmResult { host_llvm_config, .. } = builder.ensure(llvm::Llvm { target });
if builder.config.llvm_offload {
builder.ensure(llvm::OmpOffload { target });
cargo.env("LLVM_OFFLOAD", "1");
}
let llvm::LlvmResult { host_llvm_config, .. } = builder.ensure(llvm::Llvm { target });

cargo.env("LLVM_CONFIG", &host_llvm_config);

// Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script
Expand Down Expand Up @@ -2293,6 +2295,24 @@ impl Step for Assemble {
}
}

if builder.config.llvm_offload && !builder.config.dry_run() {
debug!("`llvm_offload` requested");
let offload_install = builder.ensure(llvm::OmpOffload { target: build_compiler.host });
if let Some(_llvm_config) = builder.llvm_config(builder.config.host_target) {
let target_libdir =
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
for p in offload_install.offload_paths() {
let libname = p.file_name().unwrap();
let dst_lib = target_libdir.join(libname);
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.
}
}

// Build the libraries for this compiler to link to (i.e., the libraries
// it uses at runtime).
debug!(
Expand Down
Loading
Loading