User avatar
Narann
Posts: 3
Joined: Tue Jan 13, 2015 9:12 pm
Contact: Website

Rust seems to bring some love to Rpi

Thu Jan 29, 2015 3:57 pm

Rust devs would some feedbacks from RPI community about experimental rust compiler builds for ARMv6 arch (RPI one!):

Test if the produced binaries actually run on the Raspberry Pi

Another discussion here.

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Thu Jan 29, 2015 7:01 pm

We have so many languages available today.

What are the compelling features of Rust that might induce me to spend time investigating it?

User avatar
Narann
Posts: 3
Joined: Tue Jan 13, 2015 9:12 pm
Contact: Website

Re: Rust seems to bring some love to Rpi

Thu Jan 29, 2015 7:54 pm

Rust goal #1 is safety. Technically, "if it compile it can't crash".

I would say it's C level with safety and Python flavour.

The Rust Project FAQ

The Rust Language FAQ

I'm not trying to gather peoples to test rust if they don't want to. The ticket just ask for some rpi users to download the binaries and execute the few shell command to see if "it run" or not. There is no "write code please!" involved. :D

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Sat Jan 31, 2015 4:05 pm

I don't mean to be so negative toward Rust. I'm always happy to check out compelling new technologies.

It's just that over the years I start to despair at the endless stream of "yet another language". I've had to learn and use quite a few and it seemed like pointless waste of time having to learn all the same things over again just in a new syntax/semantics.

On the other hand there are interesting language "varieties" that are worth being acquainted with. "Object oriented", "Functional", "List processing", "Dynamic" etc. It's worth learning at least one language that emphasizes each of those categories.

Hence my question re: Rust. Is it just another language? Or does it present some new concepts/styles in programming?

User avatar
bonzadog
Posts: 227
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: Rust seems to bring some love to Rpi

Mon May 04, 2015 12:48 pm

I would like to try Rust. I think the main aspect of Rust seems to safety rather than fancy languages additions.

If there is a decent IDE for it I would like one! - even if it costs something.

But looking at the subject under Raspberry Pi there doen't seem to much call or interest for it.

BD

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Mon May 04, 2015 3:23 pm

I don't buy into the safety idea.

The "if it compile it can't crash" is technically not true. In order for it not to crash it would have to be a language in which it is impossible to build and endless loop. If you can't build an endless loop in it then it is not Turing complete (Correct me if I'm wrong here) and would not be an interesting language. On the other hand if you can build endless loops in it then it can hang up for ever, which is indistinguishable from a crash.

After years of contemplating type safety in programming languages, the kind of feature that leads to statements like "if it compile it can't crash", I have almost convinced myself it's not helping. My reasoning is like so:

1) There are so many mistakes that can be made when programming a non-trivial application that we might consider the number of possible ways a wrong result can occur as infinite. That is to say there is an uncountable number of bugs that can be written.

2) "Crashing" is just another way for a program to produce a wrong result. Arguably no different than producing a result of 3 when 4 is expected. Wrong results are just as dangerous. Given the infinite number of ways a program can be "mis-coded" to produce a wrong result the number of them that cause crashes may well be a very small proportion.

3) Give 1) and 2) we see that type checking that prevents "crashing" by preventing out of bounds array accesses etc does not really help much prevent the vast ocean of possible bugs we can have.

4) Given that one will be doing testing of the finished program to see that it does indeed do what it is expected to then any errors due to type problems will be detected at test time anyway. Ergo type checking in the compiler is redundant.

I recently found I am not alone in feeling this way. The language Erlang was designed with reliability in mind. Originally intended for programming telephone network systems it is incredibly robust. Five nines up time is normal in distributed Erlang systems. Erlang is not strongly typed. It is designed around the philosophy of "let it crash". Let it crash as soon as possible without catching exceptions or otherwise propagating the problem in the system.

Rust's support for concurrency may be far more attractive than any safety idea.

User avatar
bonzadog
Posts: 227
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: Rust seems to bring some love to Rpi

