rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.03k stars 877 forks source link

Zero-sized binaries in ~/.cargo/bin (ChromeOS?) #1954

Open kinnison opened 4 years ago

kinnison commented 4 years ago

The latest version of rust (1.36.0 as of this comment) is not working. After installation on an i686 ChromeOS system, I get all zero byte binaries in ~/.cargo/bin. By the way, I fully agree with @josephRice. I see so many projects like this that require the user's path to be modified. I don't understand why this is so popular but it's the WRONG WAY to install an application. See below:

chronos@localhost /usr/local/tmp $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust programming 
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo's bin 
directory, located at:

  /home/chronos/user/.cargo/bin

This path will then be added to your PATH environment variable by modifying the
profile files located at:

  /home/chronos/user/.profile
  /home/chronos/user/.bash_profile

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: i686-unknown-linux-gnu
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

info: syncing channel updates for 'stable-i686-unknown-linux-gnu'
info: latest update on 2019-07-04, rust version 1.36.0 (a53f9df32 2019-07-03)
info: downloading component 'rustc'
103.6 MiB / 103.6 MiB (100 %)   8.2 MiB/s in 14s ETA:  0s
info: downloading component 'rust-std'
 61.0 MiB /  61.0 MiB (100 %)   7.7 MiB/s in  9s ETA:  0s
info: downloading component 'cargo'
info: downloading component 'rust-docs'
 11.0 MiB /  11.0 MiB (100 %)   8.3 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
103.6 MiB / 103.6 MiB (100 %)   1.5 MiB/s in  1m 12s ETA:  0s
info: installing component 'rust-std'
 61.0 MiB /  61.0 MiB (100 %)   1.6 MiB/s in 38s ETA:  0s
info: installing component 'cargo'
  4.7 MiB /   4.7 MiB (100 %)   1.7 MiB/s in  3s ETA:  0s
info: installing component 'rust-docs'
 11.0 MiB /  11.0 MiB (100 %) 425.6 KiB/s in 50s ETA:  0s    
info: default toolchain set to 'stable'

  stable installed - (error reading rustc version)

Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH 
environment variable. Next time you log in this will be done automatically.

To configure your current shell run source $HOME/.cargo/env
chronos@localhost ~ $ source $HOME/.cargo/env
chronos@localhost ~ $ cd .cargo/bin/
chronos@localhost ~/.cargo/bin $ ls -la
total 104
drwxr-xr-x  2 chronos chronos 4096 Jul 28 01:31 .
drwxr-xr-x  3 chronos chronos 4096 Jul 28 01:35 ..
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 cargo
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 cargo-clippy
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 cargo-fmt
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 cargo-miri
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 clippy-driver
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rls
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rustc
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rustdoc
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rustfmt
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rust-gdb
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rust-lldb
-rwxr-xr-x 12 chronos chronos    0 Jul 28 01:31 rustup

Also, why does the script download everything twice? Sorry for the rant.

Originally posted by @uberhacker in https://github.com/rust-lang/rustup.rs/issues/686#issuecomment-515738186

kinnison commented 4 years ago

@uberhacker The answer to your second point is simple -- it doesn't download everything twice. You're probably mistaking the installation phase for a download phase. The description "installing component..." rather than "downloading component..." should make this clear, but perhaps there's something we can do to improve matters subsequently.

The first point -- that your binaries are zero-length -- is more worrying. Does this happen every time you try and install Rust on ChromeOS?

uberhacker commented 4 years ago

@kinnison: Thank you for the quick feedback. Yes, sorry. I didn't notice the installing line to distinguish from downloading. Guess next time I should look more closely. I did try to install multiple times and the issue appears to be repeatable. I tried installing on another x86_64 Chromebook and the binaries in ~/.cargo/bin were no longer zero sized so this bug appears to be isolated to i686 architecture. However, ChromeOS has a few more challenges to overcome since out-of-the-box, the user directory is mounted without execution permission. To add to the fun, the install script needs a temporary directory with executable permission also. This requires something like export TMPDIR=/usr/local/tmp to allow the install script to execute. I noticed there was the RUSTUP_HOME environment variable to reroute the path from ~/.rustup. Is there a way to install to a directory other than ~/.cargo?

kinnison commented 4 years ago

You can set CARGO_HOME too, and both RUSTUP_HOME and CARGO_HOME should be part of your generalised environment (with $CARGO_HOME/bin in your PATH) if you want to control it fully.

uberhacker commented 4 years ago

Great. Now I have the info I need to package rust for Chromebrew. If it helps any, I did notice there were some non-zero sized binaries in ~/.rustup/toolchains/stable-i686-unknown-linux-gnu/bin but the rustup executable was missing. See below:

chronos@localhost ~ $ ls -l ~/.rustup/toolchains/stable-i686-unknown-linux-gnu/bin
total 19248
-rwxr-xr-x 1 chronos chronos 13681260 Jul 28 23:09 cargo
-rwxr-xr-x 1 chronos chronos   292532 Jul 28 23:10 rustc
-rwxr-xr-x 1 chronos chronos  5715644 Jul 28 23:10 rustdoc
-rwxr-xr-x 1 chronos chronos      604 Jul 28 22:40 rust-gdb
-rwxr-xr-x 1 chronos chronos     1789 Jul 28 22:40 rust-gdbgui
-rwxr-xr-x 1 chronos chronos     1245 Jul 28 22:40 rust-lldb
kinnison commented 4 years ago

Yeah, so those are the real binaries. In ~/.cargo/bin will be the rustup binary and hardlinks to it for each of the binaries it proxies into your toolchain (such as cargo rustc etc). That those are zero-sized is worrisome since it indicates something very unexpected is happening.

rbtcollins commented 3 years ago

I wonder if it is something to do with the downloaded binary and chrome protections/sandboxing.

kinnison commented 3 years ago

I've no idea how chromeos does its sandboxing sadly. It'd be fascinating to see an strace of the rustup-init run if @uberhacker is still interested in trying to bottom this and can still reproduce the issue.