Skip to content

Building your own applications

Stefan Lankes edited this page Jun 29, 2022 · 2 revisions

To give you an example on how to build your application with RustyHermit, lets create a new cargo project: A more comprehensive version of the example project is published at rusty-demo.

cargo new hello_world
cd hello_world

To bind the library operating system to the application, add the crate hermit-sys to the dependencies in the file Cargo.toml. It is important to use at least the optimization level 1. Consequently, it is required to extend Cargo.toml with following lines:

# Cargo.toml

[target.'cfg(target_os = "hermit")'.dependencies]
hermit-sys = "0.2.*"

To link the application with RustyHermit, declare hermit_sys an external crate in the main file of your application.

// src/main.rs

#[cfg(target_os = "hermit")]
extern crate hermit_sys;

fn main() {
        println!("Hello World!");
}

The final step is building the application as follows:

cargo build -Z build-std=std,core,alloc,panic_abort -Z build-std-features=compiler-builtins-mem --target x86_64-unknown-hermit

(You can set an easy alias for this in the .cargo/config file. Take a look at the demo)

The resulting "hypervisor-ready" binary then can be found in target/x86_64-unknown-hermit/debug.