Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/helloworld-rust1.94.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM rust:1.94.1-bookworm AS build

WORKDIR /src

COPY ./helloworld.rs /src/helloworld.rs

RUN set -xe; \
rustc -o /helloworld /src/helloworld.rs

FROM scratch

COPY --from=build /helloworld /helloworld
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/
COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/
9 changes: 9 additions & 0 deletions examples/helloworld-rust1.94.1/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: helloworld-rust1.75

runtime: base:latest

rootfs: ./Dockerfile

cmd: ["/helloworld"]
57 changes: 57 additions & 0 deletions examples/helloworld-rust1.94.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Rust "Hello, World!"

This directory contains a [Rust](https://www.rust-lang.org/) "Hello, World!" example running on Unikraft.

## Set Up

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.

## Run and Use

Use `kraft` to run the image and start a Unikraft instance:

```bash
kraft run --rm --plat qemu --arch x86_64 .
```

If the `--plat` argument is left out, it defaults to `qemu`.
If the `--arch` argument is left out, it defaults to your system's CPU architecture.

You should see a "Bye, world, from rust 🦀!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
juicy_goblin oci://unikraft.org/base:latest /helloworld 9 seconds ago running 64M qemu/x86_64
```

The instance name is `juicy_goblin`.
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:

```bash
kraft rm juicy_goblin
```

Note that depending on how you modify this example your instance **may** need more memory to run.
To do so, use the `kraft run`'s `-M` flag, for example:

```bash
kraft run --rm --plat qemu --arch x86_64 -M 512M .
```

## `kraft` and `sudo`

Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).

## Learn More

- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
3 changes: 3 additions & 0 deletions examples/helloworld-rust1.94.1/helloworld.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Bye, world, from rust 🦀!");
}