@@ -37,193 +37,8 @@ Rust applications that use the Rust runtime and do not directly use OS services
## Building your own applications
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](https://github.com/hermitcore/rusty-demo).
Have a look at [rusty-demo](https://github.com/hermitcore/rusty-demo).
```sh
cargo new hello_world
cd hello_world
```
To bind the library operating system to the application, add the crate [hermit-sys](https://crates.io/crates/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:
```toml
# 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.
```rust
// src/main.rs
#[cfg(target_os="hermit")]
usehermit_sysas_;
fnmain(){
println!("Hello World!");
}
```
The final step is building the application as follows:
(You can set an easy alias for this in the `.cargo/config` file. Take a look at the [demo](https://github.com/hermitcore/rusty-demo/blob/master/.cargo/config))
The resulting "hypervisor-ready" binary then can be found in `target/x86_64-unknown-hermit/debug`.
## Running RustyHermit
RustyHermit binaries can be run on either uhyve or qemu.
### Using uhyve as Hypervisor
RustyHermit can run within our own hypervisor [*uhyve*](https://github.com/hermitcore/uhyve) , which requires [KVM](https://www.linux-kvm.org/) to create a virtual machine.
Please install the hypervisor as follows:
```sh
cargo +nightly install uhyve --locked
```
Afterwards, your are able to start RustyHermit applications within our hypervisor:
It is important to enable the processor features _fsgsbase_ and _rdtscp_ because it is a prerequisite to boot RustyHermit.
You can provide arguments to the application via the kernel commandline, which you can set with qemu's `-append` option. Since both the kernel and the application can have parameters, they are separated with `--`:
Qemu provides [microvm virtual platform](https://qemu.readthedocs.io/en/latest/system/i386/microvm.html), which is a minimalist machine type without PCI nor ACPI support.
In comparison to a common hypervisor, it has a clearly smaller memory footprint and a faster boot time.
To use this VM type, all default features of RustyHermit has to be disabled (especially PCI and ACPI support).
For instance, the following command builds the smallest version of the [`hello_world` example](https://github.com/hermitcore/rusty-hermit/tree/master/examples/hello_world):
Depending on the virtualized processor, the processor frequency has to pass as kernel argument (`-freq`) to the kernel.
MHz is used as unit of frequency here.
Kernel features like TCP/IP support can be reenabled manually.
For instance, the following command creates a [minimal web-server](https://github.com/hermitcore/rusty-hermit/tree/master/examples/httpd) for Qemu's microvm platform:
RustyHermit uses the lightweight logging crate [log](https://github.com/rust-lang/log) to print kernel messages.
If the environment variable `HERMIT_LOG_LEVEL_FILTER` is set at compile time to a string matching the name of a [LevelFilter](https://docs.rs/log/0.4.8/log/enum.LevelFilter.html), then that value is used for the LevelFilter.
If the environment variable is not set, or the name doesn't match, then LevelFilter::Info is used by default, which is the same as it was before.
For instance, the following command builds RustyHermit with debug messages:
Add the feature `tcp` in the `Cargo.toml`. This includes the network stack [smoltcp](https://github.com/smoltcp-rs/smoltcp) and offers TCP/UDP communication.
`hermi-sys` dependency has to be factored out of `[target.'cfg(target_os = "hermit")'.dependencies]` because it requires features selection for network support to work thus this snippet should be added to `Cargo.toml`
Currently, RustyHermit does only support network interfaces through [virtio](https://www.redhat.com/en/blog/introduction-virtio-networking-and-vhost-net).
To use it, you have to start RustyHermit in Qemu with following command: