Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo clif build does not work on Windows #1447

Open
luxalpa opened this issue Jan 9, 2024 · 12 comments
Open

cargo clif build does not work on Windows #1447

luxalpa opened this issue Jan 9, 2024 · 12 comments
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows upstream Caused by a dependency

Comments

@luxalpa
Copy link

luxalpa commented Jan 9, 2024

Setting up the tool like in the Readme, I am getting this error when running it as cargo clif build:

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=C:\dev\cranelift\bin\rustc_codegen_cranelift.dll --sysroot C:\dev\cranelift --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit code: 1)
  --- stderr
  error: couldn't load codegen backend "C:\\dev\\cranelift\\bin\\rustc_codegen_cranelift.dll": LoadLibraryExW failed

The problem doesn't appear when using cargo-clif directly, and it appears on both the msvc and the gnu versions of the latest release.

@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2024

C:\dev\cranelift\bin\rustc_codegen_cranelift.dll does exist, right? Unfortunately libloading (the crate rustc uses for dynamic linking) doesn't print the error returned by LoadLibraryExW and instead only prints a generic error message, making it hard for me to figure out what the issue is: nagisa/rust_libloading#133

@bjorn3 bjorn3 added C-bug Category: This is a bug. O-windows Operating system: Windows labels Jan 9, 2024
@luxalpa
Copy link
Author

luxalpa commented Jan 9, 2024

Yes, the file does exist and it seems to be working when using cargo-clif.exe directly (including when using it from path, i.e. from some other directory). I'm only getting the error when using it via cargo clif command.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 19, 2024
…use-somewhat, r=bjorn3

Format sources into the error message when loading codegen backends

cc rust-lang/rustc_codegen_cranelift#1447
cc `@bjorn3`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 20, 2024
Rollup merge of rust-lang#119815 - nagisa:nagisa/polishes-libloading-use-somewhat, r=bjorn3

Format sources into the error message when loading codegen backends

cc rust-lang/rustc_codegen_cranelift#1447
cc `@bjorn3`
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 21, 2024
…hat, r=bjorn3

Format sources into the error message when loading codegen backends

cc rust-lang/rustc_codegen_cranelift#1447
cc `@bjorn3`
bjorn3 pushed a commit that referenced this issue Jan 21, 2024
…hat, r=bjorn3

Format sources into the error message when loading codegen backends

cc #1447
cc `@bjorn3`
@bjorn3
Copy link
Member

bjorn3 commented Jan 21, 2024

Could you try again with the latest master version? This now includes rust-lang/rust#119815 which should give a more useful error message.

@luxalpa
Copy link
Author

luxalpa commented Jan 22, 2024

Thanks, I've figured out the issue. Cargo uses a different environment based on the toolchain of the project in which it is being run. If it doesn't match the one that's been used to build rustc_codegen_cranelift, it won't find the right versions of the .dlls. Running

rustup run nightly-2024-01-21-x86_64-pc-windows-msvc cargo clif build

in the project folder works.

Ironically, due to this, the recent change to the error formating didn't actually yield any difference in output. It was still using the older nightly version and so it was still only displaying "LoadLibraryExW failed" without any useful error message, which had confused me at first.

@bjorn3
Copy link
Member

bjorn3 commented Jan 22, 2024

That explains it. Does cargo clif -V show the nightly used by cg_clif or the default toolchain for your project?

@luxalpa
Copy link
Author

luxalpa commented Jan 22, 2024

It shows the default toolchain for the project (same as rustup shows active toolchain).

@bjorn3
Copy link
Member

bjorn3 commented Jan 26, 2024

I can't reproduce that. No matter what I try cargo clif -V shows the toolchain with which cg_clif was built. I tried both in a directory with a different toolchain in rust-toolchain.toml and one with an override set using rustup override set. cargo resolves to the rustup wrapper, right? Not the cargo of a specific toolchain.

@bjorn3
Copy link
Member

bjorn3 commented Feb 2, 2024

I think this is caused by some Windows specific behavior described in https://internals.rust-lang.org/t/help-test-windows-behavior-between-rustup-and-cargo/20237

Could you try setting the RUSTUP_WINDOWS_PATH_ADD_BIN env var to 0?

@luxalpa
Copy link
Author

luxalpa commented Feb 2, 2024

Yes, setting that environment variable makes cargo clif build work.

@bjorn3
Copy link
Member

bjorn3 commented Feb 2, 2024

Great! As I understand from the linked thread, that will be the default in the future.

@bjorn3
Copy link
Member

bjorn3 commented Mar 24, 2024

Rustup 1.27 was released just a couple of days before the default was flipped. So this will remain an issue until rustup 1.28 is released.

@bjorn3 bjorn3 added the upstream Caused by a dependency label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows upstream Caused by a dependency
Projects
None yet
Development

No branches or pull requests

3 participants