Skip to content

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

Closed as duplicate

Description

@Nadrieril

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 ???

Activity

  1. rami3l commented on Mar 11, 2025

    @rami3l
    Member

    @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.

  2. zjp-CN commented on Mar 12, 2025

    @zjp-CN

    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

  3. rami3l commented on Mar 12, 2025

    @rami3l
    Member

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

  4. Nadrieril commented on Mar 12, 2025

    @Nadrieril
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions