rust-legacy-fork icon indicating copy to clipboard operation
rust-legacy-fork copied to clipboard

cannot compile blink

Open jdrouet opened this issue 5 years ago • 1 comments

Hi!

I've been trying to install the avr-rust toolchain to build the blink project, and because I try to keep the things reproducible, I'm doing it in a Docker image.

FROM alpine AS cache

RUN apk add --no-cache git curl

RUN curl -o /rust-std-beta-x86_64-unknown-linux-gnu.tar.gz https://static.rust-lang.org/dist/2019-05-23/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz
RUN curl -o /rustc-beta-x86_64-unknown-linux-gnu.tar.gz https://static.rust-lang.org/dist/2019-05-23/rustc-beta-x86_64-unknown-linux-gnu.tar.gz
RUN curl -o /cargo-beta-x86_64-unknown-linux-gnu.tar.gz https://static.rust-lang.org/dist/2019-05-23/cargo-beta-x86_64-unknown-linux-gnu.tar.gz

RUN git clone https://github.com/avr-rust/rust.git --recursive /avr-rust \
  && rm -rf /avr-rust/.git

FROM rust:1-slim-stretch

RUN apt-get update \
    && apt-get install -y build-essential cmake curl python \
    && rm -rf /var/lib/apt/lists/*

ENV AVR_RUST_SRC_PATH /work/avr-rust
ENV AVR_RUST_BUILD_PATH /work/avr-rust-build

COPY --from=cache /avr-rust $AVR_RUST_SRC_PATH

WORKDIR $AVR_RUST_BUILD_PATH

# Generate Makefile using settings suitable for an experimental compiler
RUN $AVR_RUST_SRC_PATH/configure \
  --enable-debug \
  --disable-docs \
  --enable-llvm-assertions \
  --enable-debug-assertions \
  --enable-optimize \
  --enable-llvm-release-debuginfo \
  --experimental-targets=AVR \
  --prefix=/opt/avr-rust

COPY --from=cache /rust-std-beta-x86_64-unknown-linux-gnu.tar.gz $AVR_RUST_BUILD_PATH/build/cache/2019-05-23/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz
COPY --from=cache /rustc-beta-x86_64-unknown-linux-gnu.tar.gz $AVR_RUST_BUILD_PATH/build/cache/2019-05-23/rustc-beta-x86_64-unknown-linux-gnu.tar.gz
COPY --from=cache /cargo-beta-x86_64-unknown-linux-gnu.tar.gz $AVR_RUST_BUILD_PATH/build/cache/2019-05-23/cargo-beta-x86_64-unknown-linux-gnu.tar.gz

# Build the compiler, optionally install it to /opt/avr-rust
RUN make
RUN mkdir -p /opt/avr-rust && make install

# Register the toolchain with rustup
RUN rustup toolchain link avr-toolchain $(realpath $(find . -name 'stage2'))

# Optionally enable the avr toolchain globally
# RUN rustup default avr-toolchain

RUN cargo install xargo

RUN cp $(find /usr/local/rustup/toolchains -name cargo | grep bin | head -n 1)* /usr/local/rustup/toolchains/avr-toolchain/bin/

It's mostly copy-pasting your documentation, but when I run docker run -e RUST_TARGET_PATH=/code -e XARGO_RUST_SRC=/work/avr-rust/src -v /path/to/blink:/code -w /code avr-rust rustup run avr-toolchain xargo build --target avr-atmega328p --release I get the following error

warning: Patch `rustc-std-workspace-alloc v1.0.0 (/work/avr-rust/src/tools/rustc-std-workspace-alloc)` was not used in the crate graph.
Patch `rustc-std-workspace-core v1.0.0 (/work/avr-rust/src/tools/rustc-std-workspace-core)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
   Compiling core v0.0.0 (/work/avr-rust/src/libcore)
error: Unrecognized option: 'json'

error: could not compile `core`.

To learn more, run the command again with --verbose.
error: `"cargo" "build" "--release" "--manifest-path" "/tmp/xargo.GHevOdzy8xrC/Cargo.toml" "--target" "avr-atmega328p" "-p" "core"` failed with exit code: Some(101)
note: run with `RUST_BACKTRACE=1` for a backtrace
make: *** [Makefile:7: build] Error 1

I've tried to look around for a solution and nothing came up, except an incompatibility of some components... Do you guys have a way to fix that?

jdrouet avatar Jun 26 '20 07:06 jdrouet

You'll need matching versions of xargo and cargo. To be specific, these versions work(ed) for me:

bash-5.0$ rustc --version
rustc 1.37.0-dev
bash-5.0$ cargo --version
cargo 1.37.0
bash-5.0$ xargo --version
xargo 0.3.17 (fd55d412234a 2019-11-08)
cargo 1.37.0

You can find more discussion around this in avr-rust/blink#15.

Rahix avatar Jun 30 '20 06:06 Rahix