rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.82k stars 12.22k forks source link

`cargo build/rustc` fails to create binary for example from embedded Rust book #91635

Open pauschar opened 2 years ago

pauschar commented 2 years ago

Hi, The "embedded Rust" book suggests a starter example, see https://docs.rust-embedded.org/book/start/hardware.html I'm running Windows10, installed Rust itself like this

rustup-init.exe -y --default-host x86_64-pc-windows-gnu --default-toolchain stable --profile default --target thumbv7em-none-eabi

and the add-ons as required by the mentioned book (https://docs.rust-embedded.org/book/intro/install.html) like this

cargo install cargo-binutils
rustup component add llvm-tools-preview
cargo install cargo-generate

As per the book, running cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart gives a usable example where you should be able to run cargo build --example hello.

When doing the builds I'm getting the expected .elf in about 50%. For the other half, the build fails, building the last step never returns:

> cargo build --example hello
   Compiling typenum v1.14.0
   Compiling semver-parser v0.7.0
   Compiling proc-macro2 v1.0.33
... lots more
   Compiling cortex-m-rt-macros v0.6.15
    Building [=========================> ] 50/51: hello(example)

That is, it sits there forever.

I would like to understand why the build fails. rustc and cargo are still visible in Windows' task manager, but they dont seem to do anything ...

I ctrl-c'd the whole thing, then tried cargo build --example hello -vv and see what rustc is doing for the last build/link step:

Compiling app v0.1.0 (D:\projects\Rust\app)
     Running `set CARGO=\\?\C:\Users\pauschar\.rustup\toolchains\stable-x86_64-pc-windows-gnu\bin\cargo.exe&& set CARGO_CRATE_NAME=hello&& set CARGO_MANIFEST_DIR=D:\projects\Rust\app&& set CARGO_PKG_DESCRIPTION=""&& set CARGO_PKG_HOMEPAGE=""&& set CARGO_PKG_LICENSE=""&& set CARGO_PKG_LICENSE_FILE=""&& set CARGO_PKG_NAME=app&& set CARGO_PKG_REPOSITORY=""&& set CARGO_PKG_VERSION=0.1.0&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MINOR=1&& set CARGO_PKG_VERSION_PATCH=0&& set CARGO_PKG_VERSION_PRE=""&& set CARGO_PRIMARY_PACKAGE=1&& set OUT_DIR=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\build\app-73078ac6ed4885fc\out&& set PATH="D:\projects\Rust\app\target\debug\deps;C:\Users\pauschar\.rustup\toolchains\stable-x86_64-pc-windows-gnu\bin;C:\Users\pauschar\.cargo\bin;C:\Users\pauschar\.rustup\toolchains\stable-x86_64-pc-windows-gnu\bin;C:\Users\pauschar\.pyenv\pyenv-win\bin;C:\Users\pauschar\.pyenv\pyenv-win\shims;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\dotnet\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\pauschar\AppData\Local\Microsoft\WindowsApps;C:\Users\pauschar\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\pauschar\AppData\Roaming\Python\Python38\Scripts;C:\Users\pauschar\.cargo\bin;D:\ModusToolbox\tools_2.4\gcc\bin;D:\ModusToolbox\tools_2.4\gcc-x86_64\bin;D:\ModusToolbox\tools_2.4\openocd\bin"&& rustc --crate-name hello --edition=2018 examples\hello.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=7af716e7343a9077 -C extra-filename=-7af716e7343a9077 --out-dir D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\examples --target thumbv7em-none-eabi -C incremental=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\incremental -L dependency=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\deps -L dependency=D:\projects\Rust\app\target\debug\deps --extern cortex_m=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\deps\libcortex_m-64e5ebd5d4cf6b74.rlib --extern cortex_m_rt=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\deps\libcortex_m_rt-000779e30b09c440.rlib --extern cortex_m_semihosting=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\deps\libcortex_m_semihosting-0e7645357bfca3ef.rlib --extern panic_halt=D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\deps\libpanic_halt-3e862fa14e8c31f4.rlib -C link-arg=--nmagic -C link-arg=-Tlink.x -L D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\build\app-73078ac6ed4885fc\out -L D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\build\cortex-m-fe97c430fb0bfe36\out -L D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\build\cortex-m-rt-8f6a553964f55910\out -L D:\projects\Rust\app\target\thumbv7em-none-eabi\debug\build\cortex-m-semihosting-1a956af1ddd09444\out`

For the above I used 1.57.0, but the problem is the same for 1.56, tried it last week prior to 1.57 release.

Meta

rustc --version --verbose:

binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-pc-windows-gnu
release: 1.57.0
LLVM version: 13.0.0
Backtrace

``` Using `$env:RUST_BACKTRACE=1` did not change the output compared to what I reported above. ```

Thx to anyone who could take a look into this.

Enselic commented 4 weeks ago

Triage: Can you still reproduce this?