Skip to content

rustup run doesn't setup the dylib path on windows #4246

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
2 tasks done
Nadrieril opened this issue Mar 11, 2025 · 4 comments
Closed
2 tasks done

rustup run doesn't setup the dylib path on windows #4246

Nadrieril opened this issue Mar 11, 2025 · 4 comments
Labels

Comments

@Nadrieril
Copy link
Member

Nadrieril commented Mar 11, 2025

Verification

Problem

Hi! I am developping a rustc driver. I make sure to always call it as rustup run my-driver, which works on Mac and Linux: both the toolchain binaries and the rustc_driver.so are accessible so my program runs well. On Windows however, calling the driver fails with "rustc_driver.dll not found".

And indeed, as far as I can tell rustup run only attempts to set up loader paths on macos and linux:

fn set_ldpath(&self, cmd: &mut Command) {

I've seen related issues (#765, #932, #1152), but they're not exactly the same problem.

Steps

  1. Install the required rustup components: rustup component add --toolchain nightly rust-src rustc-dev llvm-tools-preview;
  2. Make a minimal binary crate that dynamically links to rustc-internal crates:
#![feature(rustc_private)]
extern crate rustc_driver;
fn main() {
    println!("Hello, World!");
}
  1. cargo +nightly build
  2. Run the resulting binary on Windows with rustup run nightly path\to\test-crate.exe

Possible Solution(s)

I can't test myself because I don't own a Windows machine, but a user reports that adding the lib 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 PATH (instead of LD_LIBRARY_PATH) works. This seems confirmed by a quick google search.

Notes

The reproducing details (OS version etc) are not precise because I'm reporting on behalf of a user. If you can't reproduce on your Windows machine I'll ask for more details.

Rustup version

rustup 1.27.1

Installed toolchains

nightly

OS version

Windows ???
@rami3l
Copy link
Member

rami3l commented Mar 11, 2025

@Nadrieril Thanks for your report.

You might need to set RUSTUP_WINDOWS_PATH_ADD_BIN=1 to make it work. If this is the case then this is a duplicate of #3825.

@zjp-CN
Copy link

zjp-CN commented Mar 12, 2025

Thanks for the link. RUSTUP_WINDOWS_PATH_ADD_BIN=1 solves the problem for now.

Also related to these links:

But I don't see why PATH can't be appended with libdir by rustup, saying adding C:\Users\Administrator\.rustup\toolchains\nightly-2024-10-23-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib to PATH.

I indeed noticed the RUSTUP_WINDOWS_PATH_ADD_BIN code and comment in rustup. At that time, I think it just adds a bin dir rather than lib dir, which wouldn't have helped.

Update: after scanning
C:\Users\Administrator\.rustup\toolchains\nightly-2024-10-23-x86_64-pc-windows-msvc\bin and
C:\Users\Administrator\.rustup\toolchains\nightly-2024-10-23-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib, it seems the latter contains more deps dlls which might cause troubles? Can rustup create a dir only containing rust dll libs, and add it to PATH?

Image

@rami3l
Copy link
Member

rami3l commented Mar 12, 2025

@zjp-CN Thanks for your feedback! Let's continue the discussion over there in the main issue then.

@Nadrieril
Copy link
Member Author

Oh amazing, I didn't expect this variable would work, glad it does.

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

No branches or pull requests

3 participants