Mon May 04, 2015 6:19 pm

No language can block programming errors, but Rust is supposed to :
Quote "Rust is a new programming language targeting systems-level applications. Rust offers a similar level of control over performance to C++, but guarantees type soundness, memory safety, and data-race freedom. One of Rust's distinguishing features is that, like C++, it supports stack allocation and does not require the use of a garbage
collector"


Which takes some of the naughtiness away from programming.


And yes, I am also looking at Erlang - that does appear to have some excellent features - I assume that it may be available on the Rpi. Again I want a debuugger for any new languages I need to learn.

But I still am very much in the reading stage. One problem is that the "old" languages have huge follwoing and one can get
assistance when requires.

I am also getting interested Visual processing with Opencv and also will start reading about that as well. I'll use the recommended language there which appears to be C++ and even C#.

So I have a lot of work in front of me.

Keep the comments coming!

BD
.

User avatar
DougieLawson
Posts: 34914
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Rust seems to bring some love to Rpi

Mon May 04, 2015 6:51 pm

Erlang can be downloaded from https://packages.erlang-solutions.com/erlang/ It has the instructions on the Raspbian tab on that page.

I've got this in /etc/apt/sources.list.d/erlang.list

Code: Select all

deb http://binaries.erlang-solutions.com/debian wheezy contrib
so I can install lots of Erlang stuff with apt-get.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

plugwash
Forum Moderator
Forum Moderator
Posts: 3327
Joined: Wed Dec 28, 2011 11:45 pm

Re: Rust seems to bring some love to Rpi

Tue Mar 14, 2017 3:20 pm

Heater wrote: 2) "Crashing" is just another way for a program to produce a wrong result. Arguably no different than producing a result of 3 when 4 is expected. Wrong results are just as dangerous. Given the infinite number of ways a program can be "mis-coded" to produce a wrong result the number of them that cause crashes may well be a very small proportion.
The real problem with languages like C is not merely that programs crash. If memory violations only caused clean crashes I doubt anyone would care much about them.

However in practice memory violations lead to two very bad types of failure.

1. Latent crashes. The program crashes in code totally unrelated to the code that caused the crash because it's memory was stepped on by a pointer gone bad (overflow, underflow, use after free, etc).
2. Arbitary code execution vulnerabilities.

C++ is better than C but still problematic. Refcounting is expensive, so people generally only use it for long term stuff. That works fine in simple cases but as call chains get longer and more complicated the risk of a reference/pointer used in a function higher up the call stack being invalidated by a function lower down the call stack increases. Standard containers don't do any bounds checking by default so if programmers get things wrong you can still get overflow/underflow.

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Tue Mar 14, 2017 9:17 pm

plugwash,

I don't disagree. C gets you down to the hardware, as much as is possible on common machines, with no training wheels or safety rails.

C++ can do a bit better.

When you have those you can build "safe" languages like Javascript, Python, Lua, whatever.

Which in some cases run almost as fast as natively compiled C/C++.

Having had to learn a dozen or more different languages over the years, seems every project I ever worked on used a different language, from Algol to JS, it seems seems kind of pointless to invent yet another language every year or so.

User avatar
Gavinmc42
Posts: 2753
Joined: Wed Aug 28, 2013 3:31 am

Re: Rust seems to bring some love to Rpi

Wed Mar 15, 2017 2:42 am

I kind of like Rust.
If there was a list of languages useful to learn it would be in the top 3-5.

You can write OS's and browser's in it.
And it works on Pi's and it is quick to compile too.
Native Multi-core aware.

If Redox OS runs on Aarch64 on a Pi 3 I might just move over to it.
Every couple of months I go check.
https://github.com/redox-os/redox/releases

Compute 3 W DIY tablet running Redox?
That would be cool.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jahboater
Posts: 3932
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Wed Mar 15, 2017 9:33 am

