Compiling rustc with only the cranelift backend

According to bjorn3's article from a couple of years ago, this used to work. However, if you try compiling rustc with the following bootstrap.toml right now it fails to compile stage0 library artifacts. I saw this issue mentioned in a random rust PR but it seems like no one ever found a solution. Any ideas? I could also bring this up on GitHub if needed.

[build]
full-bootstrap = true

[rust]
codegen-backends = ["cranelift"]
python3 x.py build --stage 2
Building stage1 library artifacts (x86_64-unknown-linux-gnu)
   Compiling compiler_builtins v0.1.158
   Compiling core v0.0.0 (/root/rust/library/core)
   Compiling libc v0.2.172
   Compiling object v0.36.7
   Compiling std v0.0.0 (/root/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/root/rust/library/rustc-std-workspace-core)
error: unsupported builtin codegen backend `llvm`

error: unsupported builtin codegen backend `llvm`

error: unsupported builtin codegen backend `llvm`

error: unsupported builtin codegen backend `llvm`

error: unsupported builtin codegen backend `llvm`

error: unsupported builtin codegen backend `llvm`

   Compiling alloc v0.0.0 (/root/rust/library/alloc)
error: Failed to assemble `.globl __inline_asm_compiler_builtins__49d4216c53098d11_cgu__002_n0
       .type __inline_asm_compiler_builtins__49d4216c53098d11_cgu__002_n0,@function
       .section .text.__inline_asm_compiler_builtins__49d4216c53098d11_cgu__002_n0,"ax",@progbits
       __inline_asm_compiler_builtins__49d4216c53098d11_cgu__002_n0:
       .intel_syntax noprefix
           push rbp
           mov rbp,rsp
           push rbx
           mov rbx,rdi
           movups xmm0, [rbx+0x0]
           movups xmm1, [rbx+0x10]
           movups xmm2, [rbx+0x20]
       vfmadd213sd xmm0, xmm1, xmm2
           movups [rbx+0x0], xmm0
           pop rbx
           pop rbp
           ret
       .att_syntax
       .size __inline_asm_compiler_builtins__49d4216c53098d11_cgu__002_n0, .-__inline_asm_compiler_builtins__49d4216c53098d11_cgu__002_n0
       .text
.......

Try setting CG_CLIF_FORCE_GNU_AS=1 and make sure to install the gnu assembler (gas). This will cause cg_clif to use gas as assembler for inline asm rather than trying to use the LLVM backend for this.

In any case be aware that cg_clif produces much slower executables, so you are probably looking at at least a couple hours worth of compile time if you let the cg_clif built rustc (stage1) build rustc again (stage2).

cg_clif's CI only tests that stage1 is capable of building the standard library: rustc_codegen_cranelift/scripts/test_bootstrap.sh at master · rust-lang/rustc_codegen_cranelift · GitHub

1 Like