diff --git a/examples/helloworld-rust1.94.1/Dockerfile b/examples/helloworld-rust1.94.1/Dockerfile new file mode 100644 index 00000000..117501dc --- /dev/null +++ b/examples/helloworld-rust1.94.1/Dockerfile @@ -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/ diff --git a/examples/helloworld-rust1.94.1/Kraftfile b/examples/helloworld-rust1.94.1/Kraftfile new file mode 100644 index 00000000..09c3edfa --- /dev/null +++ b/examples/helloworld-rust1.94.1/Kraftfile @@ -0,0 +1,9 @@ +spec: v0.6 + +name: helloworld-rust1.75 + +runtime: base:latest + +rootfs: ./Dockerfile + +cmd: ["/helloworld"] diff --git a/examples/helloworld-rust1.94.1/README.md b/examples/helloworld-rust1.94.1/README.md new file mode 100644 index 00000000..310efbea --- /dev/null +++ b/examples/helloworld-rust1.94.1/README.md @@ -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) diff --git a/examples/helloworld-rust1.94.1/helloworld.rs b/examples/helloworld-rust1.94.1/helloworld.rs new file mode 100644 index 00000000..64925b91 --- /dev/null +++ b/examples/helloworld-rust1.94.1/helloworld.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Bye, world, from rust 🦀!"); +}