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

std not found when trying to cross-compile tools #85320

Closed
infinity0 opened this issue May 15, 2021 · 3 comments · Fixed by #85518
Closed

std not found when trying to cross-compile tools #85320

infinity0 opened this issue May 15, 2021 · 3 comments · Fixed by #85518

Comments

@infinity0
Copy link
Contributor

infinity0 commented May 15, 2021

We are adding rustfmt and clippy to the Debian package. Previously, with just rustc without these tools, cross-compiling works fine. When adding tools however, the cross-compile of these tools fails.

For example cross-compiling from x86_64 to armv5te:

[..]
        < Rustc { target: TargetSelection { triple: "armv5te-unknown-linux-gnueabi", file: None }, compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } } }
        c Libdir { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } }, target: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } }
        c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } } }
        c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } } }
        c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } } }
        c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } } }
        c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-unknown-linux-gnu", file: None } } }
        c Llvm { target: TargetSelection { triple: "armv5te-unknown-linux-gnueabi", file: None } }
Building stage2 tool rustfmt (armv5te-unknown-linux-gnueabi)
running: "/usr/bin/cargo" "build" "--target" "armv5te-unknown-linux-gnueabi" "-Zdual-proc-macros" "-Zbinary-dep-depinfo" "-j" "4" "-v" "-v" "--release" "--manifest-path" "/<<PKGBUILDDIR>>/src/tools/rustfmt/Cargo.toml" "--message-format" "json-render-diagnostics"
   Compiling proc-macro2 v1.0.24
     Running `CARGO=/usr/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/<<PKGBUILDDIR>>/vendor/proc-macro2 CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>:David Tolnay <dtolnay@gmail.com>' CARGO_PKG_DESCRIPTION='A substitute implementation of the compiler'\''s `proc_macro` API to decouple
token-based libraries from the procedural macro use case.
' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=proc-macro2 CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION=1.0.24 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=24 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps:/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2/lib' /<<PKGBUILDDIR>>/build/bootstrap/debug/rustc --crate-name build_script_build --edition=2018 /<<PKGBUILDDIR>>/vendor/proc-macro2/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=513cd11018457a4d -C extra-filename=-513cd11018457a4d --out-dir /<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2-tools/release/build/proc-macro2-513cd11018457a4d -L dependency=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps --cap-lints warn -Zbinary-dep-depinfo`
[..]
error[E0463]: can't find crate for `std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`


Did not run successfully: exit code: 1
"/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--crate-name" "build_script_build" "--edition=2018" "/<<PKGBUILDDIR>>/vendor/proc-macro2/build.rs" "--error-format=json" "--json=diagnostic-rendered-ansi" "--crate-type" "bin" "--emit=dep-info,link" "-C" "opt-level=3" "-Cembed-bitcode=no" "-C" "debuginfo=2" "--cfg" "feature=\"default\"" "--cfg" "feature=\"proc-macro\"" "-C" "metadata=513cd11018457a4d" "-C" "extra-filename=-513cd11018457a4d" "--out-dir" "/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2-tools/release/build/proc-macro2-513cd11018457a4d" "-L" "dependency=/<<PKGBUILDDIR>>/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--cap-lints" "warn" "-Zbinary-dep-depinfo" "-Clinker=x86_64-linux-gnu-gcc" "--remap-path-prefix" "/<<PKGBUILDDIR>>=/usr/src/rustc-1.52.1"
@infinity0
Copy link
Contributor Author

std is actually already built for the target architecture, the build still fails if i build it explicitly beforehand. It would seem that the correct paths are not being passed to the cross-compile of the tool.

@infinity0
Copy link
Contributor Author

It's a bit weird that bootstrap says running: "/usr/bin/cargo" "build" "--target" "armv5te-unknown-linux-gnueabi" [..] but the cargo verbose output doesn't mention armv5te anywhere and only contains x86_64 paths.

@infinity0
Copy link
Contributor Author

Oh, probably cargo is trying to build the dependencies of the build-scripts on the host platform, that's why --target is not being given. I am testing this diff:

diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index 3fc3b68fd..2622b0785 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -52,7 +52,10 @@ impl Step for ToolBuild {
         let is_optional_tool = self.is_optional_tool;
 
         match self.mode {
-            Mode::ToolRustc => builder.ensure(compile::Rustc { compiler, target }),
+            Mode::ToolRustc => {
+                builder.ensure(compile::Std { compiler, target: compiler.host });
+                builder.ensure(compile::Rustc { compiler, target });
+            },
             Mode::ToolStd => builder.ensure(compile::Std { compiler, target }),
             Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
             _ => panic!("unexpected Mode for tool build"),

to see if it fixes the problem.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 20, 2021
…r=Mark-Simulacrum

bootstrap: ensure host std when cross-compiling tools, fixes rust-lang#85320
bors added a commit to rust-lang-ci/rust that referenced this issue May 20, 2021
…laumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#85275 (Move `std::memchr` to `sys_common`)
 - rust-lang#85326 (bootstrap: ensure host std when cross-compiling tools, fixes rust-lang#85320)
 - rust-lang#85375 (Fix missing lifetimes diagnostics after rust-lang#83759)
 - rust-lang#85507 (Extend escape key check)
 - rust-lang#85509 (Prevent tab title to "null" if the URL is a search one)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 9719031 May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant