HermannSW
Posts: 1201
Joined: Fri Jul 22, 2016 9:09 pm

Rust does not work after successful install

Thu Nov 29, 2018 5:03 pm

For building a project I need to install Rust toolchain.
I followed the instructions and installation was good:
https://rustup.rs/#

Code: Select all

[email protected]:~ $ curl https://sh.rustup.rs -sSf | sh
info: downloading installer
...
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
[email protected]:~ $ 

But even the simplest hello world compilation with rustc hangs infinitely in Raspbian Stretch:

Code: Select all

$ cat hello.rs 
fn main() {
    println!("Hello World!");
}
$ rustc hello.rs 
I did reboot just to see whether it made a difference to just running the source command, but it did not.
Was anybody successful in installing Rust toolchain in Raspbian and getting rustc compiling?
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

HermannSW
Posts: 1201
Joined: Fri Jul 22, 2016 9:09 pm

Re: Rust does not work after successful install

Wed Dec 26, 2018 10:18 pm

I asked on rust forum as well, and got some help:
https://users.rust-lang.org/t/why-does- ... etch/22760

Summary:
While latest stable rustc binary hangs on Raspbian, latest nightly works:

Code: Select all

[email protected]:~ $ /home/pi/.rustup/toolchains/nightly-armv7-unknown-linux-gnueabihf/bin/rustc hello.rs 
[email protected]:~ $ ./hello 
Hello World!
[email protected]:~ $

P.S:
rustc hello world compile time is 38 times slower that gcc, rust executable is 292 times bigger than C executable ...

Code: Select all

[email protected]:~ $ time /home/pi/.rustup/toolchains/nightly-armv7-unknown-linux-gnueabihf/bin/rustc hello.rs 

real	0m10.985s
user	0m2.108s
sys	0m0.369s
[email protected]:~ $ ls -l hello
-rwxr-xr-x 1 pi pi 2386156 Dec 26 23:59 hello
[email protected]:~ $ 

Code: Select all

[email protected]:~ $ time gcc hello.c

real	0m0.286s
user	0m0.245s
sys	0m0.040s
[email protected]:~ $ ls -l a.out 
-rwxr-xr-x 1 pi pi 8148 Dec 27 00:02 a.out
[email protected]:~ $ 
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

User avatar
scruss
Posts: 2224
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rust does not work after successful install

Thu Dec 27, 2018 5:39 am

HermannSW wrote:
Wed Dec 26, 2018 10:18 pm
... rust executable is 292 times bigger than C executable ...
But is statically linked, IIRC. Like golang, rust does its best to avoid DLL Hell.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

HermannSW
Posts: 1201
Joined: Fri Jul 22, 2016 9:09 pm

Re: Rust does not work after successful install

Thu Dec 27, 2018 12:21 pm

OK, but C static hello world is still more than 4 times smaller, and compiles 25 times faster than rustc:

Code: Select all

[email protected]:~ $ time gcc -static hello.c

real	0m0.435s
user	0m0.348s
sys	0m0.084s
[email protected]:~ $ ls -l a.out
-rwxr-xr-x 1 pi pi 569264 Dec 27 00:06 a.out
[email protected]:~ $ ./a.out 
Hello World!
[email protected]:~ $

Of course there are other advantages of Rust over C -- but Raspbian is definitely not a platform tested since stable rustc just hangs.
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

hippy
Posts: 5122
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Rust does not work after successful install

Thu Dec 27, 2018 12:36 pm

HermannSW wrote:
Thu Dec 27, 2018 12:21 pm
OK, but C static hello world is still more than 4 times smaller, and compiles 25 times faster than rustc:
I can't help with whatever issue you have but, having not used rustc before, I installed it on my Pi3B (non-plus) using 'sudo apt-get install rustc', used your hello.rs, and ...

Code: Select all

[email protected]:~$ rustc --version
rustc 1.24.1 (f2dda7fd7 2018-08-16)
[email protected]:~$ time rustc hello.rs
real    0m2.835s
user    0m2.580s
sys     0m0.254s
[email protected]:~$ ls -l hello
-rwxr-xr-x 1 pi pi 266840 Dec 27 12:27 hello
[email protected]:[email protected]:~$ ./hello
Hello World!
[email protected]:~$
That probably isn't all of what you personally need but I thought the numbers might be useful or interesting to see.

HermannSW
Posts: 1201
Joined: Fri Jul 22, 2016 9:09 pm

Re: Rust does not work after successful install

Thu Dec 27, 2018 2:08 pm

Thanks for that information.
I installed rustc now as you did via apt-get install, and not by the official method from link in initial posting of this thread.
I get same results as you (compile time is 2.313s on Pi 3B+).
The new executable size is now half of that of the static C binary, all good with this version of rustc.

Not sure what else the nightly rustc generates into the binary, maybe its just the newer version that blew up binary size:

Code: Select all

[email protected]:~ $ /home/pi/.rustup/toolchains/nightly-armv7-unknown-linux-gnueabihf/bin/rustc --version
rustc 1.33.0-nightly (adbfec229 2018-12-17)
[email protected]:~ $ 
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

hippy
Posts: 5122
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Rust does not work after successful install

Thu Dec 27, 2018 2:37 pm

Code: Select all

real	0m10.985s
user	0m2.108s
sys	0m0.369s
That 'real' is significantly longer than 'user' so I'm wondering if your nightly builds could be trying to fetch something from a server somewhere, trying to connect to a service which doesn't exist, is hanging while waiting for a timeout ?

User avatar
paddyg
Posts: 2308
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Rust does not work after successful install

Mon Jan 14, 2019 1:24 am

@HermannSW I tried `rustup update` on my RPi to latest (stable; 1.31 '2018' version) Yesterday, after noticing this thread, and got various errors with failure to complete. When I tried it again today it all went through OK. So I think whatever problems have been fixed (though no post on the forum you linked to). Following the `standard` route using rustup, cargo etc might make development easier than using rustc. Rust will take longer to compile than C and will produce bigger applications but it will probably be worth it!
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

HermannSW
Posts: 1201
Joined: Fri Jul 22, 2016 9:09 pm

Re: Rust does not work after successful install

Mon Jan 14, 2019 8:53 am

Sorry, I forgot to update here after I got a lot help on rust forum and finaly was able to figure out the issue.
https://users.rust-lang.org/t/why-does- ... h/22760/20
Summary:

latest stable rustc hangs on Raspbian
latest nightly rustc is good on Raspbian
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

Return to “Raspbian”