Skip to content

Conversation

@fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Jan 9, 2026

This is obviously a draft in an early stage, but the amount of work needed to get it working was surprisingly little.

TODO:

  • Verify that core builds
  • File MCP, discuss best practices and options for an initial PR
  • Update src/bootstrap/download-ci-llvm-stamp
  • Update build-manifest
  • Update platform-support

@rustbot rustbot added 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. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 9, 2026
@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2026

Correct me if I'm wrong, but this would need to enable SPV_KHR_untyped_pointers, right? Rust's memory model is not compatible with typed memory and even something as simple as enums will fail (rust-gpu has a non-trivial compiler pass to try to get it to work with typed memory, but supposedly still fails on a lot of enum usage). It seems like enabling that would need -Cllvm-args=-spirv-ext=+SPV_KHR_untyped_pointers rather than -Ctarget-feature=+SPV_KHR_untyped_pointers for some reason, but I also can't find any mention of LLVM supporting this feature in the first place. Getting OpenCL SPIR-V working should be much easier. Unlike Vulkan SPIR-V, it does unconditionally support untyped pointers.

@fee1-dead
Copy link
Member Author

fee1-dead commented Jan 10, 2026

... Yeah, I did some testing today to see if I can get core to compile. After it did (it only compiles into rlib, so mostly fine), I tried this test:

pub enum A {
    Foo(u8),
    Bar(u32),
}

#[unsafe(no_mangle)]
pub fn test(x: &mut A) -> u8 {
    match x {
        A::Foo(x) => *x,
        A::Bar(b) => *b as u8 + 2,
    }
}

Which fails with:

Unimplemented implicit down-cast from load.
UNREACHABLE executed at src/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp:148!

Maybe LLVM could be updated in the future such that SPIRVLegalizePointerCast can do some transforms that make it work, but I suppose any built-in rustc spirv target will have to use the OpenCL SPIR-V, so spirv64-unknown-unknown, spirv32-unknown-unknown etc. I'll push my latest draft so anyone can have a look, though.

@rustbot rustbot added the A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) label Jan 10, 2026
@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)
Diff in /checkout/compiler/rustc_target/src/spec/targets/spirv_unknown_vulkan1_3.rs:1:
-use crate::spec::{
-    Arch, LinkerFlavor, Os, PanicStrategy, Target, TargetMetadata, TargetOptions
-};
+use crate::spec::{Arch, LinkerFlavor, Os, PanicStrategy, Target, TargetMetadata, TargetOptions};
 
 pub(crate) fn target() -> Target {
     Target {
Diff in /checkout/src/bootstrap/src/core/builder/cargo.rs:254:
     fn configure_linker(&mut self, builder: &Builder<'_>) -> &mut Cargo {
         let target = self.target;
         let compiler = self.compiler;
-        
+
         if target.contains("spirv") {
             return self;
         }
fmt: checked 6634 files
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:01:05

// Allow `cdylib` crate type.
dynamic_linking: true,
obj_is_bitcode: true,
only_cdylib: true,
Copy link
Member

Choose a reason for hiding this comment

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

I think this should also set is_like_gpu: true?

@ZuseZ4 ZuseZ4 mentioned this pull request Jan 12, 2026
5 tasks
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 15, 2026

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

@karolzwolak
Copy link
Member

any update @fee1-dead ? I'd like to build on this and add spirv64-intel variant

@fee1-dead
Copy link
Member Author

any update @fee1-dead ? I'd like to build on this and add spirv64-intel variant

Feel free to build on this. Vulkan support is probably borked until LLVM's legalization works. But then the openCL based stuff should work

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

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) 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. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

6 participants