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

bootstrap unable to copy rust-llvm-dwp when cross compiling rustc #85593

Open
jam1garner opened this issue May 22, 2021 · 3 comments
Open

bootstrap unable to copy rust-llvm-dwp when cross compiling rustc #85593

jam1garner opened this issue May 22, 2021 · 3 comments
Labels
A-cross Area: Cross compilation C-bug Category: This is a bug. O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@jam1garner
Copy link
Contributor

Similar to #85590, this is an issue with copying files when cross compiling (Linux -> Windows), however a bit more complicated so I didn't proceed with a fix (don't mind implementing one but would need guidance).

thread 'main' panicked at 'src.symlink_metadata() failed with No such file or directory (os error 2)', src/bootstrap/lib.rs:1196:24
stack backtrace:
   0: rust_begin_unwind
             at /rustc/215738137bcbef2c3637a5bd290ef612cffe6ba5/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/215738137bcbef2c3637a5bd290ef612cffe6ba5/library/std/src/panicking.rs:435:5
   2: bootstrap::Build::copy
             at ./src/bootstrap/lib.rs:1196:24
   3: <bootstrap::compile::Assemble as bootstrap::builder::Step>::run
             at ./src/bootstrap/compile.rs:1116:17
   4: bootstrap::builder::Builder::ensure
             at ./src/bootstrap/builder.rs:1518:23
   5: bootstrap::builder::Builder::compiler
             at ./src/bootstrap/builder.rs:585:9
   6: <bootstrap::tool::Rustdoc as bootstrap::builder::Step>::make_run
             at ./src/bootstrap/tool.rs:500:23
   7: bootstrap::builder::StepDescription::maybe_run
             at ./src/bootstrap/builder.rs:179:13
   8: bootstrap::builder::StepDescription::run
             at ./src/bootstrap/builder.rs:220:21
   9: bootstrap::builder::Builder::run_step_descriptions
             at ./src/bootstrap/builder.rs:577:9
  10: bootstrap::builder::Builder::execute_cli
             at ./src/bootstrap/builder.rs:569:9
  11: bootstrap::Build::build
             at ./src/bootstrap/lib.rs:510:13
  12: bootstrap::main
             at ./src/bootstrap/bin/main.rs:33:5
  13: core::ops::function::FnOnce::call_once
             at /rustc/215738137bcbef2c3637a5bd290ef612cffe6ba5/library/core/src/ops/function.rs:227:5

From adding debug prints it attempts to copy

.../rust/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-dwp.exe

to

.../rust/build/x86_64-pc-windows-gnu/stage2/lib/rustlib/x86_64-pc-windows-gnu/bin/rust-llvm-dwp.exe

Looking at the Relevant code it appears to be running llvm-config from the host in order to find the copy of llvm-dwp to copy, however when cross compiling you can't just copy over the host's llvm-dwp. This results in an error due to the fact it does properly respect the exe suffix, which means the file won't exist when cross compiling as llvm-dwp.exe won't exist in the host copy of llvm's bin directory.

@jam1garner
Copy link
Contributor Author

A potential fix could look something like this:

if builder.config.rust_codegen_backends.contains(&INTERNER.intern_str("llvm")) {
    let src_exe = exe("llvm-dwp", target_compiler.host);
    let dst_exe = exe("rust-llvm-dwp", target_compiler.host);
    let llvm_config_bin = builder.ensure(native::Llvm { target: target_compiler.host });
    if !builder.config.dry_run {
        if target_compiler.host == build_compiler.host {
            let llvm_bin_dir = output(Command::new(llvm_config_bin).arg("--bindir"));
            let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
            builder.copy(&llvm_bin_dir.join(&src_exe), &libdir_bin.join(&dst_exe));
        } else {
            let llvm_bin_dir = format!("build/{}/llvm/build/bin", target_compiler.host);
            let llvm_bin_dir = Path::new(&llvm_bin_dir);
            builder.copy(&llvm_bin_dir.join(&src_exe), &libdir_bin.join(&dst_exe));
        }
    }
}

however, notably, I don't think format! is the proper way to do the above, I'd appreciate guidance on the best way to "properly" get the expected llvm build directory given the target triple.

(Note that the above is tested and appears to work, just isn't the best way to do it and I imagine breaks under some configuration of LLVM/config.toml/etc)

@jyn514 jyn514 added A-cross Area: Cross compilation T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. O-windows Operating system: Windows labels May 23, 2021
@jyn514
Copy link
Member

jyn514 commented Nov 26, 2021

@jam1garner do you want to make a PR with that fix? :) I think as long as it passes in CI it's no worse than the existing situation, and it sounds like it's fixed your problem.

@jam1garner
Copy link
Contributor Author

I'll try and put together a PR, been a while though so I'll need to refamiliarize myself first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross Area: Cross compilation C-bug Category: This is a bug. O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants