Description
Following the instructions in the README, everything seemed to be working fine until ./y.rs build
.
The MSVC toolchain is not yet supported by rustc_codegen_cranelift.
Switch to the MinGW toolchain for Windows support.
Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to
set the global default target to MinGW
Ok, fair enough. Compatibility layer time!
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
|
= note: "x86_64-w64-mingw32-gcc" "-Wl,C:\\Users\\{redacted}\\AppData\\Local\\Temp\\rustczVob4a\\list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va"
// lots and lots of paths
= note: ld: cannot find -lcfgmgr32
warning: `rustc_codegen_cranelift` (lib) generated 1 warning
error: could not compile `rustc_codegen_cranelift` due to previous error; 1 warning emitted
Hmm, dang it. I can't seem to find helpful references to -lcfgmgr32
online. It sounds like mingw can't find the library it needs for cfgmgr32.dll
. I tried reinstalling my mingw header package with pacman
to no avail. I found out, as I understand it, that the x86_64-pc-windows-gnu
toolchain uses a bundled mingw in a rust-mingw
component, so my existing installation shouldn't matter anyway. What if I copy libcfgmgr32.a
from my local mingw into the "lib" folder of the cargo source for the winapi
it's referencing (that doesn't sound like the best idea...)? Huh, that... fixes it?
But now there's a new problem:
C:\Users\{redacted}\rustc_codegen_cranelift\build_sysroot\target\x86_64-pc-windows-gnu\release\deps\std-f372f6b22d805bdf.std.53bbqtws-cgu.0.rcgu.o:std.53bbqtws-cgu.0:(.debug_info+0x40): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.debug_str'
and other variations on that theme until
C:\Users\{redacted}\rustc_codegen_cranelift\build_sysroot\target\x86_64-pc-windows-gnu\release\deps\std-f372f6b22d805bdf.std.53bbqtws-cgu.0.rcgu.o:std.53bbqtws-cgu.0:(.debug_info+0x56): additional relocation overflows omitted from the output
collect2.exe: error: ld returned 1 exit status
I found this (https://github.com/bjorn3/rustc_codegen_cranelift/issues/977#issuecomment-830650448), which seems to be related, except I'm not using MSVC. (How do I disable DWARF debuginfo?) Based on that comment/thread, I tried to comment out the bit in y.rs
that blows up on MSVC, just for laughs. No luck; not yet implemented: Unimplemented TLS model in x64 backend: Coff
Yep, that's what the July report said, and it seems to still be the case. From what I can gather, the ADDR32
bit of it has something to do with jumps into relocatable code being too large to fit in a 32-bit pointer. I can confirm that my installed gnu
toolchain compiles other crates successfully (I have nothing nearly as large as a sysroot, though).
I played around with a bunch of RUSTFLAGS
combination (both to rustc
and passthrough to gcc
codegen/linking) based on tangential information (very little info on IMAGE_REL_AMD64_ADDR32
specifically) to no avail. It's possible that this is an effective direction, and I just don't know enough about gcc
to make it work. It seems odd to me though, because there's no mention (that I could find) of special compiler args being necessary.
I tried a few scattershot previous commits, before and after the transition to a Rust-based build system. Same problem.
I tried cross-compiling with Ubuntu on WSL2. No luck:
❯ ./y.rs build
[BUILD] y.rs
info: syncing channel updates for 'nightly-2021-08-07-x86_64-pc-windows-gnu'
info: latest update on 2021-08-07, rust version 1.56.0-nightly (5ad7389bd 2021-08-06)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'llvm-tools-preview'
info: downloading component 'rust-docs'
info: downloading component 'rust-mingw'
info: downloading component 'rust-src'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustc-dev'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'llvm-tools-preview'
info: installing component 'rust-docs'
info: installing component 'rust-mingw'
info: installing component 'rust-src'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustc-dev'
info: installing component 'rustfmt'
error: the 'rustc' binary, normally provided by the 'rustc' component, is not applicable to the 'nightly-2021-08-07-x86_64-pc-windows-gnu' toolchain
What are you talking about? It says info: downloading component 'rustc'
and then info: installing component 'rustc'
RIGHT THERE. I have no idea what's going on, as I typically don't mess with nightly/betas.
I gave up on trying to compile from source and checked out the GHA artifacts. Looks like the uploading artifacts from the windows CI build is disabled? https://github.com/bjorn3/rustc_codegen_cranelift/blob/d498e6d6971575714353f11aa4d3e63a9d2030b2/.github/workflows/main.yml#L155-L162
Oh well, cross-x86_64-mingw
sounds promising.
$ ./cargo
bash: ./cargo: cannot execute binary file: Exec format error
Dang it.
$ file cargo
cargo: ELF 64-bit LSB shared object x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=b8e72eb3363cc311d848656c88fa225cbaf411a7, for GNU/Linux 3.2.0, with debug_info, not stripped
Well, that definitely doesn't sound right.
./y.rs build --sysroot none
did compile, although it (understandably) does nothing and hangs forever when invoked. However:
$ file build/cargo
build/cargo: PE32+ executable (console) x86-64, for MS Windows
Unless I'm doing something wrong (quite possible), it seems that the cross-compile CI target isn't measuring what it's supposed to be measuring (successfully producing a Windows-runnable artifact from Linux).
TWIR sent me here. I've been following this on-and-off for a while, and it's really awesome to see how close it is to basically-feature-complete. I wanted to get in on it (faster debug builds? Yes please!), but I've tried as hard as I can on my own.
Activity
EndilWayfare commentedon Aug 14, 2021
Ayyyy, got it to work.
TL;DR: Compiling on Windows == still broken for me. Cross-compiling from Linux works if 1) target/host overrides are set correctly and 2) you make sure
target_triple
is propagated to compiling the cargo wrapper.Cross-compiling from WSL wasn't working because somehow in all my faffing about I overrode the default host triple in addition to the default target. Oof. So, it compiled then, but the resulting
cargo
failed in Windows with the same error (andfile
output) as the GHA artifact did. After digging around in the source code a bit, since the problem seemed to hinge on thecargo
binary, I decided to try altering this:https://github.com/bjorn3/rustc_codegen_cranelift/blob/d498e6d6971575714353f11aa4d3e63a9d2030b2/build_system/build_sysroot.rs#L46-L53
to this:
, to match https://github.com/bjorn3/rustc_codegen_cranelift/blob/d498e6d6971575714353f11aa4d3e63a9d2030b2/build_system/build_sysroot.rs#L179-L181
That would also explain why CI doesn't appear to be producing a viable cross-compiled artifact!
EndilWayfare commentedon Aug 14, 2021
Dammit, just kidding. That was my system
cargo.exe
, not./build/cargo.exe
. The new cross-compiledcargo
hangs forever like the./y.rs build --sysroot none
version...bjorn3 commentedon Aug 14, 2021
I have never actually tried to cross-compile cg_clif itself for windows. CI tests compiling cg_clif on windows using the mingw toolchain and it tests compiling programs using cg_clif for windows using the mingw toolchain.
Maybe removing https://github.com/bjorn3/rustc_codegen_cranelift/blob/d498e6d6971575714353f11aa4d3e63a9d2030b2/build_sysroot/Cargo.toml#L23 helps?
EndilWayfare commentedon Aug 14, 2021
Yeah, I figured that out yesterday, I just ran out of time trying weird combinations of compiling different bits on Windows and WSL to post about it. I was like, OOOOOH got it, the host/target are operating on a different layer of indirection than I assumed. It's not that the codegen is cross-compiled to run on windows, it's that the codegen does cross-compilation (running on Linux, producing cranelift debug builds that run on windows). That's awesome, but I don't feel like doubling up on dependency sources/build-artifacts between WSL and Windows...
EndilWayfare commentedon Aug 14, 2021
Ahhhh, the
Cargo.toml
in "build_sysroot", ok. I messed around with the root one, but I missed that there was another. Well, it helps a little, in the sense that it actually compiles successfully. But, it also doesn't because the resulting "cargo.exe" hangs indefinitely still.EndilWayfare commentedon Aug 14, 2021
While I'm at it, is there a reason that the
windows
CI target is disabled from uploading its artifacts? Later today, I might get a chance to try compiling on a fresher, less battle-worn Windows dev environment and we'll see if that changes anything.bjorn3 commentedon Aug 14, 2021
I can't remember. Maybe a leftover from trying to set up windows ci?
EndilWayfare commentedon Aug 15, 2021
Ok, I decided to let
cargo.exe
sit there for a while and find out if it ever actually does anything. It does. It allocates a lot of memory until it gets OOM'd.Huh. Ok, once more with


RUST_BACKTRACE=1
. While we're waiting for it to explode, let's pull up Task Manager and see if that tells us anything.Hmmm,
cargo.exe
is... multiplying? Those are all subprocesses under the terminal emulator that initially invokedcargo.exe
...!?
It caps out at over 9,000 [yes, really] subprocesses consuming 19 GB of RAM before it goes down.
Interestingly, it doesn't actually give me a backtrace. It just goes
It seems to slowly unwind the subprocesses after it prints the failure message, and it doesn't "return" to the shell prompt until all the subprocesses are gone.
EndilWayfare commentedon Aug 15, 2021
oooooh, could that be a side-effect of
debug = true
?EndilWayfare commentedon Aug 15, 2021
It's also very probable that the windows CI build suffers from the same issue. The action only tests whether it compiles;
test.sh
isn't run, because windows.I tried running
test.sh
locally with my MinGWbash
, and it exploded. First, I had to add "./build/bin" and "/c/Users/{user}/.rustup/toolchains/nightly-2021-08-07-x86_64-pc-windows-gnu/bin" to$PATH
, because otherwise windows can't find the .dll's. Then,[BUILD] mini_core
failed with the samerelocation truncated to fit: IMAGE_REL_AMD64_ADDR32
nonsense, so I added-C debuginfo=0
to the line in "scripts/tests.sh". Nowmini_core
gets intorustc
proper, but it ICEs on an unresolved symbol.Sounds suspiciously like https://github.com/bjorn3/rustc_codegen_cranelift/issues/1137?
bjorn3 commentedon Aug 15, 2021
I see what is going on. On Unix systems the directory containing the current executabe is not in
PATH
, so trying to spawn "cargo" will attempt to run the original cargo. On windows it is inPATH
, so it will attempt to run the wrapper itself.https://github.com/bjorn3/rustc_codegen_cranelift/blob/d498e6d6971575714353f11aa4d3e63a9d2030b2/scripts/cargo.rs#L76
bjorn3 commentedon Aug 15, 2021
Looks like the jit tests don't work. Could you try if disabling those tests will make the rest of the tests pass?
Todo:
EndilWayfare commentedon Aug 15, 2021
Confirmed. Renaming from
cargo.exe
tocargo-clif.exe
works. It successfully substitutes forcargo
to build another crate, except I have to setRUSTFLAGS="-C debuginfo=0"
orIMAGE_REL_AMD64_ADDR32
happens.EndilWayfare commentedon Aug 15, 2021
It looks like disabling jit tests and tests that invoke
cargo
works, and the other tests succeed. I say "looks", because I haven't gotten to the end of "tests.sh" with modification yet. It's a lot harder to kill the runaway-process phenomenon when it's a binary invoking cargo rather thanbash
invoking cargo; it's enough to SIGINT inbash
, but you kind of have to wait for OOM in the other case because Task Manager gets overwhelmed and unusable.EndilWayfare commentedon Aug 15, 2021
base_sysroot_tests
completes successfully, under above caveats9 remaining items
EndilWayfare commentedon Aug 31, 2021
Hmm, noticing some interesting things with
cargo test
Only one error, but all tests fail on
cargo-clif
Fixed the failing test, all tests still fail on
cargo-clif
.EndilWayfare commentedon Aug 31, 2021
On a lark, specifying the gnu toolchain doesn't help. It's worse 🤣
EndilWayfare commentedon Aug 31, 2021
Don't know how to determine if it can't find a clif .dll, a gnu toolchain .dll, or some other .dll entirely...
prantor19 commentedon Aug 31, 2021
bjorn3 commentedon Aug 31, 2021
What project are those failing tests on? They are probably a problem with cg_clif independent of the windows support.
bjorn3 commentedon Aug 31, 2021
I think you need to build cg_clif with the gnu toolchain too then. cg_clif needs to be built with the exact same compiler as which it will be loaded into.
EndilWayfare commentedon Aug 31, 2021
I'm 98% sure that version of
cargo-clif
was build with gnu. I'll double check, though...EndilWayfare commentedon Aug 31, 2021
Actually wait, doesn't this project force a pinned nightly toolchain? Because I only have that one installed in gnu flavor.
EndilWayfare commentedon Aug 31, 2021
Those failing tests are from one of my own projects. I was checking if cg_clif could help with test compile times.
bjorn3 commentedon Sep 1, 2022
I believe this should work fine now given recent improvements. There is still a case where it can crash on windows though which will be fixed by bytecodealliance/wasmtime#4747.
bjorn3 commentedon Sep 27, 2022
https://github.com/bjorn3/rustc_codegen_cranelift/pull/1284 has added actual native Windows testing to the CI. @EndilWayfare does it work for you now?
bjorn3 commentedon Dec 15, 2022
Closing. If you still have problems please open a new issue.