Heater wrote:I don't disagree. C gets you down to the hardware, as much as is possible on common machines, with no training wheels or safety rails.
I like C because you get the choice. Run compiled C as-is and its very fast, quick to compile, and portable - which is why its so popular. Run the binary with valgrind and it will check every instruction, every memory reference, and many library calls (such as memcpy). Of course thats slow. Faster are the compiler supplied "sanitize" run time checks. The important thing is that you have the choice. I would hate a language that was just plain slow all the time.

Then you have all the options for statically checking the code that a less mature language might not have, though of course the design of some modern languages does itself facilitate static checking.

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Wed Mar 15, 2017 10:41 am

My conviction, after spending years working on safety critical, fault tolerant systems is that what one needs is proper unit testing, code coverage analysis, integration testing etc.

The most predictable and fault free projects I ever worked on were written in a language called "Lucol". Lucol was very simple. It had no types. It did not allow for loops. As such the compiler could tell you exactly how long your code would take to run, thus ensuring the program could never exceed it's timing budget. And it made unit testing and code coverage analysis amazingly easy.

One of the most unreliable, unfathomable and untestable projects I worked on was written in Ada. A language with safety and correctness as one of it's main design goals.

As such I think all this emphasis on types and type checking and static analysis is pretty much a waste of time.

I love the sanitizers that come with Clang/LLVM. For example they do a very good job of memory leak detection and other memory misuse. Better than valgrind and faster too.

jahboater
Posts: 3932
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Wed Mar 15, 2017 10:52 am

Heater wrote:My conviction, after spending years working on safety critical, fault tolerant systems is that what one needs is proper unit testing, code coverage analysis, integration testing etc.
Of course - all that is assumed. Also proper design review, formal code inspections etc.
Heater wrote:I love the sanitizers that come with Clang/LLVM. For example they do a very good job of memory leak detection and other memory misuse. Better than valgrind and faster too.
The same sanitizers are available with GCC as well now. The later versions have more of course.

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Wed Mar 15, 2017 11:50 am

jahboater,
Of course - all that is assumed. Also proper design review, formal code inspections etc.
Quite so.

The thing that amazed me was that the Lucol and Ada projects I mentioned were at the same company, with the procedures in place. Often the same people on the teams.

The resulting Ada code was a big wobbly mess that was impossible to reason about and very hard to test. For example when I found that it's execution time was very erratic, sometimes reaching 90% of it's allotted time slot, I asked the project manager how we could guarantee that it would never overstep it's budget in some unforeseen conditions. Nobody had any idea! Something of a panic ensued.

By contrast, the Lucol projects, were very easy to test and reason about. They were solid.

All of which was the opposite of the sales pitch of Ada.

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

Re: Rust seems to bring some love to Rpi

Sun Nov 19, 2017 9:47 pm

Quick play with rust and very impressed. see viewtopic.php?f=32&t=188181&p=1236770#p1236770 (running rust from python)
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Heater
Posts: 11430
Joined: Tue Jul 17, 2012 3:02 pm

Re: Rust seems to bring some love to Rpi

Mon Nov 20, 2017 12:02 pm

Sadly it seems I will not be able to use Rust : https://www.rust-lang.org/en-US/conduct.html

n67
Posts: 939
Joined: Mon Oct 30, 2017 4:55 pm

Re: Rust seems to bring some love to Rpi

Mon Nov 20, 2017 12:32 pm

Heater wrote:
Mon Nov 20, 2017 12:02 pm
Sadly it seems I will not be able to use Rust : https://www.rust-lang.org/en-US/conduct.html
Yeah , I can see how that could be a problem.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

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

Re: Rust seems to bring some love to Rpi

Mon Nov 20, 2017 1:11 pm

