Skip to content

dynamic librustc_driver path is not set by charon #588

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

Closed
zjp-CN opened this issue Mar 10, 2025 · 10 comments · Fixed by #598
Closed

dynamic librustc_driver path is not set by charon #588

zjp-CN opened this issue Mar 10, 2025 · 10 comments · Fixed by #598

Comments

@zjp-CN
Copy link
Contributor

zjp-CN commented Mar 10, 2025

Personally speaking, the dynamic linked librustc_driver path should be always set before calling charon, otherwise there will be a loading problem.

I didn't find any issue reporting this. So this is a record for anyone who comes across the problem the first time.

On Linux, LD_LIBRARY_PATH should be set to the specified toolchain lib path:

# Ignore the inconsistent toolchains on Linux and Windows
$ rustup default nightly-2024-08-11
info: using existing install for 'nightly-2024-08-11-x86_64-unknown-linux-gnu'
info: default toolchain set to 'nightly-2024-08-11-x86_64-unknown-linux-gnu'

  nightly-2024-08-11-x86_64-unknown-linux-gnu unchanged - rustc 1.82.0-nightly (730d5d409 2024-08-10)


$ charon-driver rustc -vV
charon-driver: error while loading shared libraries: librustc_driver-9694e87df53074e6.so: cannot open shared object file: No such file or directory

$ export LD_LIBRARY_PATH=/root/.rustup/toolchains/nightly-2024-08-11-x86_64-unknown-linux-gnu/lib

$ charon-driver rustc -vV
rustc 1.82.0-nightly (730d5d409 2024-08-10)
binary: rustc
commit-hash: 730d5d4095a264ef5f7c0a0781eea68c15431d45
commit-date: 2024-08-10
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

On Windows, you'll get a windows popup saying dll is not found or something, or get a painic error from CLI indicating stdout and stderr are empty strings:

charon\charon $ target\debug\charon --print-llbc --input tests\ui\arrays.rs --no-cargo
The required toolchain is not installed. Installing...
info: syncing channel updates for 'nightly-2024-10-23-x86_64-pc-windows-msvc'

  nightly-2024-10-23-x86_64-pc-windows-msvc unchanged - rustc 1.84.0-nightly (86d69c705 2024-10-22)

thread 'main' panicked at src/bin/charon/main.rs:174:13:
info: checking for self-update
info: component 'rustc-dev' for target 'x86_64-pc-windows-msvc' is up to date
info: component 'llvm-tools' for target 'x86_64-pc-windows-msvc' is up to date
thread 'main' panicked at src/bin/charon/main.rs:174:13:
failed to determine underlying rustc version of Charon:
CommandError { stdout: "", stderr: "" }

So the solution is adding the toolchain path, e.g. C:\Users\Administrator\.rustup\toolchains\nightly-2024-10-23-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib, to system environment variable PATH, and restart the terminal to make it work.

@Nadrieril
Copy link
Member

Nadrieril commented Mar 10, 2025

This is a bug that should be fixed. On Linux and Mac, charon does always set up the toolchain path before calling the driver. You should never have to set it up yourself. Could you tell me how to set it up on Windows?

@Nadrieril
Copy link
Member

I use rustup run <toolchain> charon-driver which should normally add the right paths. If that's not working I don't know how to do it properly. Can you check if rustup run nightly-2024-10-23 path\to\charon-driver works on windows?

@Nadrieril
Copy link
Member

Also, have you encountered this bug on Linux? I would like to know what your setup is because that's also a bug that should be fixed.

@zjp-CN
Copy link
Contributor Author

zjp-CN commented Mar 11, 2025

Based on the de91049 , I still got the dll loading error with rustup run nightly-2024-10-23 charon-driver on Windows

Image

Sorry, it's Chinese; it basically says rustc_driver dll is not found. The solution I can confirm is

