Skip to content

Commit 2a6ccec

Browse files
committed
new changes, not passed ci yet
1 parent 0d26ab3 commit 2a6ccec

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,58 @@ impl Step for Assemble {
22162216
}
22172217
}
22182218

2219+
if builder.config.llvm_offload && !builder.config.dry_run() {
2220+
debug!("`llvm_offload` requested");
2221+
let offload_install = builder.ensure(llvm::OmpOffload { target: build_compiler.host });
2222+
if let Some(_llvm_config) = builder.llvm_config(builder.config.host_target) {
2223+
let src_dir = offload_install.join("lib");
2224+
let libdir = builder.sysroot_target_libdir(build_compiler, build_compiler.host);
2225+
let target_libdir =
2226+
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
2227+
let lib_ext = std::env::consts::DLL_EXTENSION;
2228+
2229+
let libenzyme = format!("libLLVMOffload");
2230+
let src_lib = src_dir.join(&libenzyme).with_extension(lib_ext);
2231+
let dst_lib = libdir.join(&libenzyme).with_extension(lib_ext);
2232+
let target_dst_lib = target_libdir.join(&libenzyme).with_extension(lib_ext);
2233+
builder.resolve_symlink_and_copy(&src_lib, &dst_lib);
2234+
builder.resolve_symlink_and_copy(&src_lib, &target_dst_lib);
2235+
2236+
// FIXME(offload): With LLVM-22, we should be able to drop everything below here.
2237+
let omp = format!("libomp");
2238+
let src_omp = src_dir.join(&omp).with_extension(lib_ext);
2239+
let dst_omp_lib = libdir.join(&omp).with_extension(lib_ext);
2240+
let target_omp_dst_lib = target_libdir.join(&omp).with_extension(lib_ext);
2241+
builder.resolve_symlink_and_copy(&src_omp, &dst_omp_lib);
2242+
builder.resolve_symlink_and_copy(&src_omp, &target_omp_dst_lib);
2243+
2244+
let tgt = format!("libomptarget");
2245+
let src_tgt = src_dir.join(&tgt).with_extension(lib_ext);
2246+
let dst_tgt_lib = libdir.join(&tgt).with_extension(lib_ext);
2247+
let target_tgt_dst_lib = target_libdir.join(&tgt).with_extension(lib_ext);
2248+
builder.resolve_symlink_and_copy(&src_tgt, &dst_tgt_lib);
2249+
builder.resolve_symlink_and_copy(&src_tgt, &target_tgt_dst_lib);
2250+
2251+
// The last one is slightly more tricky, since we have the same file twice, in two
2252+
// subfolders for amdgcn and nvptx64. We'll likely find two more in the future, once
2253+
// Intel and Spir-V support lands in offload.
2254+
let gpu_tgts = ["amdgcn-amd-amdhsa", "nvptx64-nvidia-cuda"];
2255+
let device = format!("libompdevice.a");
2256+
for tgt in gpu_tgts {
2257+
let dst_tgt_dir = libdir.join(&tgt);
2258+
let target_tgt_dst_dir = target_libdir.join(&tgt);
2259+
t!(fs::create_dir_all(&dst_tgt_dir));
2260+
t!(fs::create_dir_all(&target_tgt_dst_dir));
2261+
let dst_tgt_lib = dst_tgt_dir.join(&device);
2262+
let target_tgt_dst_lib = target_tgt_dst_dir.join(&device);
2263+
builder.resolve_symlink_and_copy(&src_tgt, &dst_tgt_lib);
2264+
builder.resolve_symlink_and_copy(&src_tgt, &target_tgt_dst_lib);
2265+
// FIXME(offload): copy the files within the directories as well, but figure out
2266+
// the naming scheme before.
2267+
}
2268+
}
2269+
}
2270+
22192271
// Build the libraries for this compiler to link to (i.e., the libraries
22202272
// it uses at runtime).
22212273
debug!(

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ impl Step for OmpOffload {
945945
// subfolder, so that all the logic that processes our build artifacts (hopefully) also
946946
// automatically manages our artifacts in the subfolder.
947947
let out_dir = builder.llvm_out(target).join("offload-outdir");
948-
if std::fs::exists(&out_dir).is_ok_and(|x| x == false) {
948+
if std::fs::exists(&out_dir).is_ok_and(|x| !x) {
949949
std::fs::DirBuilder::new().create(&out_dir).unwrap();
950950
}
951951

0 commit comments

Comments
 (0)