January 16, 2014

Trying Rust (language) on openSUSE

I am always playing with new languages. I love learning the thinking and philosophy behind them. Usually I throw them away after one evening (mostly mee-too’s), but there are some that are very interesting and get explored a bit further, and some are of course “adopted” into your toolbox.

The last ones that I spend quite some time with were:

  • Scala, which I used as base language for some courses
  • Go, which I used with the intention of writing servers for the Raspberry Pi in combination with Javascript browser apps

I was expecting to find in Go the “right” native-compiled language. Go is simple, has great (integrated) tooling, very pragmatic syntax, etc. But it has a bunch of warts that just made me very uncomfortable when translating ideas into code:

  • It does not support generics. Lists of voids (interface{})? no thanks.
  • For a language having first class functions. the functional aspects of is close to zero. After you did some ruby is hard to think again without using expressions and functional constructs like map/select/etc. “if” as a statement where you assign nil to the variable first… nope

At that time Mozilla’s Rust was still  immature and I did not manage to build a decent package to start playing with it.

Rust is a nice language. It is a bit noisy from the syntax, but it has been improved a lot in the latest releases. Garbage collected pointers (@) are gone and moved to the standard library which means there is now only ~ and &. But it is a language that got a lot (almost everything) “right”:

  • For having lot of features, it is very lightweight if you use the basics
  • It has decent integration with C
  • It has good support for concurrency using light tasks and channels
  • Supports something more flexible than classes, called traits
  • The toolchain is modern and very integrated
  • It does not reinvent everything. No own build system, and that is probably why it fits so well with Linux packaging
  • It uses LLVM as the backend, so we can expect good portability and getting all the optimization work from the LLVM guys for free
  • It has the feeling of ruby: object-oriented, with some functional sugar
  • Pattern matching!

But 0.9 was just released and this time I found some very decent .spec files to start with. I improved those with:

  • Do not install compiler related libraries to /usr/lib
  • Make parallel installation possible using /etc/alternatives

This is very similar how the Java package is structured. I also built a package for rust-bindgen, which uses clang to parse headers and generate bindings for C libraries.

08.01.2016 - Updated repository URLs and package name

So, grab one of the repositories and:

zypper ar http://download.opensuse.org/repositories/devel:/languages:/rust/openSUSE_Tumbleweed/devel:languages:rust.repo
zypper ref
zypper install rustc

Then continue with the tutorial and the manual. Happy learning!.