Sounds like an expanded version of the Raspberry Pi forum rules "Be good to each other"... But it doesn't say you can't use rust for whatever devilish antisocial purpose you had in mind, just abide by the rules if you contribute to IRC channels, github or official rust.org forum. So you could use rust and be as unfriendly as you want on reddit (so long as you don't harass people).
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

jahboater
Posts: 3932
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Mon Nov 20, 2017 3:42 pm

Apologies to anyone thats already mentioned this.
Its now in the repositories, you can install rust with:-

sudo apt install rustc

then

rustc hello.rs

works, and "man rustc" tells all.

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

Re: Rust seems to bring some love to Rpi

Mon Nov 20, 2017 10:28 pm

@jahboater does that install rustup, cargo etc? I used

Code: Select all

curl https://sh.rustup.rs -sSf | sh
on my RPi which was pretty quick and is the 'preferred' way according to rust-lang.org
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

jahboater
Posts: 3932
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 1:59 am

paddyg wrote:
Mon Nov 20, 2017 10:28 pm
@jahboater does that install rustup, cargo etc? I used

Code: Select all

curl https://sh.rustup.rs -sSf | sh
on my RPi which was pretty quick and is the 'preferred' way according to rust-lang.org
No, I needed: "sudo apt install cargo", and rust-doc, rust-gdb. Also rust-lldb (another debugger).
I don't know about rustup or anything else

User avatar
Narann
Posts: 3
Joined: Tue Jan 13, 2015 9:12 pm
Contact: Website

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 9:12 am

rustup is very interesting: It download a whole rust env in user space and you can download multiple rust version. I think it's the best way to work with rust. :)

jahboater
Posts: 3932
Joined: Wed Feb 04, 2015 6:38 pm

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 11:07 am

paddyg wrote:
Sun Nov 19, 2017 9:47 pm
Quick play with rust and very impressed. see viewtopic.php?f=32&t=188181&p=1236770#p1236770 (running rust from python)
You mentioned in the link "faster than C"?
I added another version here which actually turns out to be faster than the C and cython versions.
I ran a trivial prime number type benchmark and found it to be about an order of magnitude slower than C. Looks like its generating code for ARMv6 (but I ran it on a Pi3).
What options did you give rustc? How do you specify the ARMv8 Cortex-A53 processor on the Pi3 (which has hardware division for example - rustc was emitting function calls)?

I just gave: rustc --codegen opt-level=3
--codegen target-cpu=arm doesn't work.

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

Re: Rust seems to bring some love to Rpi

Tue Nov 21, 2017 12:10 pm

Hi, I've only been looking at rust for a week or so.. After reading the post here I uninstalled rust (lenovo i5 laptop ubuntu) and installed rustup as per Laurent's instructions and the required tool-chain for cross compiling.

Subsequent to your post I compiled on the RPi3 (just)

Code: Select all

cargo build --release
and cross compiled for armv7 on my laptop

Code: Select all

cargo build --release --target=armv7-unknown-linux-gnueabihf
the same code (doing the atkinson algorithm on a greyscale image) and the resulting executables seem to be identical so presumably the rustup-installed cargo on the RPi is correctly targetting armv7. When I ran the time comparison I got
13.250s for 10x 1a vanilla C version using ctypes, passing PIL.tobytes
13.262s for 10x 1b vanilla C version using ctypes, passing numpy array
9.112s for 10x 2 cython version using standard import passing numpy array
9.423s for 10x 3 standard python module import passing PIL.tobytes
9.238s for 10x 4a vanilla rust version using ctypes, passing PIL.tobytes
9.226s for 10x 4b vanilla rust version using ctypes, passing numpy array
So on the RPi it's no longer true that rust is the fastest but I did try to keep the code as similar as possible and it's possible that cython does various optimisations that could be done relatively easily on the rust code. (I noticed that although doing / 8 was just as fast as >> 3 on my laptop, on the RPi it was slower so I switched it back)

Also, out of interest I cross-compiled the conrod spinning-square example which I had tried on this laptop last night, and it worked (though there were issues with speed and antialiasing etc)
Screenshot from 2017-11-21 11-27-54.jpg
Screenshot from 2017-11-21 11-27-54.jpg (60.43 KiB) Viewed 3942 times
Last edited by paddyg on Tue Nov 21, 2017 12:21 pm, edited 2 times in total.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Other programming languages”