Skip to content

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Sep 9, 2025

Implements #146356 by adding the raw_dylib_macho feature flag.

@Noratrieb sniped me at RustWeek few months back to investigate this, never got around to finishing it.

This is a draft because I found out (after being 80% done with the impl) that using LLVM's TextAPI is probably not going to fly if we want to support other codegen backends, we'll need to write .tbd stubs ourselves.

TODO:

  • Figure out which TextAPI version to support (should at least support our minimum host tooling).
  • Write some hacky code to output the yaml manually (we probably don't want to pull in a whole yaml library). Alternatively, emit a Mach-O stub file using object.
  • Replace the LLVM TextAPI stuff I've done already.
  • Write a properly detailed PR description.
  • Add a bunch more tests in different scenarios.

r? bjorn3
CC @Noratrieb @thomcc @roblabla

@madsmtm madsmtm added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-raw_dylib `#![feature(raw_dylib)]` O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) labels Sep 9, 2025
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 9, 2025
@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)
tidy check
Checking tidy rustdoc_json...
No error code explanation was removed!
tidy: Skipping binary file check, read-only filesystem
##[error]tidy error: /checkout/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs:135: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
##[error]tidy error: /checkout/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs:142: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
##[error]tidy error: /checkout/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs:154: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
##[error]tidy error: /checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:1968: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
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.2)
linting python files
---
                               ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:1963:29: error: code should be clang-formatted [-Wclang-format-violations]
    uint32_t CurrentVersion,
                            ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:1965:43: error: code should be clang-formatted [-Wclang-format-violations]
    const LLVMRustMachOTbdExport *Exports,
                                          ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:1981:72: error: code should be clang-formatted [-Wclang-format-violations]
    File.addSymbol(Exports[i].kind, StringRef(Exports[i].name), Target, Exports[i].flags);
                                                                       ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:1994:67: error: code should be clang-formatted [-Wclang-format-violations]
  if (Error Err = MachO::TextAPIWriter::writeToStream(OS, File)) {
                                                                  ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:1995:62: error: code should be clang-formatted [-Wclang-format-violations]
      LLVMRustSetLastError(toString(std::move(Err)).c_str());
                                                             ^

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)
@@ -1956,15 +1956,11 @@
   MachO::EncodeKind kind;
 };
 
 extern "C" uint8_t LLVMRustMachoTbdWrite(
-    const char *Path,
-    const char *LLVMTargetName,
-    const char *InstallName,
-    uint32_t CurrentVersion,
-    uint32_t CompatibilityVersion,
-    const LLVMRustMachOTbdExport *Exports,
-    size_t NumExports) {
+    const char *Path, const char *LLVMTargetName, const char *InstallName,
+    uint32_t CurrentVersion, uint32_t CompatibilityVersion,
+    const LLVMRustMachOTbdExport *Exports, size_t NumExports) {
   MachO::InterfaceFile File;
   File.setFileType(MachO::FileType::TBD_V1); // TODO
 
   File.setInstallName(StringRef(InstallName));
@@ -1977,9 +1973,10 @@
   MachO::Target Target{Triple(LLVMTargetName)};
   File.addTarget(Target);
 
   for (size_t i = 0; i < NumExports; i++) {
-    File.addSymbol(Exports[i].kind, StringRef(Exports[i].name), Target, Exports[i].flags);
+    File.addSymbol(Exports[i].kind, StringRef(Exports[i].name), Target,
+                   Exports[i].flags);
   }
 
   std::string ErrorInfo;
   std::error_code EC;
@@ -1991,10 +1988,10 @@
     return -1;
   }
 
   if (Error Err = MachO::TextAPIWriter::writeToStream(OS, File)) {
-      LLVMRustSetLastError(toString(std::move(Err)).c_str());
-      return -1;
+    LLVMRustSetLastError(toString(std::move(Err)).c_str());
+    return -1;
   }
 
   return 0;
 }

some tidy checks failed
tidy error: checks with external tool 'clang-format' failed
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
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/npm --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1550:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1281:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:01:18
  local time: Tue Sep  9 02:00:13 UTC 2025
  network time: Tue, 09 Sep 2025 02:00:13 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@bors
Copy link
Collaborator

bors commented Sep 27, 2025

☔ The latest upstream changes (presumably #146636) made this pull request unmergeable. Please resolve the merge conflicts.

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-raw_dylib `#![feature(raw_dylib)]` O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) 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.

5 participants