Rollup merge of #152195 - ZuseZ4:update-offload-llvm22-A, r=jieyouxu

update openmp/offload builds to LLVM 22, Part 1

This part of the update of OpenMP/Offload to LLVM 22 does not depend on a backport in the future LLVM release candidate 3. Let's therefore merge it first, to unblock existing users/developers.

r? @jieyouxu
This commit is contained in:
Jonathan Brouwer 2026-02-06 10:06:48 +01:00 committed by GitHub
commit 8420a080da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1008,33 +1008,9 @@ impl Step for OmpOffload {
t!(fs::create_dir_all(&out_dir));
builder.config.update_submodule("src/llvm-project");
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/runtimes/"));
// If we use an external clang as opposed to building our own llvm_clang, than that clang will
// come with it's own set of default include directories, which are based on a potentially older
// LLVM. This can cause issues, so we overwrite it to include headers based on our
// `src/llvm-project` submodule instead.
// FIXME(offload): With LLVM-22 we hopefully won't need an external clang anymore.
let mut cflags = CcFlags::default();
if !builder.config.llvm_clang {
let base = builder.llvm_out(target).join("include");
let inc_dir = base.display();
cflags.push_all(format!(" -I {inc_dir}"));
}
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), cflags, &[]);
// Re-use the same flags as llvm to control the level of debug information
// generated for offload.
let profile = match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
(false, _) => "Debug",
(true, false) => "Release",
(true, true) => "RelWithDebInfo",
};
trace!(?profile);
// OpenMP/Offload builds currently (LLVM-21) still depend on Clang, although there are
// intentions to loosen this requirement for LLVM-22. If we were to
// OpenMP/Offload builds currently (LLVM-22) still depend on Clang, although there are
// intentions to loosen this requirement over time. FIXME(offload): re-evaluate on LLVM 23
let clang_dir = if !builder.config.llvm_clang {
// We must have an external clang to use.
assert!(&builder.build.config.llvm_clang_dir.is_some());
@ -1044,23 +1020,66 @@ impl Step for OmpOffload {
None
};
// FIXME(offload): Once we move from OMP to Offload (Ol) APIs, we should drop the openmp
// runtime to simplify our build. We should also re-evaluate the LLVM_Root and try to get
// rid of the Clang_DIR, once we upgrade to LLVM-22.
cfg.out_dir(&out_dir)
.profile(profile)
.env("LLVM_CONFIG_REAL", &host_llvm_config)
.define("LLVM_ENABLE_ASSERTIONS", "ON")
.define("LLVM_ENABLE_RUNTIMES", "openmp;offload")
.define("LLVM_INCLUDE_TESTS", "OFF")
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
.define("OPENMP_STANDALONE_BUILD", "ON")
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
.define("LLVM_DIR", llvm_cmake_dir);
if let Some(p) = clang_dir {
cfg.define("Clang_DIR", p);
// In the context of OpenMP offload, some libraries must be compiled for the gpu target,
// some for the host, and others for both. We do not perform a full cross-compilation, since
// we don't want to run rustc on a GPU.
let omp_targets = vec![target.triple.as_ref(), "amdgcn-amd-amdhsa", "nvptx64-nvidia-cuda"];
for omp_target in omp_targets {
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/runtimes/"));
// If we use an external clang as opposed to building our own llvm_clang, than that clang will
// come with it's own set of default include directories, which are based on a potentially older
// LLVM. This can cause issues, so we overwrite it to include headers based on our
// `src/llvm-project` submodule instead.
// FIXME(offload): With LLVM-22 we hopefully won't need an external clang anymore.
let mut cflags = CcFlags::default();
if !builder.config.llvm_clang {
let base = builder.llvm_out(target).join("include");
let inc_dir = base.display();
cflags.push_all(format!(" -I {inc_dir}"));
}
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), cflags, &[]);
// Re-use the same flags as llvm to control the level of debug information
// generated for offload.
let profile =
match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
(false, _) => "Debug",
(true, false) => "Release",
(true, true) => "RelWithDebInfo",
};
trace!(?profile);
// FIXME(offload): Once we move from OMP to Offload (Ol) APIs, we should drop the openmp
// runtime to simplify our build. So far, these are still under development.
cfg.out_dir(&out_dir)
.profile(profile)
.env("LLVM_CONFIG_REAL", &host_llvm_config)
.define("LLVM_ENABLE_ASSERTIONS", "ON")
.define("LLVM_INCLUDE_TESTS", "OFF")
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
.define("LLVM_DIR", llvm_cmake_dir.clone())
.define("LLVM_DEFAULT_TARGET_TRIPLE", omp_target);
if let Some(p) = clang_dir.clone() {
cfg.define("Clang_DIR", p);
}
// We don't perform a full cross-compilation of rustc, therefore our target.triple
// will still be a CPU target.
if *omp_target == *target.triple {
// The offload library provides functionality which only makes sense on the host.
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp;offload");
} else {
// OpenMP provides some device libraries, so we also compile it for all gpu targets.
cfg.define("LLVM_USE_LINKER", "lld");
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp");
cfg.define("CMAKE_C_COMPILER_TARGET", omp_target);
cfg.define("CMAKE_CXX_COMPILER_TARGET", omp_target);
}
cfg.build();
}
cfg.build();
t!(stamp.write());