Skip to content

Conversation

@ZuseZ4
Copy link
Member

@ZuseZ4 ZuseZ4 commented Nov 22, 2025

This automates steps 2+3 (the clang invocations) of the rust offload usage pipeline.
Needs a full rewrite before review, but I managed to skip everything except the clang-linker-invocation with this!

r? ghost

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 22, 2025
@rust-log-analyzer

This comment has been minimized.

@ZuseZ4 ZuseZ4 added the F-gpu_offload `#![feature(gpu_offload)]` label Nov 22, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
fmt: checked 6563 files
tidy check
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
tidy [style (compiler)]: /checkout/compiler/rustc_codegen_llvm/src/back/write.rs:798: `dbg!` macro is intended as a debugging tool. It should not be in version control.
tidy [style (compiler)]: FAIL
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.3)
linting python files
All checks passed!
checking python file formatting
27 files already formatted
checking C++ file formatting
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:44:1: error: code should be clang-formatted [-Wclang-format-violations]
#include "llvm/Transforms/Utils/ModuleUtils.h"
^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:180:73: error: code should be clang-formatted [-Wclang-format-violations]
extern "C" bool LLVMRustBundleImages(LLVMModuleRef M, TargetMachine &TM, const char *HostOutPath) {
                                                                        ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:193:51: error: code should be clang-formatted [-Wclang-format-violations]
  ImageBinary.TheOffloadKind = object::OFK_OpenMP;
                                                  ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:259:1: error: code should be clang-formatted [-Wclang-format-violations]
#include "llvm/Support/TargetSelect.h"
^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:263:3: error: code should be clang-formatted [-Wclang-format-violations]
---
  ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:265:1: error: code should be clang-formatted [-Wclang-format-violations]
#include "llvm/MC/TargetRegistry.h"
^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:270:42: error: code should be clang-formatted [-Wclang-format-violations]
Error emitHostObjectWithTM(Module &HostM,
                                         ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:274:5: error: code should be clang-formatted [-Wclang-format-violations]
  //HostM.setDataLayout(TM.createDataLayout());
    ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:275:5: error: code should be clang-formatted [-Wclang-format-violations]
  //HostM.setTargetTriple(TM.getTargetTriple().str());
    ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:283:46: error: code should be clang-formatted [-Wclang-format-violations]
  if (TM.addPassesToEmitFile(PM, OS, nullptr, llvm::CodeGenFileType::ObjectFile))
                                             ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:324:18: error: code should be clang-formatted [-Wclang-format-violations]
  std::string CPU       = "x86-64"; // OK for X86
                 ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:337:58: error: code should be clang-formatted [-Wclang-format-violations]
      T->createTargetMachine(TripleStr, CPU, /*Features*/"", Opts, RM));
                                                         ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:343:71: error: code should be clang-formatted [-Wclang-format-violations]
// lib.bc (from first rustc) + host.out (from LLVMRustBundleImages) => host.offload.o
                                                                      ^

clang-format linting failed! Printing diff suggestions:
--- /checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp (actual)
+++ /checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp (formatted)
---
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
 
 // for raw `write` in the bad-alloc handler
 #ifdef _MSC_VER
 #include <io.h>
@@ -176,9 +176,10 @@
 // clang-offload-packager -o host.out
 //  --image=file=device.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp
 // The input module is the rust code compiled for a gpu target like amdgpu.
 // Based on clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
-extern "C" bool LLVMRustBundleImages(LLVMModuleRef M, TargetMachine &TM, const char *HostOutPath) {
+extern "C" bool LLVMRustBundleImages(LLVMModuleRef M, TargetMachine &TM,
+                                     const char *HostOutPath) {
   std::string Storage;
   llvm::raw_string_ostream OS1(Storage);
   llvm::WriteBitcodeToFile(*unwrap(M), OS1);
   OS1.flush();
@@ -191,9 +192,8 @@
   ImageBinary.TheImageKind = object::IMG_Bitcode;
   ImageBinary.Image = std::move(MB);
   ImageBinary.TheOffloadKind = object::OFK_OpenMP;
 
-
   std::string TripleStr = TM.getTargetTriple().str();
   llvm::StringRef CPURef = TM.getTargetCPU();
   ImageBinary.StringData["triple"] = TripleStr;
   ImageBinary.StringData["arch"] = CPURef;
@@ -255,33 +255,33 @@
   embedBufferInModule(HostM, Buf);
   return Error::success();
 }
 
+#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/IR/LegacyPassManager.h"
-//#include "llvm/Support/Host.h"
-//#include "llvm/Support/TargetRegistry.h"
+// #include "llvm/Support/Host.h"
+// #include "llvm/Support/TargetRegistry.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/CodeGen.h" // <-- new
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/CodeGen.h"        // <-- new
 
-Error emitHostObjectWithTM(Module &HostM,
-                           TargetMachine &TM,
+Error emitHostObjectWithTM(Module &HostM, TargetMachine &TM,
                            StringRef OutObjPath) {
   // Make sure module matches the TM
-  //HostM.setDataLayout(TM.createDataLayout());
-  //HostM.setTargetTriple(TM.getTargetTriple().str());
+  // HostM.setDataLayout(TM.createDataLayout());
+  // HostM.setTargetTriple(TM.getTargetTriple().str());
 
   legacy::PassManager PM;
   std::error_code EC;
   raw_fd_ostream OS(OutObjPath, EC, sys::fs::OF_None);
   if (EC)
     return errorCodeToError(EC);
 
-  if (TM.addPassesToEmitFile(PM, OS, nullptr, llvm::CodeGenFileType::ObjectFile))
+  if (TM.addPassesToEmitFile(PM, OS, nullptr,
+                             llvm::CodeGenFileType::ObjectFile))
     return createStringError(inconvertibleErrorCode(),
                              "TargetMachine can't emit a file of this type");
 
   PM.run(HostM);
@@ -320,9 +320,9 @@
   }
 
   // Hardcoded host triple + CPU (adapt if your CI/host differs)
   std::string TripleStr = "x86_64-unknown-linux-gnu";
-  std::string CPU       = "x86-64"; // OK for X86
+  std::string CPU = "x86-64"; // OK for X86
 
   std::string Err;
   const Target *T = TargetRegistry::lookupTarget(TripleStr, Err);
   if (!T) {
@@ -333,15 +333,16 @@
   TargetOptions Opts;
   auto RM = std::optional<Reloc::Model>(Reloc::PIC_);
 
   std::unique_ptr<TargetMachine> TM(
-      T->createTargetMachine(TripleStr, CPU, /*Features*/"", Opts, RM));
+      T->createTargetMachine(TripleStr, CPU, /*Features*/ "", Opts, RM));
 
   return TM;
 }
 
 // Top-level entry: host finalize in second rustc invocation
-// lib.bc (from first rustc) + host.out (from LLVMRustBundleImages) => host.offload.o
+// lib.bc (from first rustc) + host.out (from LLVMRustBundleImages) =>
+// host.offload.o
 extern "C" bool LLVMRustFinalizeOffload(const char *LibBCPath,
                                         const char *HostOutPath,
                                         const char *OutObjPath) {
   LLVMContext Ctx;

rerun tidy with `--extra-checks=cpp:fmt --bless` to reformat C++ code
tidy [extra_checks]: checks with external tool 'clang-format' failed
tidy [extra_checks]: FAIL
tidy: The following checks failed: extra_checks, style (compiler)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/yarn --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1594:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1285:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:01:23
  local time: Sat Nov 22 10:23:40 UTC 2025
  network time: Sat, 22 Nov 2025 10:23:40 GMT
##[error]Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide F-gpu_offload `#![feature(gpu_offload)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants