<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>gandro’s blog</title>
 <link href="http://gandro.github.io/atom.xml" rel="self"/>
 <link href="http://gandro.github.io/"/>
 <updated>2020-06-13T12:02:42+00:00</updated>
 <id>http://gandro.github.io</id>
 <author>
   <name>Sebastian Wicki</name>
   <email>gandro@gmx.net</email>
 </author>

 
 <entry>
   <title>Running Rust on the Rumprun unikernel</title>
   <link href="http://gandro.github.io/2015/09/27/rust-on-rumprun/"/>
   <updated>2015-09-27T00:00:00+00:00</updated>
   <id>http://gandro.github.io/2015/09/27/rust-on-rumprun</id>
   <content type="html">&lt;p&gt;The &lt;a href=&quot;https://www.rust-lang.org/&quot;&gt;Rust&lt;/a&gt; programming language has been able to
run on bare-metal
&lt;a href=&quot;https://github.com/charliesome/rustboot&quot;&gt;without the standard library&lt;/a&gt;
for quite some while now. However, most Rust applications depend on the
&lt;a href=&quot;https://doc.rust-lang.org/std/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std&lt;/code&gt;&lt;/a&gt; crate, and therefore still need a full
operating system to run.&lt;/p&gt;

&lt;p&gt;This is where the
&lt;a href=&quot;http://repo.rumpkernel.org/rumprun&quot;&gt;Rumprun unikernel platform&lt;/a&gt; comes into
play. It allows you to build your POSIX applications into bootable
single-purpose images. Because unikernels are tailored to run a single application,
they come without the footprint of a full-featured operating system. This makes
them a great tool for application virtualization. Supported platforms of Rumprun include not
only Xen/EC2 and KVM, but you can also run your image on bare-metal hardware.&lt;/p&gt;

&lt;p&gt;Rumprun is based on &lt;a href=&quot;http://rumpkernel.org&quot;&gt;rump kernels&lt;/a&gt;, it reuses
NetBSD’s libc and drivers as components to provide a POSIX-y interface –
the interface which the Rust standard library is built upon.&lt;/p&gt;

&lt;p&gt;For the last couple of days we have been working on Rumprun support for Rust –
you can now deploy your Rust application as a Rumprun unikernel. With our toolchain
set up, a single &lt;a href=&quot;https://github.com/rust-lang/cargo/&quot;&gt;cargo&lt;/a&gt; command is all
you need to turn your Rust application into a Rumprun unikernel image.&lt;/p&gt;

&lt;p&gt;Here is a screenshot of an example TCP/IP server written in Rust and built with
cargo, running in a Rumprun unikernel on QEMU.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/public/rust-on-rumprun/tcp.png&quot;&gt;&lt;img alt=&quot;An example Rust TCP/IP server on Rumprun&quot; src=&quot;/public/rust-on-rumprun/tcp.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that running Rust on bare-metal without a standard library is different
from running Rust on bare-metal Rumprun: Rust’s
&lt;a href=&quot;https://doc.rust-lang.org/book/no-stdlib.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#![no_std]&lt;/code&gt;&lt;/a&gt; feature
means you write your own drivers and environment. Rust on Rumprun on the other hand already
provides you with production-quality NetBSD drivers and a standard library. You can
choose which subsystems and drivers you want to compile into your image.&lt;/p&gt;

&lt;p&gt;A significant portion of the work was spent on making &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std&lt;/code&gt; work correctly
on NetBSD. As a side effect of this project, you can now also compile
your Rust binaries for &lt;a href=&quot;https://github.com/rust-lang/rust/pull/28543&quot;&gt;NetBSD/amd64&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;getting-started&quot;&gt;Getting started&lt;/h3&gt;

&lt;p&gt;The remaining part of this blog post briefly guides you through the necessary
steps to build your Rust application into a Rumprun unikernel image. This is
what you have to do:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Build the Rumprun unikernel platform, it provides the tools and libraries
to build Rumprun unikernels.&lt;/li&gt;
  &lt;li&gt;Set up a Rust cross-compiler and standard library for Rumprun.
This allows you to compile binaries that you can later “bake” into a Rumprun
unikernel.&lt;/li&gt;
  &lt;li&gt;Compile your Rust application using the Rust cross-compiler.&lt;/li&gt;
  &lt;li&gt;Bake the generated Rust binary into a Rumprun unikernel image, which you
can then run on a hypervisor or bare-metal machine of your choice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;building-rumprun&quot;&gt;Building Rumprun&lt;/h4&gt;

&lt;p&gt;First, we need to build Rumprun. The repository provides its own cross-compile
tools that are needed in the following steps.
Check out the excellent &lt;a href=&quot;http://wiki.rumpkernel.org/Tutorial%3A-Building-Rumprun-Unikernels&quot;&gt;Tutorial - Building Rumprun Unikernels&lt;/a&gt;
for instructions. I recommend following the whole tutorial, but if you are in a
hurry, the section “Building the Rumprun Platform” is all you need to continue
to the next step.&lt;/p&gt;

&lt;h4 id=&quot;building-a-rust-cross-compiler&quot;&gt;Building a Rust cross-compiler&lt;/h4&gt;

&lt;p&gt;The Rust source tree already
&lt;a href=&quot;https://github.com/rust-lang/rust/pull/28593&quot;&gt;contains all patches&lt;/a&gt; needed
to build for Rumprun, but you will have to enable the Rumprun target.
We provide the scripts for building a Rust cross-compiler and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std&lt;/code&gt;
crate automatically in the  &lt;a href=&quot;http://repo.rumpkernel.org/rumprun-packages&quot;&gt;rumprun-packages&lt;/a&gt;
repository. Just follow the &lt;a href=&quot;https://github.com/rumpkernel/rumprun-packages/blob/master/rust/README.md&quot;&gt;instructions on how to build the Rust package&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;compiling-and-baking-your-rust-application&quot;&gt;Compiling and baking your Rust application&lt;/h4&gt;

&lt;p&gt;If everything is working properly, building your Rust application as a
unikernel image is as easy as running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cargo rumpbake&lt;/code&gt;. Be aware though that
at the time of writing, some crates on &lt;a href=&quot;https://crates.io&quot;&gt;crates.io&lt;/a&gt; don’t
have proper NetBSD support yet, and might fail to compile or execute.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Congratulations!&lt;/em&gt; You are now set up to build your own Rust applications into
Rumprun unikernel images.&lt;/p&gt;

&lt;h3 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h3&gt;

&lt;p&gt;This project is all about taking existing pieces of software and putting
them together. Without the awesome previous work of the Rust and the rump kernel
hackers, this could not exist. A special thank you goes to
&lt;a href=&quot;https://twitter.com/anttikantee&quot;&gt;@anttikantee&lt;/a&gt; for his support along the way.&lt;/p&gt;
</content>
 </entry>
 

</feed>
