-
Notifications
You must be signed in to change notification settings - Fork 88
Building your own applications
Stefan Lankes edited this page Jun 23, 2024
·
6 revisions
To give you an example on how to build your application with HermitOS, lets create a new cargo project: A more comprehensive version of the example project is published at hermit-rs-template.
cargo new hello_world
cd hello_world
To bind the library operating system to the application, add the crate hermit 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 = "0.9.*"
To link the application with HermitOS, declare hermit
in the main file of your application.
// src/main.rs
#[cfg(target_os = "hermit")]
use hermit as _;
fn main() {
println!("Hello World!");
}
The final step is building the application as follows:
cargo build -Z build-std=std,core,alloc,panic_abort --target x86_64-unknown-hermit
The resulting "hypervisor-ready" binary then can be found in target/x86_64-unknown-hermit/debug
.