rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
54.01k stars 10.15k forks source link

Compile error using alpine / musl, but not on debian #2036

Closed pimlie closed 4 months ago

pimlie commented 4 months ago

Using the rust:alpine based docker image from my other issue about the terminal today, I cannot get past exercise if1 as I keep getting a rustc compile error. All other exercises up to if1 compiled fine using alpine. I tried debugging this myself a bit but I guess I'm still too much of a n00b, so sorry about that ;)

As it works using debian, this can be considered a low prio issue I guess.

# create debian container
$ docker run -d --rm --name rl-debian -v ./rl-data:/data rust:slim sh -c 'cargo install rustlings; rustup component add clippy; echo "READY"; tail -f /.dockerenv'

# create alpine container
$ docker run -d --rm --name rl-alpine -v ./rl-data:/data rust:alpine sh -c 'apk add build-base musl-dev; cargo install rustlings; rustup component add clippy; echo "READY"; tail -f /.dockerenv'

# ... wait for container builds to finish ...

# init rustlings (once, containers share the same folder)
$ docker exec -it -w /data rl-debian rustlings init

# take ownership of local folder
$ sudo chmod 777 ./rl-data -R

# fix if1
$ editor ./rl-data/rustlings/exercises/03_if/if1.rs

# run if1 using the debian container, this should work if you fixed if1 correctly
$ docker exec -it -w /data/rustlings rl-debian rustlings run if1
... shortened ...
✓ Successfully ran exercises/03_if/if1.rs

# run if1 using the alpine container
$ docker exec -it -w /data/rustlings rl-alpine rustlings run if1

The alpine container will show the following error, this ofc prevents you from continuing to the next exercise

error: output of --print=file-names missing when learning about target-specific information from rustc
command was: `/usr/local/rustup/toolchains/1.79.0-x86_64-unknown-linux-musl/bin/rustc - --crate-name ___ --print=file-names -A warnings --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg`

--- stdout
___
lib___.rlib
lib___.a
lib___.so
/usr/local/rustup/toolchains/1.79.0-x86_64-unknown-linux-musl
off
packed
unpacked
___
debug_assertions
panic="unwind"
proc_macro
target_abi=""
target_arch="x86_64"
target_endian="little"
target_env="musl"
target_family="unix"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="linux"
target_pointer_width="64"
target_vendor="unknown"
unix
mo8it commented 4 months ago

The problem why if1 fails is that it is the first exercise with tests. Rustlings currently tests by calling cargo test with RUSTFLAGS="-A warning". It looks like RUSTFLAGS is not handled probably on Alpine.

Closing because Rustlings can't do anything about this issue. It has to be fixed by cargo or rustc. Follow the issue that I opened: https://github.com/rust-lang/rust/issues/127498

Anyway: Just use Debian. Alpine is often problematic and even has worse performance sometimes.

pimlie commented 4 months ago

Thanks :)

I thought indeed that the tests could be the cause of the issue, so I tried removing all the tests from if1 but I guess that it's not possible to toggle https://github.com/rust-lang/rustlings/blob/main/src/exercise.rs dynamically? If I understand correctly it's currently set in the macro config here during the rustlings build and not during the build of the exercise? https://github.com/rust-lang/rustlings/blob/main/rustlings-macros/info.toml

mo8it commented 4 months ago

Disabling this would either mean disabling tests or having duplicated output of cargo check 😅

qaqland commented 3 months ago

works well here

image

rustc 1.78.0 (9b00956e5 2024-04-29) (Alpine Linux 1.78.0-r0)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-alpine-linux-musl
release: 1.78.0
LLVM version: 17.0.6

i haven't try docker but it seems you can install clippy by apk

apk add rust-clippy

because it has some "special" patches

everything work well on pipeline

https://pkgs.alpinelinux.org/packages?name=rustlings

mo8it commented 3 months ago

@qaqland Thanks!

I can confirm that both the packaged rustlings and the normal installation after apk add cargo rust-clippy work. Weird how adding rust-clippy fixes the problem 😅