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

Rust compiler does not build on Raspbian Linux (Raspberry Pi 4) #72473

Closed
urbas opened this issue Nov 1, 2019 · 4 comments
Closed

Rust compiler does not build on Raspbian Linux (Raspberry Pi 4) #72473

urbas opened this issue Nov 1, 2019 · 4 comments
Labels
0.kind: bug Something is broken 6.topic: rust

Comments

@urbas
Copy link
Contributor

urbas commented Nov 1, 2019

Describe the bug
Building rustc on Raspbian linux (on a Raspberry Pi 4) fails with the following error message:

# Executed on Raspberry Pi 4, Raspbian, 4.19.66-v7l+ #1253 SMP Thu Aug 15 12:02:08 BST 2019 armv7l GNU/Linux
% git checkout f81600619171febcee723db6796d0045552a660f && nix-build . -aV pkgs.rustc

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/build/rustc-1.38.0-src/build/bootstrap/debug/rustc - --crate-name ___ --print=file-names -Ccodegen-units=10 --target armv7l-unknown-linux-gnueabihf --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: Error loading target specification: Could not find specification for target "armv7l-unknown-linux-gnueabihf"
  |
  = help: Use `--print target-list` for a list of built-in targets


command did not execute successfully: "/nix/store/3azy4bjmgfxi67xmziqrpsp2q7nqrv84-cargo-bootstrap-1.37.0/bin/cargo" "build" "--target" "armv7l-unknown-linux-gnueabihf" "-j" "4" "--release" "--frozen" "--features" "panic-unwind backtrace profiler compiler-builtins-c" "--manifest-path" "/build/rustc-1.38.0-src/src/libstd/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101

Note that I also had to disable the m_hugefile test in e2fsprogs because it was failing (as a dependency of the pkgs.fd package, which is written in Rust).

To Reproduce
Steps to reproduce the behavior:

  1. Find a Raspberry Pi 4 with Raspbian 10 (4.19.66-v7l+ rubylibs: add several expressions #1253 SMP Thu Aug 15 12:02:08 BST 2019 armv7l GNU/Linux)
  2. Checkout nixpkgs on a recent commit SHA (I used f81600619171febcee723db6796d0045552a660f)
  3. Disable the m_hugefile test in e2fsprogs package (it's consistently failing on ARMv7v Raspbian)
  4. Run nix-build . -aV pkgs.rustc

Expected behavior
The Rust compiler should have been built and .result/bin/rustc should execute without problems.

Screenshots
Not applicable.

Additional context
It looks like Nix's platform string armv7l-unknown-linux-gnueabihf is passed directly to rustc. Unfortunately, rustc doesn't know about armv7l. However, it turns out rustc accepts the following ARMv7 target strings:

  • armv7-linux-androideabi
  • armv7-unknown-cloudabi-eabihf
  • armv7-unknown-freebsd
  • armv7-unknown-linux-gnueabi
  • armv7-unknown-linux-gnueabihf
  • armv7-unknown-linux-musleabi
  • armv7-unknown-linux-musleabihf
  • armv7-unknown-netbsd-eabihf
  • armv7-wrs-vxworks
  • armv7r-none-eabi
  • armv7r-none-eabihf

After a bit of testing, I discovered that rustc compiles successfully if we transform Nix's platform string from armv7l-* to armv7-*.

Metadata

  • system: "armv7l-linux"
  • host os: Linux 4.19.66-v7l+, Raspbian GNU/Linux, 10 (buster)
  • multi-user?: no
  • sandbox: yes
  • version: nix-env (Nix) 2.3.1
  • channels(mat): "nixpkgs-20.03pre197736.91d5b3f07d2"
  • nixpkgs: /home/pi/programming/nixpkgs

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
  - rustc
# a list of nixos modules affected by the problem
module: []
@urbas urbas added the 0.kind: bug Something is broken label Nov 1, 2019
@matthewbauer
Copy link
Member

armv7l is a Debianism that we've adopted. But "armv7" and "armv7l" are identical so it shouldn't be an issue. Rust should pick this up from LLVM which recognizes both.

Adding another check here should fix the issue:

https://github.com/matthewbauer/nixpkgs/blob/static-nix/pkgs/build-support/rust/build-rust-crate/build-crate.nix#L20

@urbas
Copy link
Contributor Author

urbas commented Nov 2, 2019

armv7l is a Debianism that we've adopted. But "armv7" and "armv7l" are identical so it shouldn't be an issue. Rust should pick this up from LLVM which recognizes both.

Adding another check here should fix the issue:

https://github.com/matthewbauer/nixpkgs/blob/static-nix/pkgs/build-support/rust/build-rust-crate/build-crate.nix#L20

I tried building with this change and it still failed with the same error message (while building the same package):

diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix
index e0a52e62561..b3e59bde767 100644
--- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix
+++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix
@@ -17,7 +17,7 @@
     # Some platforms have different names for rustc.
     rustPlatform =
       with stdenv.hostPlatform.parsed;
-      let cpu_ = if cpu.name == "armv7a" then "armv7"
+      let cpu_ = if cpu.name == "armv7a" || cpu.name == "armv7l" then "armv7"
                  else cpu.name;
           vendor_ = vendor.name;
           kernel_ = kernel.name;

I had to change --target parameters in other places too (see PR #72480).

urbas added a commit to urbas/nixpkgs that referenced this issue Nov 15, 2019
Addresses issue NixOS#72473

`rustc` and Rust packages would not compile on Raspbian on a Raspberry Pi. It turns out that Rust's ARMv7 targets are slightly different from Nix's.

This change adds a function that maps `armv7a` and `armv7l` architectures to `armv7`. The former are used in Raspbian on Raspberry Pi but are unknown to rustc. Rust knows only `armv7`.
@urbas
Copy link
Contributor Author

urbas commented Nov 16, 2019

The initial PR has been retracted in favour of #73472

@urbas
Copy link
Contributor Author

urbas commented Dec 8, 2019

#73472 was merged and resolved this issue.

@urbas urbas closed this as completed Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: rust
Projects
None yet
Development

No branches or pull requests

3 participants