rust-lang / rustlings

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

Installation issue on macOS 14.0 #1953

Closed ruby-ist closed 5 months ago

ruby-ist commented 5 months ago

I've been trying to install Rustlings on my m1 macbook air but I'm facing the following compilation error again and again.

Screenshot 2024-04-19 at 1 55 01 PM

Here's the details about my spec:

$ rustc -V
rustc 1.77.2 (25ef9e3d8 2024-04-09)

$ file $(which rustc)
/Users/srira/.cargo/bin/rustc: Mach-O 64-bit executable arm64

$ file $(which rustup)
/Users/srira/.cargo/bin/rustup: Mach-O 64-bit executable arm64

$ file $(which cargo)
/Users/srira/.cargo/bin/cargo: Mach-O 64-bit executable arm64

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

OS: macOS 14.0 Sonoma Xcode version: 15.3

I tried everything recommended on stackoverflow but had no luck, I also saw one other issue similar to this here. But that fix doesn't seem to be working for me. I also tried re-installing rust, cmake, llvm and xcode command line tools.

Edit: I have another linux machine, in which rustlings installed successfully

mo8it commented 5 months ago

@ruby-ist It is unfortunate that I can't reproduce it because I don't have MacOS. It might be just a dependency problem. I recommend trying the main branch which has all dependencies updated. To do so, could you please delete the rustlings directory and run the following?

git clone --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
cargo install --force --path .

Please tell me if it works :)

ruby-ist commented 5 months ago

@mo8it That doesn't work, facing the same issue. However I found out that even though compilation failed, the cargo run command works with default installation. And cargo run watch command works as expected too. Is this a normal behaviour? I'm new to Rust. Can I continue this course with cargo run command instead of rustlings command?

mo8it commented 5 months ago

Weird. It looks like a problem with the release profile then. Could you please try to run cargo run --release instead of cargo run? In that case, you would get the error again.

Could you please also post the output of the command rustup toolchain list?

Otherwise, yes, you can work with cargo run watch. Sorry for the inconvenience. I will try to ask around to debug this issue and prevent it in the future.

ruby-ist commented 5 months ago

I ran cargo run --release command and yes, it threw the same error again.

Output of rustup toolchain list:

stable-aarch64-apple-darwin (default)

Thanks for your response @mo8it. I will continue with cargo run watch command for now.

mo8it commented 5 months ago

I got a hint. Could you please share the output of the following commands?

which strip
whereis strip
echo $PATH
mo8it commented 5 months ago

You might also find something helpful in https://github.com/rust-lang/cargo/issues/8913 or https://github.com/rust-lang/rust/issues/73908

Of course only if you are interested in fixing the issue. Otherwise, I hope that cargo run watch is good enough :)

ruby-ist commented 5 months ago

Sure, I would be happy to help you fix the issues. Here are the outputs:

$ which strip
/opt/homebrew/opt/binutils/bin/strip

$ whereis strip
strip: /usr/bin/strip /opt/homebrew/opt/binutils/share/man/man1/strip.1

$ echo "${PATH//:/\n}"
/opt/homebrew/opt/binutils/bin
/Users/srira/.bun/bin
/Users/srira/.wasmtime/bin
/opt/homebrew/opt/openjdk/bin
/Users/srira/.gem/ruby/3.1.0/bin
/Users/srira/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/bin
/Users/srira/.rubies/ruby-3.1.0/bin
/opt/homebrew/opt/sqlite/bin
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Users/srira/DragonRuby
/Users/srira/.rubies/ruby-3.1.0/bin
/Users/srira/.gem/ruby/3.1.0/bin
/Users/srira/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
/Library/Apple/usr/bin
/Applications/Postgres.app/Contents/Versions/latest/bin
/Users/srira/.cargo/bin
/Users/srira/Library/Application Support/JetBrains/Toolbox/scripts
mo8it commented 5 months ago

Your output shows that this has to be this bug related to stripping: https://github.com/dtolnay/proc-macro2/issues/448

See this too: https://github.com/rust-lang/cargo/issues/11641#issuecomment-1407531012

which strip should return /usr/bin/strip, not something from homebrew.

The solution would be to find out where the PATH variable is changed to prepend /opt/homebrew/opt/binutils/bin. Probably in .bash_profile, you should find something like this (prepending):

PATH="/opt/homebrew/opt/binutils/bin:$PATH"

Then, just change it to this (appending):

PATH="$PATH:/opt/homebrew/opt/binutils/bin"

This means that binaries will be looked for in /usr/bin before /opt/homebrew/opt/binutils/bin. Therefore, which strip should then return /usr/bin/strip and the compilation in the release profile should work :D

Feel free to reopen if it doesn't work.

ruby-ist commented 5 months ago

Thanks a lot @mo8it changing PATH variable precedence solved the issue, though I have to remove the folder and install it again. Everything is working fine now 👍🏽