Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ impl Step for OmpOffload {
let inc_dir = base.display();
cflags.push_all(format!(" -I {inc_dir}"));
}
cflags.push_all(
" -ULIBC_NAMESPACE -DLIBC_NAMESPACE=__llvm_libc_22_1_0_rust1_95_0nightly",
);

configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), cflags, &[]);

Expand All @@ -1068,6 +1071,10 @@ impl Step for OmpOffload {
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
.define("LLVM_DIR", llvm_cmake_dir.clone())
// FIXME(offload): re-evaluate with LLVM23 if we can drop these three lines
//.define("LLVM_ENABLE_PER_TARGET_RUNTIME_DIR", "ON")
.define("CMAKE_CXX_COMPILER_WORKS", "TRUE")
.define("CMAKE_C_COMPILER_WORKS", "TRUE")
.define("LLVM_DEFAULT_TARGET_TRIPLE", omp_target);
if let Some(p) = clang_dir.clone() {
cfg.define("Clang_DIR", p);
Expand All @@ -1081,7 +1088,10 @@ impl Step for OmpOffload {
} 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("LIBC_INCLUDE_BENCHMARKS", "OFF");
cfg.define("LIBC_TARGET_TRIPLE", omp_target);
cfg.define("LLVM_LIBC_FULL_BUILD", "ON");
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp;libc");
Comment on lines +1091 to +1094
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: unfortunately I'm not sure.

I tried to remove the line where we set the target in configure_cmake (cfg.target(&target.triple).host(&builder.config.host_target.triple);), so libc-for-gpu could guess its GPU target, and rust bootstrap on the other hand isn't "surprised" by a different target.

I wonder if you are running into something like #138784 or rust-lang/cmake-rs#242 where cmake-rs isn't really equipped to handle cross-compilation outside of build.rs (i.e. used as a runtime library)?

Copy link
Member Author

@ZuseZ4 ZuseZ4 Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we're both here being unsure about a cmake change, while you link an issue about two other rustc devs being unsure about a cmake change. I see a common pattern here :D

@madsmtm it looks like you've been involved in some related issues. I have a single cmake invocation (out of 3 or 4) during bootstrap where I want the cpu target to either not be printed, or replace it once with a gpu target. Is there a way to achieve that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes 4 in total 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Since we already know that we don't understand it, I did the only reasonable thing: I didn't change anything and recompiled. It now works.

I also rebased and re-tested it in both combinations (enabling the clang project which is the normal local workflow, and with an external clang/llvm which is our CI workflow).

libc still uses the compiler name as a C++ namespace, which breaks since rust uses a . in our compiler name (1.96). I undefine and redefine it which breaks if you ctrl-C during the build and re-start (since it doesn't re-undefine the old name), but there should be a tracked variable for it.

To be clear, our current behaviour of setting the target to the host cpu when we compile libc (or some of the other gpu projects here) for a gpu is wrong, but we don't seem to know how to resolve that properly and it works for now, so I'll take that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Since we already know that we don't understand it, I did the only reasonable thing: I didn't change anything and recompiled. It now works.

Image

To be clear, our current behaviour of setting the target to the host cpu when we compile libc (or some of the other gpu projects here) for a gpu is wrong, but we don't seem to know how to resolve that properly and it works for now, so I'll take that.

Can you leave that as an FIXME in the code / tracked as an issue somewhere?

cfg.define("CMAKE_C_COMPILER_TARGET", omp_target);
cfg.define("CMAKE_CXX_COMPILER_TARGET", omp_target);
}
Expand Down
Loading