adding the toolchain path, e.g. C:\Users\Administrator\.rustup\toolchains\nightly-2024-10-23-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib, to system environment variable PATH, and restarting the terminal to make it work.


On Linux and Mac, charon does always set up the toolchain path before calling the driver. You should never have to set it up yourself.

Oh, it works on Linux! I mean

  • rustup run nightly-2024-10-23 target/debug/charon-driver rustc -vV prints stuff correctly
  • target/debug/charon --no-cargo --input tests/ui/arrays.rs --print-ullbc --rustc-flag=--crate-type=rlib prints stuff correctly

I didn't realize rustup run sets up toolchain path. So there's no problem on Linux now.

@zjp-CN
Copy link
Contributor Author

zjp-CN commented Mar 11, 2025

It's weird. rustup run nightly-2024-10-23 rustc -vV works fine on Windows:

$ rustup run nightly-2024-10-23 rustc -vV
rustc 1.84.0-nightly (86d69c705 2024-10-22)
binary: rustc
commit-hash: 86d69c705a552236a622eee3fdea94bf13c5f102
commit-date: 2024-10-22
host: x86_64-pc-windows-msvc
release: 1.84.0-nightly
LLVM version: 19.1.1

But rustup run nightly-2024-10-23 target\debug\charon-driver.exe rustc -vV doesn't. Maybe this is a rustup bug? (Yes :)

Update: I think there is a bug from charon-driver rustup. On Windows, I made a test for rustup:

fn main() {
    let args: Vec<_> = std::env::args().collect();
    dbg!(&args);
    let output = std::process::Command::new("rustc")
        .args(args)
        .output()
        .unwrap();
    let stdout = std::str::from_utf8(&output.stdout).unwrap();
    let stderr = std::str::from_utf8(&output.stderr).unwrap();
    println!("stdout = {stdout}\ntderr = {stderr}");
}

rustup run succeeds in forwarding -vV to rustc

$ rustup run nightly-2024-10-23 target\debug\test-rustup.exe -vV
[src\main.rs:3:5] &args = [
    "target\\debug\\test-rustup.exe",
    "-vV",
]
stdout = rustc 1.84.0-nightly (86d69c705 2024-10-22)
binary: rustc
commit-hash: 86d69c705a552236a622eee3fdea94bf13c5f102
commit-date: 2024-10-22
host: x86_64-pc-windows-msvc
release: 1.84.0-nightly
LLVM version: 19.1.1

tderr =

@zjp-CN

This comment has been minimized.

@Nadrieril
Copy link
Member

Nadrieril commented Mar 11, 2025

So far this is consistent with my understanding: the issue is that charon-driver.exe dynamically links to rustc_driver.dll. rustc itself doesn't need that, which is why it runs correctly.

It seems that rustup run correctly sets up binary discovery (so rustc is found), but not dll discovery. I don't think there's anything that charon-driver.exe can do because this dynamic linking is done by the OS when we ask to run charon_driver.exe.

It seems that rustup doesn't even try to set up the right loader paths on windows: https://github.com/rust-lang/rustup/blob/895a43a3e2d942c5bb93b7b1c77c0ad9a0df95d6/src/toolchain.rs#L178

@Nadrieril
Copy link
Member

Nadrieril commented Mar 11, 2025

I'll open a rustup issue. I don't have a Windows machine: could you confirm that the same problem happens if instead of charon-driver you try to rustup run just a tiny crate that contains:

#![feature(rustc_private)]
extern crate rustc_driver;
fn main() {
    println!("Hello, World!");
}

?

@zjp-CN
Copy link
Contributor Author

zjp-CN commented Mar 11, 2025

could you confirm that the same problem happens

Yay, I can confirm the dll loading problem happens!

Image

BTW I also noticed the rustup code you linked in the day, and suspect on Windows the loading path should be PATH instead of LD_LIBRARY_PATH :)

@Nadrieril
Copy link
Member

Nice, I've opened an issue: rust-lang/rustup#4246.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants