From 173bf5001ce046d0e7c8d3c91e0099c2faa9d9e6 Mon Sep 17 00:00:00 2001 From: mierepeashi1 Date: Sat, 18 Oct 2025 12:08:10 +0300 Subject: [PATCH 1/3] Introduce cpp-bye program Signed-off-by: mierepeashi1 --- cpp-bye/.gitignore | 1 + cpp-bye/Config.uk | 12 ++ cpp-bye/Makefile | 14 ++ cpp-bye/Makefile.uk | 3 + cpp-bye/README.md | 271 ++++++++++++++++++++++++++++++++++ cpp-bye/README.scripts.md | 54 +++++++ cpp-bye/build.fc.arm64 | 18 +++ cpp-bye/build.fc.x86_64 | 18 +++ cpp-bye/build.qemu.arm64 | 18 +++ cpp-bye/build.qemu.x86_64 | 18 +++ cpp-bye/build.xen.arm64 | 18 +++ cpp-bye/build.xen.x86_64 | 18 +++ cpp-bye/bye.cpp | 7 + cpp-bye/defconfig.fc.arm64 | 11 ++ cpp-bye/defconfig.fc.x86_64 | 8 + cpp-bye/defconfig.qemu.arm64 | 11 ++ cpp-bye/defconfig.qemu.x86_64 | 8 + cpp-bye/defconfig.xen.arm64 | 10 ++ cpp-bye/defconfig.xen.x86_64 | 7 + cpp-bye/fc.arm64.json | 12 ++ cpp-bye/fc.x86_64.json | 12 ++ cpp-bye/run.fc.arm64 | 12 ++ cpp-bye/run.fc.x86_64 | 12 ++ cpp-bye/run.qemu.arm64 | 14 ++ cpp-bye/run.qemu.x86_64 | 13 ++ cpp-bye/run.xen.arm64 | 9 ++ cpp-bye/run.xen.x86_64 | 9 ++ cpp-bye/test.all.sh | 33 +++++ cpp-bye/test.common.sh | 134 +++++++++++++++++ cpp-bye/test.sh | 4 + cpp-bye/test.wrapper.sh | 24 +++ cpp-bye/xen.arm64.cfg | 5 + cpp-bye/xen.x86_64.cfg | 5 + 33 files changed, 823 insertions(+) create mode 100644 cpp-bye/.gitignore create mode 100644 cpp-bye/Config.uk create mode 100644 cpp-bye/Makefile create mode 100644 cpp-bye/Makefile.uk create mode 100644 cpp-bye/README.md create mode 100644 cpp-bye/README.scripts.md create mode 100755 cpp-bye/build.fc.arm64 create mode 100755 cpp-bye/build.fc.x86_64 create mode 100755 cpp-bye/build.qemu.arm64 create mode 100755 cpp-bye/build.qemu.x86_64 create mode 100755 cpp-bye/build.xen.arm64 create mode 100755 cpp-bye/build.xen.x86_64 create mode 100644 cpp-bye/bye.cpp create mode 100644 cpp-bye/defconfig.fc.arm64 create mode 100644 cpp-bye/defconfig.fc.x86_64 create mode 100644 cpp-bye/defconfig.qemu.arm64 create mode 100644 cpp-bye/defconfig.qemu.x86_64 create mode 100644 cpp-bye/defconfig.xen.arm64 create mode 100644 cpp-bye/defconfig.xen.x86_64 create mode 100644 cpp-bye/fc.arm64.json create mode 100644 cpp-bye/fc.x86_64.json create mode 100755 cpp-bye/run.fc.arm64 create mode 100755 cpp-bye/run.fc.x86_64 create mode 100755 cpp-bye/run.qemu.arm64 create mode 100755 cpp-bye/run.qemu.x86_64 create mode 100755 cpp-bye/run.xen.arm64 create mode 100755 cpp-bye/run.xen.x86_64 create mode 100755 cpp-bye/test.all.sh create mode 100644 cpp-bye/test.common.sh create mode 100755 cpp-bye/test.sh create mode 100755 cpp-bye/test.wrapper.sh create mode 100644 cpp-bye/xen.arm64.cfg create mode 100644 cpp-bye/xen.x86_64.cfg diff --git a/cpp-bye/.gitignore b/cpp-bye/.gitignore new file mode 100644 index 0000000..6a3417b --- /dev/null +++ b/cpp-bye/.gitignore @@ -0,0 +1 @@ +/out/ diff --git a/cpp-bye/Config.uk b/cpp-bye/Config.uk new file mode 100644 index 0000000..1a5e719 --- /dev/null +++ b/cpp-bye/Config.uk @@ -0,0 +1,12 @@ +# Configure C++ Bye application. Use C++ libraries. + +config APPCPPBYE +bool "Configure C++ Bye" +default y + + # Select C++ libraries. + select LIBCOMPILER_RT + select LIBCXX + select LIBCXXABI + select LIBUNWIND + select LIBMUSL diff --git a/cpp-bye/Makefile b/cpp-bye/Makefile new file mode 100644 index 0000000..a6a8b6b --- /dev/null +++ b/cpp-bye/Makefile @@ -0,0 +1,14 @@ +UK_ROOT ?= $(PWD)/../repos/unikraft +UK_BUILD ?= $(PWD)/out +UK_APP ?= $(PWD) +LIBS_BASE = $(PWD)/../repos/libs +UK_LIBS := $(LIBS_BASE)/libcxxabi:$(LIBS_BASE)/libcxx:$(LIBS_BASE)/libunwind:$(LIBS_BASE)/compiler-rt:$(LIBS_BASE)/musl + +.PHONY: all + +all: + @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) + +$(MAKECMDGOALS): + @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) $(MAKECMDGOALS) + diff --git a/cpp-bye/Makefile.uk b/cpp-bye/Makefile.uk new file mode 100644 index 0000000..cdbd440 --- /dev/null +++ b/cpp-bye/Makefile.uk @@ -0,0 +1,3 @@ +$(eval $(call addlib,appbyecpp)) + +APPBYECPP_SRCS-y += $(APPBYECPP_BASE)/bye.cpp diff --git a/cpp-bye/README.md b/cpp-bye/README.md new file mode 100644 index 0000000..5653bc2 --- /dev/null +++ b/cpp-bye/README.md @@ -0,0 +1,271 @@ +# C++ Hello on Unikraft + +Build and run a C++ Hello program on Unikraft. +Follow the instructions below to set up, configure, build and run C++ Hello. +Make sure you installed the [requirements](../README.md#requirements). + +## Quick Setup (aka TLDR) + +For a quick setup, run the commands below. +Note that you still need to install the [requirements](../README.md#requirements). + +To build and run the application for `x86_64`, use the commands below: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/libcxxabi || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d ../repos/libs/libcxx || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d ../repos/libs/libunwind || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +make distclean +echo -e 'CONFIG_PLAT_KVM=y\nCONFIG_PLAT_KVM_VMM_QEMU=y\nCONFIG_ARCH_X86_64=y\nCONFIG_LIBCOMPILER_RT=y\nCONFIG_LIBCXX=y\nCONFIG_LIBCXXABI=y\nCONFIG_LIBUNWIND=y\nCONFIG_LIBMUSL=y' > /tmp/defconfig +UK_DEFCONFIG=/tmp/defconfig make defconfig +make -j $(nproc) +qemu-system-x86_64 -nographic -m 8 -cpu max -kernel out/cpp-bye_qemu-x86_64 +``` + +This will configure, build and run the application, resulting in a `Hello from Unikraft!` message being printed. + +To do the same for `AArch64`, run the commands below: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/libcxxabi || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxa> +test -d ../repos/libs/libcxx || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d ../repos/libs/libunwind || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwi> +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/com> +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +make distclean +echo -e 'CONFIG_PLAT_KVM=y\nCONFIG_PLAT_KVM_VMM_QEMU=y\nCONFIG_ARCH_ARM_64=y\nCONFIG_LIBCOMPILER_RT=y\nCONFIG_LIBCXX=y\nCONFIG_LIBCXXABI=y\nCONFIG_LIBUNWIND=y\nCONFIG_LIBMUSL=y' > /tmp/defconfig +UK_DEFCONFIG=/tmp/defconfig make defconfig +make -j $(nproc) +qemu-system-aarch64 -nographic -machine virt -m 8 -cpu max -kernel out/cpp-bye_qemu-arm64 +``` + +Similar to the `x86_64` build, this will result in a `Hello from Unikraft!` message being printed. + +Information about every step and about other types of builds is detailed below. + +## Set Up + +Set up the [`unikraft` repository](https://github.com/unikraft/unikraft). +Clone it in `../repos/unikraft/` if not already cloned: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/libcxxabi || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d ../repos/libs/libcxx || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d ../repos/libs/libunwind || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +``` + +If you want use a custom variant of the repository (e.g. apply your own patch, make modifications), update it accordingly in the `../repos/` directory. + +## Clean + +While not strictly required, it is safest to clean the previous build artifacts: + +```console +make distclean +``` + +## Configure + +To configure the kernel, use: + +```console +make menuconfig +``` + +In the console menu interface, choose the target architecture (x86_64 or ARMv8 or ARMv7) and platform (Xen or KVM/QEMU or KVM/Firecracker). + +The end result will be the creation of the `.config` configuration file. + +## Build + +Build the application for the current configuration: + +```console +make -j $(nproc) +``` + +This results in the creation of the `out/` directory storing the build artifacts. +The unikernel application image file is `out/cpp-bye_-`, where `` is the platform name (`qemu`, `fc`, `xen`), and `` is the architecture (`x86_64` or `arm64`). + +### Use a Different Compiler + +If you want to use a different compiler, such as a Clang or a different GCC version, pass the `CC` variable to `make`. + +To build with Clang, use the commands below: + +```console +make properclean +make CC=clang -j $(nproc) +``` + +Note that Clang >= 14 is required to build Unikraft. + +To build with another GCC version, use the commands below: + +```console +make properclean +make CC=gcc- -j $(nproc) +``` + +where `` is the GCC version, such as `11`, `12`. + +Note that GCC >= 8 is required to build Unikraft. + +## Clean Up + +Doing a new configuration, or a new build may require cleaning up the configuration and build artifacts. + +In order to remove the build artifacts, use: + +```console +make clean +``` + +In order to remove fetched files also, that is the removal of the `out/` directory, use: + +```console +make properclean +``` + +In order to remove the generated `.config` file as well, use: + +```console +make distclean +``` + +## Run + +Run the resulting image using the corresponding platform tool. +Firecracker requires KVM support. +Xen requires a system with Xen installed. + +A successful run will show a message such as the one below: + +```text +Booting from ROM..Powered by +o. .o _ _ __ _ +Oo Oo ___ (_) | __ __ __ _ ' _) :_ +oO oO ' _ `| | |/ / _)' _` | |_| _) +oOo oOO| | | | | (| | | (_) | _) :_ + OoOoO ._, ._:_:_,\_._, .__,_:_, \___) + Calypso 0.17.0~5d38d108 +Hello from Unikraft! +``` + +### Run on QEMU/x86_64 + +```console +qemu-system-x86_64 -nographic -m 8 -cpu max -kernel out/cpp-bye_qemu-x86_64 +``` + +### Run on QEMU/ARM64 + +```console +qemu-system-aarch64 -nographic -machine virt -m 8 -cpu max -kernel out/cpp-bye_qemu-arm64 +``` + +### Run on Firecracker/x86_64 + +```console +rm -f firecracker.socket +firecracker-x86_64 --config-file fc.x86_64.json --api-sock firecracker.socket +``` + +The user running the above command must be able to use KVM. +Typically this means being part of the `kvm` group. +Otherwise, run the command above as root or prefixed by `sudo`. + +### Run on Firecracker/ARM64 + +```console +rm -f firecracker.socket +firecracker-aarch64 --config-file fc.arm64.json --api-sock firecracker.socket +``` + +The user running the above command must be able to use KVM. +Typically this means being part of the `kvm` group. +Otherwise, run the command above as the `root` account or prefixed by `sudo`. + +### Run on Xen/x86_64 + +```console +sudo xl create -c xen.x86_64.cfg +``` + +You need use `sudo` or the `root` account to run Xen. + +### Run on Xen/ARM64 + +```console +sudo xl create -c xen.arm64.cfg +``` + +You need use `sudo` or the `root` account to run Xen. + +## Customize +### Update the Unikraft Core Code + +If updating the Unikraft core code in the `../repos/unikraft/` directory, you then go through the [configure](#configure), [build](#build) and [run](#run) steps. + +### Add Other Source Code Files + +The current configuration use a single source file: `bye.cpp`. +If looking to add another file to the build, update the [`Makefile.uk`](Makefile.uk) file. + +For example, to add a new file `support.cpp` to the build, update the [`Makefile.uk`](Makefile.uk) file to: + +```make +$(eval $(call addlib,appbyeworldcpp)) + +APPHELLOWORLDCPP_SRCS-y += $(APPHELLOWORLDCPP_BASE)/bye.cpp +APPHELLOWORLDCPP_SRCS-y += $(APPHELLOWORLDCPP_BASE)/support.cpp +``` + +To add a new include directory, such as a local `include/` directory, update the [`Makefile.uk`](Makefile.uk) file to: + +```make +$(eval $(call addlib,appbyeworldcpp)) + +APPHELLOWORLDCPP_SRCS-y += $(APPHELLOWORLDCPP_BASE)/bye.cpp +CINLUDES-y += -I$(APPHELLOWORLDCPP_BASE)/include +``` + +Then go through the [configure](#configure), [build](#build) and [run](#run) steps. + +### Add Other Libraries + +It may be the case that you want to add a library to the build, in order to test the library or a certain feature. +If that is the case, update the `UK_LIBS` variable in the [`Makefile`](Makefile). + +For example, to add the Musl library to the build, clone the [`lib-musl` library repository](https://github.com/unikraft/lib-musl): + +```console +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +``` + +and update the `UK_LIBS` line the [`Makefile`](Makefile) to: + +```make +UK_LIBS ?= $(LIBS_BASE)/musl +``` + +To add another library, such as LWIP, clone the [corresponding `lib-lwip` repository](https://github.com/unikraft/lib-musl): + +```console +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +``` + +and update the `UK_LIBS` line the [`Makefile`](Makefile) to: + +```make +UK_LIBS ?= $(LIBS_BASE)/musl:$(LIBS_BASE)/lwip +``` + +Then go through the [configure](#configure), [build](#build) and [run](#run) steps. diff --git a/cpp-bye/README.scripts.md b/cpp-bye/README.scripts.md new file mode 100644 index 0000000..556f65b --- /dev/null +++ b/cpp-bye/README.scripts.md @@ -0,0 +1,54 @@ +# Scripts for C++ Bye on Unikraft + +These are companions instruction to the main instructions in the [`README`](README.md). + +Use scripts as quick actions for building and running C++ Bye on Unikraft. + +## Build for / : + +```console +./build.. +``` + +e.g.: + +```console +./build.qemu.x86_64 +./build.qemu.arm64 +./build.fc.x86_64 +./build.xen.arm64 +``` + +## Build for / using a different compiler + +```console +CC=/path/to/compiler ./build.. +``` + +e.g. + +```console +CC=/usr/bin/gcc-12 ./build.qemu.x86_64 +CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.qemu.arm64 +CC=/usr/bin/clang ./build.qemu.x86_64 +CC=/usr/bin/clang ./build.qemu.arm64 +CC=/usr/bin/gcc-12 ./build.fc.x86_64 +CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.fc.arm64 +CC=/usr/bin/clang ./build.fc.x86_64 +CC=/usr/bin/clang ./build.fc.arm64 +``` + +## Run on / + +```console +./run.. +``` + +e.g. + +```console +./run.qemu.x86_64 +./run.qemu.arm64 +./run.fc.x86_64 +./run.xen.arm64 +``` diff --git a/cpp-bye/build.fc.arm64 b/cpp-bye/build.fc.arm64 new file mode 100755 index 0000000..daf9595 --- /dev/null +++ b/cpp-bye/build.fc.arm64 @@ -0,0 +1,18 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/cpp-bye/build.fc.x86_64 b/cpp-bye/build.fc.x86_64 new file mode 100755 index 0000000..6c65200 --- /dev/null +++ b/cpp-bye/build.fc.x86_64 @@ -0,0 +1,18 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/cpp-bye/build.qemu.arm64 b/cpp-bye/build.qemu.arm64 new file mode 100755 index 0000000..db95a5c --- /dev/null +++ b/cpp-bye/build.qemu.arm64 @@ -0,0 +1,18 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/cpp-bye/build.qemu.x86_64 b/cpp-bye/build.qemu.x86_64 new file mode 100755 index 0000000..efb1e9f --- /dev/null +++ b/cpp-bye/build.qemu.x86_64 @@ -0,0 +1,18 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/cpp-bye/build.xen.arm64 b/cpp-bye/build.xen.arm64 new file mode 100755 index 0000000..2f3569c --- /dev/null +++ b/cpp-bye/build.xen.arm64 @@ -0,0 +1,18 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.xen.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/cpp-bye/build.xen.x86_64 b/cpp-bye/build.xen.x86_64 new file mode 100755 index 0000000..8d1a511 --- /dev/null +++ b/cpp-bye/build.xen.x86_64 @@ -0,0 +1,18 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi +test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx +test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind +test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.xen.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/cpp-bye/bye.cpp b/cpp-bye/bye.cpp new file mode 100644 index 0000000..ea57aa2 --- /dev/null +++ b/cpp-bye/bye.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::cout << "Bye from Unikraft!" << std::endl; + return 0; +} diff --git a/cpp-bye/defconfig.fc.arm64 b/cpp-bye/defconfig.fc.arm64 new file mode 100644 index 0000000..5503174 --- /dev/null +++ b/cpp-bye/defconfig.fc.arm64 @@ -0,0 +1,11 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBCOMPILER_RT=y +CONFIG_LIBCXX=y +CONFIG_LIBCXXABI=y +CONFIG_LIBUNWIND=y +CONFIG_LIBMUSL=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/cpp-bye/defconfig.fc.x86_64 b/cpp-bye/defconfig.fc.x86_64 new file mode 100644 index 0000000..17448ca --- /dev/null +++ b/cpp-bye/defconfig.fc.x86_64 @@ -0,0 +1,8 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBCOMPILER_RT=y +CONFIG_LIBCXX=y +CONFIG_LIBCXXABI=y +CONFIG_LIBUNWIND=y +CONFIG_LIBMUSL=y diff --git a/cpp-bye/defconfig.qemu.arm64 b/cpp-bye/defconfig.qemu.arm64 new file mode 100644 index 0000000..86279d2 --- /dev/null +++ b/cpp-bye/defconfig.qemu.arm64 @@ -0,0 +1,11 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBCOMPILER_RT=y +CONFIG_LIBCXX=y +CONFIG_LIBCXXABI=y +CONFIG_LIBUNWIND=y +CONFIG_LIBMUSL=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/cpp-bye/defconfig.qemu.x86_64 b/cpp-bye/defconfig.qemu.x86_64 new file mode 100644 index 0000000..1247389 --- /dev/null +++ b/cpp-bye/defconfig.qemu.x86_64 @@ -0,0 +1,8 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBCOMPILER_RT=y +CONFIG_LIBCXX=y +CONFIG_LIBCXXABI=y +CONFIG_LIBUNWIND=y +CONFIG_LIBMUSL=y diff --git a/cpp-bye/defconfig.xen.arm64 b/cpp-bye/defconfig.xen.arm64 new file mode 100644 index 0000000..7f701f5 --- /dev/null +++ b/cpp-bye/defconfig.xen.arm64 @@ -0,0 +1,10 @@ +CONFIG_PLAT_XEN=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBCOMPILER_RT=y +CONFIG_LIBCXX=y +CONFIG_LIBCXXABI=y +CONFIG_LIBUNWIND=y +CONFIG_LIBMUSL=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/cpp-bye/defconfig.xen.x86_64 b/cpp-bye/defconfig.xen.x86_64 new file mode 100644 index 0000000..e644e18 --- /dev/null +++ b/cpp-bye/defconfig.xen.x86_64 @@ -0,0 +1,7 @@ +CONFIG_PLAT_XEN=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBCOMPILER_RT=y +CONFIG_LIBCXX=y +CONFIG_LIBCXXABI=y +CONFIG_LIBUNWIND=y +CONFIG_LIBMUSL=y diff --git a/cpp-bye/fc.arm64.json b/cpp-bye/fc.arm64.json new file mode 100644 index 0000000..731c818 --- /dev/null +++ b/cpp-bye/fc.arm64.json @@ -0,0 +1,12 @@ +{ + "boot-source": { + "kernel_image_path": "out/cpp-hello_fc-arm64" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 8, + "smt": false, + "track_dirty_pages": false + } +} diff --git a/cpp-bye/fc.x86_64.json b/cpp-bye/fc.x86_64.json new file mode 100644 index 0000000..4e5c84e --- /dev/null +++ b/cpp-bye/fc.x86_64.json @@ -0,0 +1,12 @@ +{ + "boot-source": { + "kernel_image_path": "out/cpp-hello_fc-x86_64" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 8, + "smt": false, + "track_dirty_pages": false + } +} diff --git a/cpp-bye/run.fc.arm64 b/cpp-bye/run.fc.arm64 new file mode 100755 index 0000000..49e6a52 --- /dev/null +++ b/cpp-bye/run.fc.arm64 @@ -0,0 +1,12 @@ +#!/bin/sh + +if test ! -f "out/cpp-bye_fc-arm64"; then + echo "No kernel file out/cpp-bye_fc-arm64." 1>&2 + echo "Did you run ./build.fc.arm64 ?" 1>&2 + exit 1 +fi + +rm -f firecracker.socket +firecracker-aarch64 \ + --api-sock firecracker.socket \ + --config-file fc.arm64.json diff --git a/cpp-bye/run.fc.x86_64 b/cpp-bye/run.fc.x86_64 new file mode 100755 index 0000000..556294f --- /dev/null +++ b/cpp-bye/run.fc.x86_64 @@ -0,0 +1,12 @@ +#!/bin/sh + +if test ! -f "out/cpp-bye_fc-x86_64"; then + echo "No kernel file out/cpp-bye_fc-x86_64." 1>&2 + echo "Did you run ./build.fc.x86_64 ?" 1>&2 + exit 1 +fi + +rm -f firecracker.socket +firecracker-x86_64 \ + --api-sock firecracker.socket \ + --config-file fc.x86_64.json diff --git a/cpp-bye/run.qemu.arm64 b/cpp-bye/run.qemu.arm64 new file mode 100755 index 0000000..2e0e8fa --- /dev/null +++ b/cpp-bye/run.qemu.arm64 @@ -0,0 +1,14 @@ +#!/bin/sh + +if test ! -f "out/cpp-bye_qemu-arm64"; then + echo "No kernel file out/cpp-bye_qemu-arm64." 1>&2 + echo "Did you run ./build.qemu.arm64 ?" 1>&2 + exit 1 +fi + +qemu-system-aarch64 \ + -nographic \ + -machine virt \ + -m 8 \ + -cpu max \ + -kernel out/cpp-bye_qemu-arm64 diff --git a/cpp-bye/run.qemu.x86_64 b/cpp-bye/run.qemu.x86_64 new file mode 100755 index 0000000..455a916 --- /dev/null +++ b/cpp-bye/run.qemu.x86_64 @@ -0,0 +1,13 @@ +#!/bin/sh + +if test ! -f "out/cpp-bye_qemu-x86_64"; then + echo "No kernel file out/cpp-bye_qemu-x86_64." 1>&2 + echo "Did you run ./build.qemu.x86_64 ?" 1>&2 + exit 1 +fi + +qemu-system-x86_64 \ + -nographic \ + -m 8 \ + -cpu max \ + -kernel out/cpp-bye_qemu-x86_64 diff --git a/cpp-bye/run.xen.arm64 b/cpp-bye/run.xen.arm64 new file mode 100755 index 0000000..c563728 --- /dev/null +++ b/cpp-bye/run.xen.arm64 @@ -0,0 +1,9 @@ +#!/bin/sh + +if test ! -f "out/cpp-bye_xen-arm64"; then + echo "No kernel file out/cpp-bye_xen-arm64." 1>&2 + echo "Did you run ./build.xen.arm64 ?" 1>&2 + exit 1 +fi + +sudo xl create -c xen.arm64.cfg diff --git a/cpp-bye/run.xen.x86_64 b/cpp-bye/run.xen.x86_64 new file mode 100755 index 0000000..adb05da --- /dev/null +++ b/cpp-bye/run.xen.x86_64 @@ -0,0 +1,9 @@ +#!/bin/sh + +if test ! -f "out/cpp-bye_xen-x86_64"; then + echo "No kernel file out/cpp-bye_xen-x86_64." 1>&2 + echo "Did you run ./build.xen.x86_64 ?" 1>&2 + exit 1 +fi + +sudo xl create -c xen.x86_64.cfg diff --git a/cpp-bye/test.all.sh b/cpp-bye/test.all.sh new file mode 100755 index 0000000..70b746d --- /dev/null +++ b/cpp-bye/test.all.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +test_build() +{ + printf "%-46s ... " build."$1" + ./build."$1" > log.build."$1" 2>&1 + if test $? -eq 0; then + echo "PASSED" + else + echo "FAILED" + fi +} + +test_build_run() +{ + printf "%-46s ... " build."$1" + ./build."$1" > log.build."$1" 2>&1 + if test $? -eq 0; then + echo "PASSED" + else + echo "FAILED" + fi + + printf " %-42s ... " run."$1" + ./test.wrapper.sh ./run."$1" 2> log.run."$1" +} + +test_build_run qemu.x86_64 +test_build_run qemu.arm64 +test_build_run fc.x86_64 +test_build fc.arm64 +test_build xen.x86_64 +test_build xen.arm64 diff --git a/cpp-bye/test.common.sh b/cpp-bye/test.common.sh new file mode 100644 index 0000000..897205b --- /dev/null +++ b/cpp-bye/test.common.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +if test -z "$log_file"; then + log_file="/dev/null" +fi + +clean_up() +{ + { + # Clean up any previous instances. + sudo pkill -9 qemu-system + sudo pkill -9 firecracker + kraft stop --all + kraft rm --all + sudo kraft stop --all + sudo kraft rm --all + + # Remove previously created network interfaces. + sudo ip link set dev tap0 down + sudo ip link del dev tap0 + sudo ip link set dev virbr0 down + sudo ip link del dev virbr0 + } > /dev/null 2>&1 +} + +start_instance() +{ + # Start instance. + setsid --fork "$start_command" 1>&2 & + if test $? -ne 0; then + echo "Cannot start instance" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_ping() +{ + host="$1" + + # Connect to instance. + ping -c 1 "$host" 1>&2 + if test $? -ne 0; then + echo "Cannot ping $host" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_curl_connect() +{ + host="$1" + port="$2" + + # Query instance. + curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" 1>&2 + if test $? -ne 0; then + echo "Cannot connect to $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_curl_check_reply() +{ + host="$1" + port="$2" + message="$3" + + # Check server message contents. + curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" | grep "$message" 1>&2 + if test $? -ne 0; then + echo "Wrong message from $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_netcat_connect() +{ + host="$1" + port="$2" + + # Check connection. + netcat -w 3 "$host" "$port" < /dev/null 1>&2 + if test $? -ne 0; then + echo "Cannot connect to $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_redis_connect() +{ + host="$1" + port="$2" + + redis-cli -h "$host" -p "$port" < /dev/null 1>&2 + if test $? -ne 0; then + echo "Cannot connect client to Redis server at $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_redis_cli() +{ + host="$1" + port="$2" + + redis-cli -h "$host" -p "$port" set a 1 1>&2 + redis-cli -h "$host" -p "$port" get a 1>&2 + if test $? -eq 1; then + echo "FAILED" + echo "Cannot talk to Redis server at $host:$port" 1>&2 + clean_up + exit 1 + fi +} + +end_with_success() +{ + echo "PASSED" + clean_up + exit 0 +} + +start_command="$1" diff --git a/cpp-bye/test.sh b/cpp-bye/test.sh new file mode 100755 index 0000000..c18e81e --- /dev/null +++ b/cpp-bye/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +. ./test.common.sh + diff --git a/cpp-bye/test.wrapper.sh b/cpp-bye/test.wrapper.sh new file mode 100755 index 0000000..7182d26 --- /dev/null +++ b/cpp-bye/test.wrapper.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +. ./test.common.sh + +if test $# -ne 1; then + echo "Unknown arguments." 1>&2 + echo "Usage: $0 " 1>&2 + exit 1 +fi + +# Clean up previous instances. +clean_up + +# Start instance. +start_instance 2>&1 | grep "Hello from Unikraft!" 1>&2 +if test $? -ne 0; then + echo "Wrong message printed." 1>&2 + echo "FAILED" + clean_up + exit 1 +fi + +# Stop instance. +end_with_success diff --git a/cpp-bye/xen.arm64.cfg b/cpp-bye/xen.arm64.cfg new file mode 100644 index 0000000..c860dc9 --- /dev/null +++ b/cpp-bye/xen.arm64.cfg @@ -0,0 +1,5 @@ +name = "cpp-bye" +vcpus = "1" +kernel = "./out/cpp-bye_xen-arm64" +memory = "8" +type = "pv" diff --git a/cpp-bye/xen.x86_64.cfg b/cpp-bye/xen.x86_64.cfg new file mode 100644 index 0000000..8faf6c2 --- /dev/null +++ b/cpp-bye/xen.x86_64.cfg @@ -0,0 +1,5 @@ +name = "cpp-bye" +vcpus = "1" +kernel = "./out/cpp-bye_xen-x86_64" +memory = "8" +type = "pv" From bea4d904b1013db034601718e23193565d91ebc0 Mon Sep 17 00:00:00 2001 From: mierepeashi1 Date: Sat, 18 Oct 2025 12:10:05 +0300 Subject: [PATCH 2/3] Introduce python3-bye program Signed-off-by: mierepeashi1 --- python3-bye/.gitignore | 2 + python3-bye/Config.uk | 30 +++ python3-bye/Dockerfile | 7 + python3-bye/Makefile | 13 + python3-bye/Makefile.uk | 0 python3-bye/README.md | 407 ++++++++++++++++++++++++++++++ python3-bye/README.scripts.md | 54 ++++ python3-bye/build.fc.arm64 | 17 ++ python3-bye/build.fc.x86_64 | 17 ++ python3-bye/build.qemu.arm64 | 17 ++ python3-bye/build.qemu.x86_64 | 17 ++ python3-bye/build.xen.arm64 | 17 ++ python3-bye/build.xen.x86_64 | 17 ++ python3-bye/defconfig.fc.arm64 | 15 ++ python3-bye/defconfig.fc.x86_64 | 12 + python3-bye/defconfig.qemu.arm64 | 15 ++ python3-bye/defconfig.qemu.x86_64 | 12 + python3-bye/defconfig.xen.arm64 | 14 + python3-bye/defconfig.xen.x86_64 | 11 + python3-bye/fc.arm64.json | 14 + python3-bye/fc.x86_64.json | 14 + python3-bye/hello.py | 9 + python3-bye/run.fc.arm64 | 22 ++ python3-bye/run.fc.x86_64 | 22 ++ python3-bye/run.qemu.arm64 | 24 ++ python3-bye/run.qemu.x86_64 | 23 ++ python3-bye/run.xen.arm64 | 17 ++ python3-bye/run.xen.x86_64 | 17 ++ python3-bye/test.all.sh | 33 +++ python3-bye/test.common.sh | 146 +++++++++++ python3-bye/test.sh | 3 + python3-bye/test.wrapper.sh | 24 ++ python3-bye/xen.arm64.cfg | 7 + python3-bye/xen.x86_64.cfg | 7 + 34 files changed, 1076 insertions(+) create mode 100644 python3-bye/.gitignore create mode 100644 python3-bye/Config.uk create mode 100644 python3-bye/Dockerfile create mode 100644 python3-bye/Makefile create mode 100644 python3-bye/Makefile.uk create mode 100644 python3-bye/README.md create mode 100644 python3-bye/README.scripts.md create mode 100755 python3-bye/build.fc.arm64 create mode 100755 python3-bye/build.fc.x86_64 create mode 100755 python3-bye/build.qemu.arm64 create mode 100755 python3-bye/build.qemu.x86_64 create mode 100755 python3-bye/build.xen.arm64 create mode 100755 python3-bye/build.xen.x86_64 create mode 100644 python3-bye/defconfig.fc.arm64 create mode 100644 python3-bye/defconfig.fc.x86_64 create mode 100644 python3-bye/defconfig.qemu.arm64 create mode 100644 python3-bye/defconfig.qemu.x86_64 create mode 100644 python3-bye/defconfig.xen.arm64 create mode 100644 python3-bye/defconfig.xen.x86_64 create mode 100644 python3-bye/fc.arm64.json create mode 100644 python3-bye/fc.x86_64.json create mode 100644 python3-bye/hello.py create mode 100755 python3-bye/run.fc.arm64 create mode 100755 python3-bye/run.fc.x86_64 create mode 100755 python3-bye/run.qemu.arm64 create mode 100755 python3-bye/run.qemu.x86_64 create mode 100755 python3-bye/run.xen.arm64 create mode 100755 python3-bye/run.xen.x86_64 create mode 100755 python3-bye/test.all.sh create mode 100644 python3-bye/test.common.sh create mode 100755 python3-bye/test.sh create mode 100755 python3-bye/test.wrapper.sh create mode 100644 python3-bye/xen.arm64.cfg create mode 100644 python3-bye/xen.x86_64.cfg diff --git a/python3-bye/.gitignore b/python3-bye/.gitignore new file mode 100644 index 0000000..cbe8cbb --- /dev/null +++ b/python3-bye/.gitignore @@ -0,0 +1,2 @@ +/rootfs/ +/9pfs-rootfs/ diff --git a/python3-bye/Config.uk b/python3-bye/Config.uk new file mode 100644 index 0000000..1ff4fdf --- /dev/null +++ b/python3-bye/Config.uk @@ -0,0 +1,30 @@ +# Configure Python3 application for a build that uses initrd to pass the root +# filesystem. +# Enable initrd / CPIO-related core components and configurations. + +config APPBYEPYTHON3 + bool "Configure Python3 application with initrd as rootfs" + default y + + # Select application library (Python3). Use main function in + # application library. Other libraries, such as Musl or LWIP, are + # selected as dependencies of Python3. + select LIBPYTHON3 + select LIBPYTHON3_MAIN_FUNCTION + + # Select filesystem core components: vfscore, cpio, ramfs, devfs. For + # each select corresponding features. The other core components are + # selected as dependencies of Python3. + select LIBVFSCORE + select LIBVFSCORE_AUTOMOUNT_UP + select LIBRAMFS + select LIBUKCPIO + + # Pass environment variables as command line arguments. This is + # required for passing the `PYTHONPATH` environment variable. + select LIBPOSIX_ENVIRON + select LIBPOSIX_ENVIRON_LIBPARAM + + # Add randomness support. + select LIBUKRANDOM + select LIBUKRANDOM_GETRANDOM diff --git a/python3-bye/Dockerfile b/python3-bye/Dockerfile new file mode 100644 index 0000000..826b73a --- /dev/null +++ b/python3-bye/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.10.11 AS base + +FROM scratch + +COPY --from=base /usr/local/lib/python3.10 /usr/local/lib/python3.10 + +COPY ./hello.py /app/hello.py diff --git a/python3-bye/Makefile b/python3-bye/Makefile new file mode 100644 index 0000000..6f25b0c --- /dev/null +++ b/python3-bye/Makefile @@ -0,0 +1,13 @@ +UK_ROOT ?= $(PWD)/../repos/unikraft +UK_BUILD ?= $(PWD)/out +UK_APP ?= $(PWD) +LIBS_BASE = $(PWD)/../repos/libs +UK_LIBS ?= $(LIBS_BASE)/musl:$(LIBS_BASE)/lwip:$(LIBS_BASE)/python3:$(LIBS_BASE)/compiler-rt + +.PHONY: all + +all: + @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) + +$(MAKECMDGOALS): + @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) $(MAKECMDGOALS) diff --git a/python3-bye/Makefile.uk b/python3-bye/Makefile.uk new file mode 100644 index 0000000..e69de29 diff --git a/python3-bye/README.md b/python3-bye/README.md new file mode 100644 index 0000000..bbd1d7b --- /dev/null +++ b/python3-bye/README.md @@ -0,0 +1,407 @@ +# Python3 Hello on Unikraft + +Build and run a Python3 Hello program on Unikraft. +Follow the instructions below to set up, configure, build and run Python3 Hello. +Make sure you installed the [requirements](../README.md#requirements). + +## Quick Setup (aka TLDR) + +For a quick setup, run the commands below. +Note that you still need to install the [requirements](../README.md#requirements). + +To build and run the application for `x86_64`, use the commands below: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ....//repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +make distclean +> /tmp/defconfig echo 'CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y' +UK_DEFCONFIG=/tmp/defconfig make defconfig +make -j $(nproc) +test -d ./rootfs/ || docker build -o ./rootfs -f Dockerfile . +test -f initrd.cpio || ../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ +qemu-system-x86_64 \ + -nographic \ + -m 256 \ + -cpu max \ + -append "python3-bye_qemu-x86_64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-x86_64 \ + -initrd ./initrd.cpio +``` + +This will configure, build and run Python3 Hello on Unikraft. +You can see how to test it in the ["Test" section](#test). +To close the virtual machine, see the instructions in the ["Close QEMU" section](#close-qemu). + +To do the same for `AArch64`, run the commands below: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ....//repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +make distclean +> /tmp/defconfig echo 'CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n' +UK_DEFCONFIG=/tmp/defconfig make defconfig +make -j $(nproc) +test -d ./rootfs/ || docker build -o ./rootfs -f Dockerfile . +test -f initrd.cpio || ../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ +qemu-system-aarch64 \ + -nographic \ + -machine virt \ + -m 256 \ + -cpu max \ + -append "python3-bye_qemu-arm64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-arm64 \ + -initrd ./initrd.cpio +``` + +Similar to the `x86_64` build, this will configure, build and run Python3 Hello on Unikraft. + +Information about every step and about other types of builds is detailed below. + +## Set Up + +Set up the required repositories. +Clone them in `../repos/` if not already cloned: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ....//repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt +``` + +If you want use a custom variant of a repository (e.g. apply your own patch, make modifications), update it accordingly in the `../repos/` directory. + +## Clean + +While not strictly required, it is safest to clean the previous build artifacts: + +```console +make distclean +``` + +## Configure + +To configure the kernel, use: + +```console +make menuconfig +``` + +In the console menu interface, choose the target architecture (x86_64 or ARMv8 or ARMv7) and platform (Xen or KVM/QEMU or KVM/Firecracker). +After choosing the target architecture and the platform, go back to the `Architecture Selection` menu entry and update the `Stack size page order` to `10`. +Then save the configuration. + +The end result will be the creation of the `.config` configuration file. + +## Build + +Build the application for the current configuration: + +```console +make -j $(nproc) +``` + +This results in the creation of the `out/` directory storing the build artifacts. +The unikernel application image file is `out/python3-bye_-`, where `` is the platform name (`qemu`, `fc`, `xen`), and `` is the architecture (`x86_64` or `arm64`). + +### Use a Different Compiler + +If you want to use a different compiler, such as a Clang or a different GCC version, pass the `CC` variable to `make`. + +To build with Clang, use the commands below: + +```console +make properclean +make CC=clang -j $(nproc) +``` + +Note that Clang >= 14 is required to build Unikraft. + +To build with another GCC version, use the commands below: + +```console +make properclean +make CC=gcc- -j $(nproc) +``` + +where `` is the GCC version, such as `11`, `12`. + +Note that GCC >= 8 is required to build Unikraft. + +### Build the Filesystem + +The filesystem is to be packed into `initrd.cpio`, an initial ramdisk CPIO file. + +First create the root filesystem from the [`Dockerfile`](Dockerfile) into the `./rootfs/` directory: + +```console +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . +``` + +Then pack the `./rootfs/` directory in the `initrd.cpio` file: + +```console +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ +``` + +## Clean Up + +Doing a new configuration, or a new build, may require cleaning up the configuration and build artifacts. + +In order to remove the build artifacts, use: + +```console +make clean +``` + +In order to remove fetched files also, that is the removal of the `out/` directory, use: + +```console +make properclean +``` + +In order to remove the generated `.config` file as well, use: + +```console +make distclean +``` + +## Run + +Run the resulting image using the corresponding platform tool. +Firecracker requires KVM support. +Xen requires a system with Xen installed. + +A successful run will show a message such as the one below: + +```text +Powered by +o. .o _ _ __ _ +Oo Oo ___ (_) | __ __ __ _ ' _) :_ +oO oO ' _ `| | |/ / _)' _` | |_| _) +oOo oOO| | | | | (| | | (_) | _) :_ + OoOoO ._, ._:_:_,\_._, .__,_:_, \___) + Calypso 0.17.0~ca507107 +Hello from Unikraft! +``` + +This means that Python3 Hello runs on Unikraft. + +The shutdown mechanism doesn't currently work for Python3; +To close the virtual machine, see the instructions in the ["Close QEMU" section](#close-qemu). + +### Run on QEMU/x86_64 + +```console +qemu-system-x86_64 \ + -nographic \ + -m 256 \ + -cpu max \ + -append "python3-bye_qemu-x86_64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-x86_64 \ + -initrd ./initrd.cpio +``` + +### Run on QEMU/ARM64 + +```console +qemu-system-aarch64 \ + -nographic \ + -machine virt \ + -m 256 \ + -cpu max \ + -append "python3-bye_qemu-arm64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-arm64 \ + -initrd ./initrd.cpio +``` + +### Run on Firecracker/x86_64 + +```console +rm -f firecracker.socket +firecracker-x86_64 --config-file fc.x86_64.json --api-sock firecracker.socket +``` + +The user running the above command must be able to use KVM. +Typically this means being part of the `kvm` group. +Otherwise, run the command above as root or prefixed by `sudo`. + +### Run on Firecracker/ARM64 + +```console +rm -f firecracker.socket +firecracker-aarch64 --config-file fc.arm64.json --api-sock firecracker.socket +``` + +The user running the above command must be able to use KVM. +Typically this means being part of the `kvm` group. +Otherwise, run the command above as the `root` account or prefixed by `sudo`. + +### Run on Xen/x86_64 + +```console +sudo xl create -c xen.x86_64.cfg +``` + +You need use `sudo` or the `root` account to run Xen. + +### Run on Xen/ARM64 + +```console +sudo xl create -c xen.arm64.cfg +``` + +You need use `sudo` or the `root` account to run Xen. + +## Close + +The shutdown mechanism doesn't currently work with Python3. +So the virtual machine is left hanging after printing the Hello message. +Closing the virtual machine depends on the platform. + +### Close QEMU + +To close the QEMU virtual machine, use the `Ctrl+a x` keyboard shortcut; +that is press the `Ctrl` and `a` keys at the same time and then, separately, press the `x` key. + +### Close Firecracker + +To close the Firecracker virtual machine, open another console and use the command: + +```console +sudo pkill -f firecracker +``` + +### Close Xen + +To close the Xen virtual machine, open another console and use the command: + +```console +sudo xl destroy python3-bye +``` + +## Customize + +### Use a Different Application + +The current program is [`bye.py`](bye.py), a simple Hello-printing Python3 program. + +In order to use another program, potentially comprising of multiple source code files, do the following: + +1. Create the corresponding Python3 source code files. + Ideally, test them locally. + +1. Update the `COPY` command in the [`Dockerfile`](Dockerfile) to copy all source code files. + +1. Update the command line arguments for starting the virtual machine, to use the new command line arguments instead of `-- /app/bye.py`. + For QEMU this means updating the `qemu-system-x86_64` or `qemu-system-aarch64` command line. + For Firecracker this means updating the `fc.x86_64.json` or the `fc.arm64.json` file. + For Xen this means updating the `xen.x86_64.cfg` or the `xen.arm64.cfg` file. + +### Use a Different Python Filesystem + +Based on the [`Dockerfile`](Dockerfile), the application uses a filesystem for version `3.10.11` of Python. +This is because the Python interpreter build is for `3.10.11`, as seen [in the `Makefile.uk` for `unikraft/lib-python3`](https://github.com/unikraft/lib-python3/blob/staging/Makefile.uk#L54). + +You can use another filesystem for another Python version, while still using the Python interpreter build for `3.10.11`. +For example, to use the filesystem for Python `3.12.7`, do the following: + +1. Update the [`Dockerfile`](Dockerfile) to use `FROM python:3.12.7 ...`. + +1. Update the `COPY --from=base` line in the [`Dockerfile`](Dockerfile) to use `python3.12` instead of `python3.10`. + +1. Update the command line arguments for starting the virtual machine, to use an updated value for the `PYTHONPATH` environment variable. + As above, use `python3.12` instead of `python3.10`. + +### Use a Different Filesystem Type for QEMU + +You can use [`9pfs`](https://github.com/unikraft/unikraft/tree/staging/lib/9pfs) as an alternate filesystem to initrd. +Note that 9pfs does not work with Firecracker. +And it requires re-building Xen to add 9pfs support. +Below find instructions on running Python3 Hello on QEMU with 9pfs support. + +You need to use these contents for the [`Config.uk`](Config.uk) configuration file: + +```text +config APPPYTHON3 +bool "Configure Python3 Hello application with initrd as rootfs" +default y + select LIBPYTHON3 + select LIBPYTHON3_MAIN_FUNCTION + select LIBVFSCORE + select LIBVFSCORE_AUTOMOUNT_UP + select LIBUK9P + select LIB9PFS + select LIBPOSIX_ENVIRON + select LIBPOSIX_ENVIRON_LIBPARAM +``` + +This means you replace these two lines in [`Config.uk`](Config.uk): + +```text + select LIBRAMFS + select LIBUKCPIO +``` + +with these lines: + +```text + select LIBUK9P + select LIB9PFS +``` + +Now go through the [configure](#configure) and [build](#build) steps. + +Finally, after configuring networking, use the commands below to run Python3 Hello on QEMU/x86_64 with 9pfs support: + +```console +# Create a copy of the filesystem to be mounted as 9pfs. +rm -fr ./9pfs-rootfs +cp -r ./rootfs ./9pfs-rootfs + +qemu-system-x86_64 \ + -nographic \ + -m 256 \ + -cpu max \ + -fsdev local,id=myid,path=$(pwd)/9pfs-rootfs/,security_model=none \ + -device virtio-9p-pci,fsdev=myid,mount_tag=fs0 \ + -append "python3-bye_qemu-x86_64 vfs.fstab=[ \"fs0:/:9pfs:::\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-x86_64 +``` + +You would use a similar command for QEMU/ARM64. diff --git a/python3-bye/README.scripts.md b/python3-bye/README.scripts.md new file mode 100644 index 0000000..7d1d680 --- /dev/null +++ b/python3-bye/README.scripts.md @@ -0,0 +1,54 @@ +# Scripts for Python3 Bye on Unikraft + +These are companions instruction to the main instructions in the [`README`](README.md). + +Use scripts as quick actions for building and running Python3 Bye on Unikraft. + +## Build for / : + +```console +./build.. +``` + +e.g.: + +```console +./build.qemu.x86_64 +./build.qemu.arm64 +./build.fc.x86_64 +./build.xen.arm64 +``` + +## Build for / using a different compiler + +```console +CC=/path/to/compiler ./build.. +``` + +e.g. + +```console +CC=/usr/bin/gcc-12 ./build.qemu.x86_64 +CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.qemu.arm64 +CC=/usr/bin/clang ./build.qemu.x86_64 +CC=/usr/bin/clang ./build.qemu.arm64 +CC=/usr/bin/gcc-12 ./build.fc.x86_64 +CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.fc.arm64 +CC=/usr/bin/clang ./build.fc.x86_64 +CC=/usr/bin/clang ./build.fc.arm64 +``` + +## Run on / + +```console +./run.. +``` + +e.g. + +```console +./run.qemu.x86_64 +./run.qemu.arm64 +./run.fc.x86_64 +./run.xen.arm64 +``` diff --git a/python3-bye/build.fc.arm64 b/python3-bye/build.fc.arm64 new file mode 100755 index 0000000..26f5f7d --- /dev/null +++ b/python3-bye/build.fc.arm64 @@ -0,0 +1,17 @@ +#!/bin/sh + +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/python3-bye/build.fc.x86_64 b/python3-bye/build.fc.x86_64 new file mode 100755 index 0000000..4ae21c0 --- /dev/null +++ b/python3-bye/build.fc.x86_64 @@ -0,0 +1,17 @@ +#!/bin/sh + +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/python3-bye/build.qemu.arm64 b/python3-bye/build.qemu.arm64 new file mode 100755 index 0000000..24cb479 --- /dev/null +++ b/python3-bye/build.qemu.arm64 @@ -0,0 +1,17 @@ +#!/bin/sh + +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/python3-bye/build.qemu.x86_64 b/python3-bye/build.qemu.x86_64 new file mode 100755 index 0000000..b6d070e --- /dev/null +++ b/python3-bye/build.qemu.x86_64 @@ -0,0 +1,17 @@ +#!/bin/sh + +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/python3-bye/build.xen.arm64 b/python3-bye/build.xen.arm64 new file mode 100755 index 0000000..1816652 --- /dev/null +++ b/python3-bye/build.xen.arm64 @@ -0,0 +1,17 @@ +#!/bin/sh + +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.xen.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/python3-bye/build.xen.x86_64 b/python3-bye/build.xen.x86_64 new file mode 100755 index 0000000..ad156dd --- /dev/null +++ b/python3-bye/build.xen.x86_64 @@ -0,0 +1,17 @@ +#!/bin/sh + +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +test -d ../repos/libs/python3 || git clone https://github.com/unikraft/lib-python3 ../repos/libs/python3 +test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.xen.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/python3-bye/defconfig.fc.arm64 b/python3-bye/defconfig.fc.arm64 new file mode 100644 index 0000000..7d2af50 --- /dev/null +++ b/python3-bye/defconfig.fc.arm64 @@ -0,0 +1,15 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/python3-bye/defconfig.fc.x86_64 b/python3-bye/defconfig.fc.x86_64 new file mode 100644 index 0000000..4d1ffba --- /dev/null +++ b/python3-bye/defconfig.fc.x86_64 @@ -0,0 +1,12 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y diff --git a/python3-bye/defconfig.qemu.arm64 b/python3-bye/defconfig.qemu.arm64 new file mode 100644 index 0000000..fab7378 --- /dev/null +++ b/python3-bye/defconfig.qemu.arm64 @@ -0,0 +1,15 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/python3-bye/defconfig.qemu.x86_64 b/python3-bye/defconfig.qemu.x86_64 new file mode 100644 index 0000000..679ed46 --- /dev/null +++ b/python3-bye/defconfig.qemu.x86_64 @@ -0,0 +1,12 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y diff --git a/python3-bye/defconfig.xen.arm64 b/python3-bye/defconfig.xen.arm64 new file mode 100644 index 0000000..9b1fd0e --- /dev/null +++ b/python3-bye/defconfig.xen.arm64 @@ -0,0 +1,14 @@ +CONFIG_PLAT_XEN=y +CONFIG_ARCH_ARM_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/python3-bye/defconfig.xen.x86_64 b/python3-bye/defconfig.xen.x86_64 new file mode 100644 index 0000000..5db38aa --- /dev/null +++ b/python3-bye/defconfig.xen.x86_64 @@ -0,0 +1,11 @@ +CONFIG_PLAT_XEN=y +CONFIG_ARCH_X86_64=y +CONFIG_LIBPYTHON3=y +CONFIG_LIBPYTHON3_MAIN_FUNCTION=y +CONFIG_LIBVFSCORE=y +CONFIG_LIBVFSCORE_AUTOMOUNT_UP=y +CONFIG_LIBRAMFS=y +CONFIG_LIBUKCPIO=y +CONFIG_STACK_SIZE_PAGE_ORDER=10 +CONFIG_LIBPOSIX_ENVIRON=y +CONFIG_LIBPOSIX_ENVIRON_LIBPARAM=y diff --git a/python3-bye/fc.arm64.json b/python3-bye/fc.arm64.json new file mode 100644 index 0000000..8ae0e6b --- /dev/null +++ b/python3-bye/fc.arm64.json @@ -0,0 +1,14 @@ +{ + "boot-source": { + "kernel_image_path": "out/python3-hello_fc-arm64", + "boot_args": "python3-hello_fc-arm64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/hello.py", + "initrd_path": "initrd.cpio" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 256, + "smt": false, + "track_dirty_pages": false + } +} diff --git a/python3-bye/fc.x86_64.json b/python3-bye/fc.x86_64.json new file mode 100644 index 0000000..acec3df --- /dev/null +++ b/python3-bye/fc.x86_64.json @@ -0,0 +1,14 @@ +{ + "boot-source": { + "kernel_image_path": "out/python3-hello_fc-x86_64", + "boot_args": "python3-hello_fc-x86_64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/hello.py", + "initrd_path": "initrd.cpio" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 256, + "smt": false, + "track_dirty_pages": false + } +} diff --git a/python3-bye/hello.py b/python3-bye/hello.py new file mode 100644 index 0000000..93977e4 --- /dev/null +++ b/python3-bye/hello.py @@ -0,0 +1,9 @@ +import sys + + +def main(): + print("Bye from Unikraft!") + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/python3-bye/run.fc.arm64 b/python3-bye/run.fc.arm64 new file mode 100755 index 0000000..8101683 --- /dev/null +++ b/python3-bye/run.fc.arm64 @@ -0,0 +1,22 @@ +#!/bin/sh + +if test ! -f "out/python3-bye_fc-arm64"; then + echo "No kernel file out/python3-bye_fc-arm64." 1>&2 + echo "Did you run ./build.fc.arm64 ?" 1>&2 + exit 1 +fi + +# Generate root filesystem from Dockerfile. +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +# Remove previously created files. +rm -f firecracker.socket + +firecracker-aarch64 \ + --api-sock firecracker.socket \ + --config-file fc.arm64.json diff --git a/python3-bye/run.fc.x86_64 b/python3-bye/run.fc.x86_64 new file mode 100755 index 0000000..14eaa8d --- /dev/null +++ b/python3-bye/run.fc.x86_64 @@ -0,0 +1,22 @@ +#!/bin/sh + +if test ! -f "out/python3-bye_fc-x86_64"; then + echo "No kernel file out/python3-bye_fc-x86_64." 1>&2 + echo "Did you run ./build.fc.x86_64 ?" 1>&2 + exit 1 +fi + +# Generate root filesystem from Dockerfile. +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +# Remove previously created files. +rm -f firecracker.socket + +firecracker-x86_64 \ + --api-sock firecracker.socket \ + --config-file fc.x86_64.json diff --git a/python3-bye/run.qemu.arm64 b/python3-bye/run.qemu.arm64 new file mode 100755 index 0000000..9a83f66 --- /dev/null +++ b/python3-bye/run.qemu.arm64 @@ -0,0 +1,24 @@ +#!/bin/sh + +if test ! -f "out/python3-bye_qemu-arm64"; then + echo "No kernel file out/python3-bye_qemu-arm64." 1>&2 + echo "Did you run ./build.qemu.arm64 ?" 1>&2 + exit 1 +fi + +# Generate root filesystem from Dockerfile. +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +qemu-system-aarch64 \ + -nographic \ + -machine virt \ + -m 256 \ + -cpu max \ + -append "python3-bye_qemu-arm64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-arm64 \ + -initrd ./initrd.cpio diff --git a/python3-bye/run.qemu.x86_64 b/python3-bye/run.qemu.x86_64 new file mode 100755 index 0000000..ca598ca --- /dev/null +++ b/python3-bye/run.qemu.x86_64 @@ -0,0 +1,23 @@ +#!/bin/sh + +if test ! -f "out/python3-bye_qemu-x86_64"; then + echo "No kernel file out/python3-bye_qemu-x86_64." 1>&2 + echo "Did you run ./build.qemu.x86_64 ?" 1>&2 + exit 1 +fi + +# Generate root filesystem from Dockerfile. +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +qemu-system-x86_64 \ + -nographic \ + -m 256 \ + -cpu max \ + -append "python3-bye_qemu-x86_64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" \ + -kernel out/python3-bye_qemu-x86_64 \ + -initrd ./initrd.cpio diff --git a/python3-bye/run.xen.arm64 b/python3-bye/run.xen.arm64 new file mode 100755 index 0000000..38dc01f --- /dev/null +++ b/python3-bye/run.xen.arm64 @@ -0,0 +1,17 @@ +#!/bin/sh + +if test ! -f "out/python3-bye_xen-arm64"; then + echo "No kernel file out/python3-bye_xen-arm64." 1>&2 + echo "Did you run ./build.xen.arm64 ?" 1>&2 + exit 1 +fi + +# Generate root filesystem from Dockerfile. +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +sudo xl create -c xen.arm64.cfg diff --git a/python3-bye/run.xen.x86_64 b/python3-bye/run.xen.x86_64 new file mode 100755 index 0000000..757f611 --- /dev/null +++ b/python3-bye/run.xen.x86_64 @@ -0,0 +1,17 @@ +#!/bin/sh + +if test ! -f "out/python3-bye_xen-x86_64"; then + echo "No kernel file out/python3-bye_xen-x86_64." 1>&2 + echo "Did you run ./build.xen.x86_64 ?" 1>&2 + exit 1 +fi + +# Generate root filesystem from Dockerfile. +rm -fr ./rootfs +docker build -o ./rootfs -f Dockerfile . + +# Pack filesystem as an initial ramdisk CPIO file. +rm -f initrd.cpio +../repos/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/ + +sudo xl create -c xen.x86_64.cfg diff --git a/python3-bye/test.all.sh b/python3-bye/test.all.sh new file mode 100755 index 0000000..70b746d --- /dev/null +++ b/python3-bye/test.all.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +test_build() +{ + printf "%-46s ... " build."$1" + ./build."$1" > log.build."$1" 2>&1 + if test $? -eq 0; then + echo "PASSED" + else + echo "FAILED" + fi +} + +test_build_run() +{ + printf "%-46s ... " build."$1" + ./build."$1" > log.build."$1" 2>&1 + if test $? -eq 0; then + echo "PASSED" + else + echo "FAILED" + fi + + printf " %-42s ... " run."$1" + ./test.wrapper.sh ./run."$1" 2> log.run."$1" +} + +test_build_run qemu.x86_64 +test_build_run qemu.arm64 +test_build_run fc.x86_64 +test_build fc.arm64 +test_build xen.x86_64 +test_build xen.arm64 diff --git a/python3-bye/test.common.sh b/python3-bye/test.common.sh new file mode 100644 index 0000000..be542f2 --- /dev/null +++ b/python3-bye/test.common.sh @@ -0,0 +1,146 @@ +#!/bin/bash + +if test -z "$log_file"; then + log_file="/dev/null" +fi + +clean_up() +{ + { + # Clean up any previous instances. + sudo pkill -9 qemu-system + sudo pkill -9 firecracker + kraft stop --all + kraft rm --all + sudo kraft stop --all + sudo kraft rm --all + + # Remove previously created network interfaces. + sudo ip link set dev tap0 down + sudo ip link del dev tap0 + sudo ip link set dev virbr0 down + sudo ip link del dev virbr0 + } > /dev/null 2>&1 +} + +start_instance() +{ + # Start instance. + setsid --fork "$start_command" 1>&2 & + if test $? -ne 0; then + echo "Cannot start instance" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +start_instance_timeout() +{ + # Start instance. + setsid --fork timeout -k 2 5 "$start_command" 1>&2 & + if test $? -ne 0; then + echo "Cannot start instance" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_ping() +{ + host="$1" + + # Connect to instance. + ping -c 1 "$host" 1>&2 + if test $? -ne 0; then + echo "Cannot ping $host" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_curl_connect() +{ + host="$1" + port="$2" + + # Query instance. + curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" 1>&2 + if test $? -ne 0; then + echo "Cannot connect to $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_curl_check_reply() +{ + host="$1" + port="$2" + message="$3" + + # Check server message contents. + curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" | grep "$message" 1>&2 + if test $? -ne 0; then + echo "Wrong message from $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_netcat_connect() +{ + host="$1" + port="$2" + + # Check connection. + netcat -w 3 "$host" "$port" < /dev/null 1>&2 + if test $? -ne 0; then + echo "Cannot connect to $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_redis_connect() +{ + host="$1" + port="$2" + + redis-cli -h "$host" -p "$port" < /dev/null 1>&2 + if test $? -ne 0; then + echo "Cannot connect client to Redis server at $host:$port" 1>&2 + echo "FAILED" + clean_up + exit 1 + fi +} + +test_redis_cli() +{ + host="$1" + port="$2" + + redis-cli -h "$host" -p "$port" set a 1 1>&2 + redis-cli -h "$host" -p "$port" get a 1>&2 + if test $? -eq 1; then + echo "FAILED" + echo "Cannot talk to Redis server at $host:$port" 1>&2 + clean_up + exit 1 + fi +} + +end_with_success() +{ + echo "PASSED" + clean_up + exit 0 +} + +start_command="$1" diff --git a/python3-bye/test.sh b/python3-bye/test.sh new file mode 100755 index 0000000..8a4c708 --- /dev/null +++ b/python3-bye/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +. ./test.common.sh diff --git a/python3-bye/test.wrapper.sh b/python3-bye/test.wrapper.sh new file mode 100755 index 0000000..4a8fe23 --- /dev/null +++ b/python3-bye/test.wrapper.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +. ./test.common.sh + +if test $# -ne 1; then + echo "Unknown arguments." 1>&2 + echo "Usage: $0 " 1>&2 + exit 1 +fi + +# Clean up previous instances. +clean_up + +# Start instance. +start_instance_timeout 2>&1 | grep "Hello from Unikraft!" 1>&2 +if test $? -ne 0; then + echo "Wrong message printed." 1>&2 + echo "FAILED" + clean_up + exit 1 +fi + +# Stop instance. +end_with_success diff --git a/python3-bye/xen.arm64.cfg b/python3-bye/xen.arm64.cfg new file mode 100644 index 0000000..f0564dc --- /dev/null +++ b/python3-bye/xen.arm64.cfg @@ -0,0 +1,7 @@ +name = "python3-bye" +vcpus = "1" +kernel = "./out/python3-bye_xen-arm64" +ramdisk = "./initrd.cpio" +cmdline = "python3-bye_xen-arm64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" +memory = "256" +type = "pv" diff --git a/python3-bye/xen.x86_64.cfg b/python3-bye/xen.x86_64.cfg new file mode 100644 index 0000000..6cbe6a7 --- /dev/null +++ b/python3-bye/xen.x86_64.cfg @@ -0,0 +1,7 @@ +name = "python3-bye" +vcpus = "1" +kernel = "./out/python3-bye_xen-x86_64" +ramdisk = "./initrd.cpio" +cmdline = "python3-bye_xen-x86_64 vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] env.vars=[ PYTHONPATH=\"/usr/local/lib/python3.10:/usr/local/lib/python3.10/site-packages\" ] -- /app/bye.py" +memory = "256" +type = "pv" From 08315a02c36cac5a6007a9333e5fc6cff4680792 Mon Sep 17 00:00:00 2001 From: mierepeashi1 Date: Sat, 18 Oct 2025 12:24:58 +0300 Subject: [PATCH 3/3] Removed files as its no longer needed --- cpp-bye/.gitignore | 1 - cpp-bye/Config.uk | 12 -- cpp-bye/Makefile | 14 -- cpp-bye/Makefile.uk | 3 - cpp-bye/README.md | 271 ---------------------------------- cpp-bye/README.scripts.md | 54 ------- cpp-bye/build.fc.arm64 | 18 --- cpp-bye/build.fc.x86_64 | 18 --- cpp-bye/build.qemu.arm64 | 18 --- cpp-bye/build.qemu.x86_64 | 18 --- cpp-bye/build.xen.arm64 | 18 --- cpp-bye/build.xen.x86_64 | 18 --- cpp-bye/bye.cpp | 7 - cpp-bye/defconfig.fc.arm64 | 11 -- cpp-bye/defconfig.fc.x86_64 | 8 - cpp-bye/defconfig.qemu.arm64 | 11 -- cpp-bye/defconfig.qemu.x86_64 | 8 - cpp-bye/defconfig.xen.arm64 | 10 -- cpp-bye/defconfig.xen.x86_64 | 7 - cpp-bye/fc.arm64.json | 12 -- cpp-bye/fc.x86_64.json | 12 -- cpp-bye/run.fc.arm64 | 12 -- cpp-bye/run.fc.x86_64 | 12 -- cpp-bye/run.qemu.arm64 | 14 -- cpp-bye/run.qemu.x86_64 | 13 -- cpp-bye/run.xen.arm64 | 9 -- cpp-bye/run.xen.x86_64 | 9 -- cpp-bye/test.all.sh | 33 ----- cpp-bye/test.common.sh | 134 ----------------- cpp-bye/test.sh | 4 - cpp-bye/test.wrapper.sh | 24 --- cpp-bye/xen.arm64.cfg | 5 - cpp-bye/xen.x86_64.cfg | 5 - 33 files changed, 823 deletions(-) delete mode 100644 cpp-bye/.gitignore delete mode 100644 cpp-bye/Config.uk delete mode 100644 cpp-bye/Makefile delete mode 100644 cpp-bye/Makefile.uk delete mode 100644 cpp-bye/README.md delete mode 100644 cpp-bye/README.scripts.md delete mode 100755 cpp-bye/build.fc.arm64 delete mode 100755 cpp-bye/build.fc.x86_64 delete mode 100755 cpp-bye/build.qemu.arm64 delete mode 100755 cpp-bye/build.qemu.x86_64 delete mode 100755 cpp-bye/build.xen.arm64 delete mode 100755 cpp-bye/build.xen.x86_64 delete mode 100644 cpp-bye/bye.cpp delete mode 100644 cpp-bye/defconfig.fc.arm64 delete mode 100644 cpp-bye/defconfig.fc.x86_64 delete mode 100644 cpp-bye/defconfig.qemu.arm64 delete mode 100644 cpp-bye/defconfig.qemu.x86_64 delete mode 100644 cpp-bye/defconfig.xen.arm64 delete mode 100644 cpp-bye/defconfig.xen.x86_64 delete mode 100644 cpp-bye/fc.arm64.json delete mode 100644 cpp-bye/fc.x86_64.json delete mode 100755 cpp-bye/run.fc.arm64 delete mode 100755 cpp-bye/run.fc.x86_64 delete mode 100755 cpp-bye/run.qemu.arm64 delete mode 100755 cpp-bye/run.qemu.x86_64 delete mode 100755 cpp-bye/run.xen.arm64 delete mode 100755 cpp-bye/run.xen.x86_64 delete mode 100755 cpp-bye/test.all.sh delete mode 100644 cpp-bye/test.common.sh delete mode 100755 cpp-bye/test.sh delete mode 100755 cpp-bye/test.wrapper.sh delete mode 100644 cpp-bye/xen.arm64.cfg delete mode 100644 cpp-bye/xen.x86_64.cfg diff --git a/cpp-bye/.gitignore b/cpp-bye/.gitignore deleted file mode 100644 index 6a3417b..0000000 --- a/cpp-bye/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/out/ diff --git a/cpp-bye/Config.uk b/cpp-bye/Config.uk deleted file mode 100644 index 1a5e719..0000000 --- a/cpp-bye/Config.uk +++ /dev/null @@ -1,12 +0,0 @@ -# Configure C++ Bye application. Use C++ libraries. - -config APPCPPBYE -bool "Configure C++ Bye" -default y - - # Select C++ libraries. - select LIBCOMPILER_RT - select LIBCXX - select LIBCXXABI - select LIBUNWIND - select LIBMUSL diff --git a/cpp-bye/Makefile b/cpp-bye/Makefile deleted file mode 100644 index a6a8b6b..0000000 --- a/cpp-bye/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -UK_ROOT ?= $(PWD)/../repos/unikraft -UK_BUILD ?= $(PWD)/out -UK_APP ?= $(PWD) -LIBS_BASE = $(PWD)/../repos/libs -UK_LIBS := $(LIBS_BASE)/libcxxabi:$(LIBS_BASE)/libcxx:$(LIBS_BASE)/libunwind:$(LIBS_BASE)/compiler-rt:$(LIBS_BASE)/musl - -.PHONY: all - -all: - @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) - -$(MAKECMDGOALS): - @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) $(MAKECMDGOALS) - diff --git a/cpp-bye/Makefile.uk b/cpp-bye/Makefile.uk deleted file mode 100644 index cdbd440..0000000 --- a/cpp-bye/Makefile.uk +++ /dev/null @@ -1,3 +0,0 @@ -$(eval $(call addlib,appbyecpp)) - -APPBYECPP_SRCS-y += $(APPBYECPP_BASE)/bye.cpp diff --git a/cpp-bye/README.md b/cpp-bye/README.md deleted file mode 100644 index 5653bc2..0000000 --- a/cpp-bye/README.md +++ /dev/null @@ -1,271 +0,0 @@ -# C++ Hello on Unikraft - -Build and run a C++ Hello program on Unikraft. -Follow the instructions below to set up, configure, build and run C++ Hello. -Make sure you installed the [requirements](../README.md#requirements). - -## Quick Setup (aka TLDR) - -For a quick setup, run the commands below. -Note that you still need to install the [requirements](../README.md#requirements). - -To build and run the application for `x86_64`, use the commands below: - -```console -test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d ../repos/libs/libcxxabi || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d ../repos/libs/libcxx || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d ../repos/libs/libunwind || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl -make distclean -echo -e 'CONFIG_PLAT_KVM=y\nCONFIG_PLAT_KVM_VMM_QEMU=y\nCONFIG_ARCH_X86_64=y\nCONFIG_LIBCOMPILER_RT=y\nCONFIG_LIBCXX=y\nCONFIG_LIBCXXABI=y\nCONFIG_LIBUNWIND=y\nCONFIG_LIBMUSL=y' > /tmp/defconfig -UK_DEFCONFIG=/tmp/defconfig make defconfig -make -j $(nproc) -qemu-system-x86_64 -nographic -m 8 -cpu max -kernel out/cpp-bye_qemu-x86_64 -``` - -This will configure, build and run the application, resulting in a `Hello from Unikraft!` message being printed. - -To do the same for `AArch64`, run the commands below: - -```console -test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d ../repos/libs/libcxxabi || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxa> -test -d ../repos/libs/libcxx || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d ../repos/libs/libunwind || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwi> -test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/com> -test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl -make distclean -echo -e 'CONFIG_PLAT_KVM=y\nCONFIG_PLAT_KVM_VMM_QEMU=y\nCONFIG_ARCH_ARM_64=y\nCONFIG_LIBCOMPILER_RT=y\nCONFIG_LIBCXX=y\nCONFIG_LIBCXXABI=y\nCONFIG_LIBUNWIND=y\nCONFIG_LIBMUSL=y' > /tmp/defconfig -UK_DEFCONFIG=/tmp/defconfig make defconfig -make -j $(nproc) -qemu-system-aarch64 -nographic -machine virt -m 8 -cpu max -kernel out/cpp-bye_qemu-arm64 -``` - -Similar to the `x86_64` build, this will result in a `Hello from Unikraft!` message being printed. - -Information about every step and about other types of builds is detailed below. - -## Set Up - -Set up the [`unikraft` repository](https://github.com/unikraft/unikraft). -Clone it in `../repos/unikraft/` if not already cloned: - -```console -test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d ../repos/libs/libcxxabi || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d ../repos/libs/libcxx || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d ../repos/libs/libunwind || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d ../repos/libs/compiler-rt || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl -``` - -If you want use a custom variant of the repository (e.g. apply your own patch, make modifications), update it accordingly in the `../repos/` directory. - -## Clean - -While not strictly required, it is safest to clean the previous build artifacts: - -```console -make distclean -``` - -## Configure - -To configure the kernel, use: - -```console -make menuconfig -``` - -In the console menu interface, choose the target architecture (x86_64 or ARMv8 or ARMv7) and platform (Xen or KVM/QEMU or KVM/Firecracker). - -The end result will be the creation of the `.config` configuration file. - -## Build - -Build the application for the current configuration: - -```console -make -j $(nproc) -``` - -This results in the creation of the `out/` directory storing the build artifacts. -The unikernel application image file is `out/cpp-bye_-`, where `` is the platform name (`qemu`, `fc`, `xen`), and `` is the architecture (`x86_64` or `arm64`). - -### Use a Different Compiler - -If you want to use a different compiler, such as a Clang or a different GCC version, pass the `CC` variable to `make`. - -To build with Clang, use the commands below: - -```console -make properclean -make CC=clang -j $(nproc) -``` - -Note that Clang >= 14 is required to build Unikraft. - -To build with another GCC version, use the commands below: - -```console -make properclean -make CC=gcc- -j $(nproc) -``` - -where `` is the GCC version, such as `11`, `12`. - -Note that GCC >= 8 is required to build Unikraft. - -## Clean Up - -Doing a new configuration, or a new build may require cleaning up the configuration and build artifacts. - -In order to remove the build artifacts, use: - -```console -make clean -``` - -In order to remove fetched files also, that is the removal of the `out/` directory, use: - -```console -make properclean -``` - -In order to remove the generated `.config` file as well, use: - -```console -make distclean -``` - -## Run - -Run the resulting image using the corresponding platform tool. -Firecracker requires KVM support. -Xen requires a system with Xen installed. - -A successful run will show a message such as the one below: - -```text -Booting from ROM..Powered by -o. .o _ _ __ _ -Oo Oo ___ (_) | __ __ __ _ ' _) :_ -oO oO ' _ `| | |/ / _)' _` | |_| _) -oOo oOO| | | | | (| | | (_) | _) :_ - OoOoO ._, ._:_:_,\_._, .__,_:_, \___) - Calypso 0.17.0~5d38d108 -Hello from Unikraft! -``` - -### Run on QEMU/x86_64 - -```console -qemu-system-x86_64 -nographic -m 8 -cpu max -kernel out/cpp-bye_qemu-x86_64 -``` - -### Run on QEMU/ARM64 - -```console -qemu-system-aarch64 -nographic -machine virt -m 8 -cpu max -kernel out/cpp-bye_qemu-arm64 -``` - -### Run on Firecracker/x86_64 - -```console -rm -f firecracker.socket -firecracker-x86_64 --config-file fc.x86_64.json --api-sock firecracker.socket -``` - -The user running the above command must be able to use KVM. -Typically this means being part of the `kvm` group. -Otherwise, run the command above as root or prefixed by `sudo`. - -### Run on Firecracker/ARM64 - -```console -rm -f firecracker.socket -firecracker-aarch64 --config-file fc.arm64.json --api-sock firecracker.socket -``` - -The user running the above command must be able to use KVM. -Typically this means being part of the `kvm` group. -Otherwise, run the command above as the `root` account or prefixed by `sudo`. - -### Run on Xen/x86_64 - -```console -sudo xl create -c xen.x86_64.cfg -``` - -You need use `sudo` or the `root` account to run Xen. - -### Run on Xen/ARM64 - -```console -sudo xl create -c xen.arm64.cfg -``` - -You need use `sudo` or the `root` account to run Xen. - -## Customize -### Update the Unikraft Core Code - -If updating the Unikraft core code in the `../repos/unikraft/` directory, you then go through the [configure](#configure), [build](#build) and [run](#run) steps. - -### Add Other Source Code Files - -The current configuration use a single source file: `bye.cpp`. -If looking to add another file to the build, update the [`Makefile.uk`](Makefile.uk) file. - -For example, to add a new file `support.cpp` to the build, update the [`Makefile.uk`](Makefile.uk) file to: - -```make -$(eval $(call addlib,appbyeworldcpp)) - -APPHELLOWORLDCPP_SRCS-y += $(APPHELLOWORLDCPP_BASE)/bye.cpp -APPHELLOWORLDCPP_SRCS-y += $(APPHELLOWORLDCPP_BASE)/support.cpp -``` - -To add a new include directory, such as a local `include/` directory, update the [`Makefile.uk`](Makefile.uk) file to: - -```make -$(eval $(call addlib,appbyeworldcpp)) - -APPHELLOWORLDCPP_SRCS-y += $(APPHELLOWORLDCPP_BASE)/bye.cpp -CINLUDES-y += -I$(APPHELLOWORLDCPP_BASE)/include -``` - -Then go through the [configure](#configure), [build](#build) and [run](#run) steps. - -### Add Other Libraries - -It may be the case that you want to add a library to the build, in order to test the library or a certain feature. -If that is the case, update the `UK_LIBS` variable in the [`Makefile`](Makefile). - -For example, to add the Musl library to the build, clone the [`lib-musl` library repository](https://github.com/unikraft/lib-musl): - -```console -test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl -``` - -and update the `UK_LIBS` line the [`Makefile`](Makefile) to: - -```make -UK_LIBS ?= $(LIBS_BASE)/musl -``` - -To add another library, such as LWIP, clone the [corresponding `lib-lwip` repository](https://github.com/unikraft/lib-musl): - -```console -test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip -``` - -and update the `UK_LIBS` line the [`Makefile`](Makefile) to: - -```make -UK_LIBS ?= $(LIBS_BASE)/musl:$(LIBS_BASE)/lwip -``` - -Then go through the [configure](#configure), [build](#build) and [run](#run) steps. diff --git a/cpp-bye/README.scripts.md b/cpp-bye/README.scripts.md deleted file mode 100644 index 556f65b..0000000 --- a/cpp-bye/README.scripts.md +++ /dev/null @@ -1,54 +0,0 @@ -# Scripts for C++ Bye on Unikraft - -These are companions instruction to the main instructions in the [`README`](README.md). - -Use scripts as quick actions for building and running C++ Bye on Unikraft. - -## Build for / : - -```console -./build.. -``` - -e.g.: - -```console -./build.qemu.x86_64 -./build.qemu.arm64 -./build.fc.x86_64 -./build.xen.arm64 -``` - -## Build for / using a different compiler - -```console -CC=/path/to/compiler ./build.. -``` - -e.g. - -```console -CC=/usr/bin/gcc-12 ./build.qemu.x86_64 -CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.qemu.arm64 -CC=/usr/bin/clang ./build.qemu.x86_64 -CC=/usr/bin/clang ./build.qemu.arm64 -CC=/usr/bin/gcc-12 ./build.fc.x86_64 -CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.fc.arm64 -CC=/usr/bin/clang ./build.fc.x86_64 -CC=/usr/bin/clang ./build.fc.arm64 -``` - -## Run on / - -```console -./run.. -``` - -e.g. - -```console -./run.qemu.x86_64 -./run.qemu.arm64 -./run.fc.x86_64 -./run.xen.arm64 -``` diff --git a/cpp-bye/build.fc.arm64 b/cpp-bye/build.fc.arm64 deleted file mode 100755 index daf9595..0000000 --- a/cpp-bye/build.fc.arm64 +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl - -make distclean -UK_DEFCONFIG=$(pwd)/defconfig.fc.arm64 make defconfig -touch Makefile.uk -make prepare -if test -z "$CC"; then - make -j $(nproc) -else - make CC="$CC" -j $(nproc) -fi diff --git a/cpp-bye/build.fc.x86_64 b/cpp-bye/build.fc.x86_64 deleted file mode 100755 index 6c65200..0000000 --- a/cpp-bye/build.fc.x86_64 +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl - -make distclean -UK_DEFCONFIG=$(pwd)/defconfig.fc.x86_64 make defconfig -touch Makefile.uk -make prepare -if test -z "$CC"; then - make -j $(nproc) -else - make CC="$CC" -j $(nproc) -fi diff --git a/cpp-bye/build.qemu.arm64 b/cpp-bye/build.qemu.arm64 deleted file mode 100755 index db95a5c..0000000 --- a/cpp-bye/build.qemu.arm64 +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl - -make distclean -UK_DEFCONFIG=$(pwd)/defconfig.qemu.arm64 make defconfig -touch Makefile.uk -make prepare -if test -z "$CC"; then - make -j $(nproc) -else - make CC="$CC" -j $(nproc) -fi diff --git a/cpp-bye/build.qemu.x86_64 b/cpp-bye/build.qemu.x86_64 deleted file mode 100755 index efb1e9f..0000000 --- a/cpp-bye/build.qemu.x86_64 +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl - -make distclean -UK_DEFCONFIG=$(pwd)/defconfig.qemu.x86_64 make defconfig -touch Makefile.uk -make prepare -if test -z "$CC"; then - make -j $(nproc) -else - make CC="$CC" -j $(nproc) -fi diff --git a/cpp-bye/build.xen.arm64 b/cpp-bye/build.xen.arm64 deleted file mode 100755 index 2f3569c..0000000 --- a/cpp-bye/build.xen.arm64 +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl - -make distclean -UK_DEFCONFIG=$(pwd)/defconfig.xen.arm64 make defconfig -touch Makefile.uk -make prepare -if test -z "$CC"; then - make -j $(nproc) -else - make CC="$CC" -j $(nproc) -fi diff --git a/cpp-bye/build.xen.x86_64 b/cpp-bye/build.xen.x86_64 deleted file mode 100755 index 8d1a511..0000000 --- a/cpp-bye/build.xen.x86_64 +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft -test -d "../repos/libs/libcxxabi" || git clone https://github.com/unikraft/lib-libcxxabi ../repos/libs/libcxxabi -test -d "../repos/libs/libcxx" || git clone https://github.com/unikraft/lib-libcxx ../repos/libs/libcxx -test -d "../repos/libs/libunwind" || git clone https://github.com/unikraft/lib-libunwind ../repos/libs/libunwind -test -d "../repos/libs/compiler-rt" || git clone https://github.com/unikraft/lib-compiler-rt ../repos/libs/compiler-rt -test -d "../repos/libs/musl" || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl - -make distclean -UK_DEFCONFIG=$(pwd)/defconfig.xen.x86_64 make defconfig -touch Makefile.uk -make prepare -if test -z "$CC"; then - make -j $(nproc) -else - make CC="$CC" -j $(nproc) -fi diff --git a/cpp-bye/bye.cpp b/cpp-bye/bye.cpp deleted file mode 100644 index ea57aa2..0000000 --- a/cpp-bye/bye.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main() -{ - std::cout << "Bye from Unikraft!" << std::endl; - return 0; -} diff --git a/cpp-bye/defconfig.fc.arm64 b/cpp-bye/defconfig.fc.arm64 deleted file mode 100644 index 5503174..0000000 --- a/cpp-bye/defconfig.fc.arm64 +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG_PLAT_KVM=y -CONFIG_KVM_VMM_FIRECRACKER=y -CONFIG_ARCH_ARM_64=y -CONFIG_LIBCOMPILER_RT=y -CONFIG_LIBCXX=y -CONFIG_LIBCXXABI=y -CONFIG_LIBUNWIND=y -CONFIG_LIBMUSL=y -CONFIG_ARM64_ERRATUM_858921=n -CONFIG_ARM64_ERRATUM_835769=n -CONFIG_ARM64_ERRATUM_843419=n diff --git a/cpp-bye/defconfig.fc.x86_64 b/cpp-bye/defconfig.fc.x86_64 deleted file mode 100644 index 17448ca..0000000 --- a/cpp-bye/defconfig.fc.x86_64 +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_PLAT_KVM=y -CONFIG_KVM_VMM_FIRECRACKER=y -CONFIG_ARCH_X86_64=y -CONFIG_LIBCOMPILER_RT=y -CONFIG_LIBCXX=y -CONFIG_LIBCXXABI=y -CONFIG_LIBUNWIND=y -CONFIG_LIBMUSL=y diff --git a/cpp-bye/defconfig.qemu.arm64 b/cpp-bye/defconfig.qemu.arm64 deleted file mode 100644 index 86279d2..0000000 --- a/cpp-bye/defconfig.qemu.arm64 +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG_PLAT_KVM=y -CONFIG_KVM_VMM_QEMU=y -CONFIG_ARCH_ARM_64=y -CONFIG_LIBCOMPILER_RT=y -CONFIG_LIBCXX=y -CONFIG_LIBCXXABI=y -CONFIG_LIBUNWIND=y -CONFIG_LIBMUSL=y -CONFIG_ARM64_ERRATUM_858921=n -CONFIG_ARM64_ERRATUM_835769=n -CONFIG_ARM64_ERRATUM_843419=n diff --git a/cpp-bye/defconfig.qemu.x86_64 b/cpp-bye/defconfig.qemu.x86_64 deleted file mode 100644 index 1247389..0000000 --- a/cpp-bye/defconfig.qemu.x86_64 +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_PLAT_KVM=y -CONFIG_KVM_VMM_QEMU=y -CONFIG_ARCH_X86_64=y -CONFIG_LIBCOMPILER_RT=y -CONFIG_LIBCXX=y -CONFIG_LIBCXXABI=y -CONFIG_LIBUNWIND=y -CONFIG_LIBMUSL=y diff --git a/cpp-bye/defconfig.xen.arm64 b/cpp-bye/defconfig.xen.arm64 deleted file mode 100644 index 7f701f5..0000000 --- a/cpp-bye/defconfig.xen.arm64 +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_PLAT_XEN=y -CONFIG_ARCH_ARM_64=y -CONFIG_LIBCOMPILER_RT=y -CONFIG_LIBCXX=y -CONFIG_LIBCXXABI=y -CONFIG_LIBUNWIND=y -CONFIG_LIBMUSL=y -CONFIG_ARM64_ERRATUM_858921=n -CONFIG_ARM64_ERRATUM_835769=n -CONFIG_ARM64_ERRATUM_843419=n diff --git a/cpp-bye/defconfig.xen.x86_64 b/cpp-bye/defconfig.xen.x86_64 deleted file mode 100644 index e644e18..0000000 --- a/cpp-bye/defconfig.xen.x86_64 +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_PLAT_XEN=y -CONFIG_ARCH_X86_64=y -CONFIG_LIBCOMPILER_RT=y -CONFIG_LIBCXX=y -CONFIG_LIBCXXABI=y -CONFIG_LIBUNWIND=y -CONFIG_LIBMUSL=y diff --git a/cpp-bye/fc.arm64.json b/cpp-bye/fc.arm64.json deleted file mode 100644 index 731c818..0000000 --- a/cpp-bye/fc.arm64.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "boot-source": { - "kernel_image_path": "out/cpp-hello_fc-arm64" - }, - "drives": [], - "machine-config": { - "vcpu_count": 1, - "mem_size_mib": 8, - "smt": false, - "track_dirty_pages": false - } -} diff --git a/cpp-bye/fc.x86_64.json b/cpp-bye/fc.x86_64.json deleted file mode 100644 index 4e5c84e..0000000 --- a/cpp-bye/fc.x86_64.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "boot-source": { - "kernel_image_path": "out/cpp-hello_fc-x86_64" - }, - "drives": [], - "machine-config": { - "vcpu_count": 1, - "mem_size_mib": 8, - "smt": false, - "track_dirty_pages": false - } -} diff --git a/cpp-bye/run.fc.arm64 b/cpp-bye/run.fc.arm64 deleted file mode 100755 index 49e6a52..0000000 --- a/cpp-bye/run.fc.arm64 +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -if test ! -f "out/cpp-bye_fc-arm64"; then - echo "No kernel file out/cpp-bye_fc-arm64." 1>&2 - echo "Did you run ./build.fc.arm64 ?" 1>&2 - exit 1 -fi - -rm -f firecracker.socket -firecracker-aarch64 \ - --api-sock firecracker.socket \ - --config-file fc.arm64.json diff --git a/cpp-bye/run.fc.x86_64 b/cpp-bye/run.fc.x86_64 deleted file mode 100755 index 556294f..0000000 --- a/cpp-bye/run.fc.x86_64 +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -if test ! -f "out/cpp-bye_fc-x86_64"; then - echo "No kernel file out/cpp-bye_fc-x86_64." 1>&2 - echo "Did you run ./build.fc.x86_64 ?" 1>&2 - exit 1 -fi - -rm -f firecracker.socket -firecracker-x86_64 \ - --api-sock firecracker.socket \ - --config-file fc.x86_64.json diff --git a/cpp-bye/run.qemu.arm64 b/cpp-bye/run.qemu.arm64 deleted file mode 100755 index 2e0e8fa..0000000 --- a/cpp-bye/run.qemu.arm64 +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -if test ! -f "out/cpp-bye_qemu-arm64"; then - echo "No kernel file out/cpp-bye_qemu-arm64." 1>&2 - echo "Did you run ./build.qemu.arm64 ?" 1>&2 - exit 1 -fi - -qemu-system-aarch64 \ - -nographic \ - -machine virt \ - -m 8 \ - -cpu max \ - -kernel out/cpp-bye_qemu-arm64 diff --git a/cpp-bye/run.qemu.x86_64 b/cpp-bye/run.qemu.x86_64 deleted file mode 100755 index 455a916..0000000 --- a/cpp-bye/run.qemu.x86_64 +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -if test ! -f "out/cpp-bye_qemu-x86_64"; then - echo "No kernel file out/cpp-bye_qemu-x86_64." 1>&2 - echo "Did you run ./build.qemu.x86_64 ?" 1>&2 - exit 1 -fi - -qemu-system-x86_64 \ - -nographic \ - -m 8 \ - -cpu max \ - -kernel out/cpp-bye_qemu-x86_64 diff --git a/cpp-bye/run.xen.arm64 b/cpp-bye/run.xen.arm64 deleted file mode 100755 index c563728..0000000 --- a/cpp-bye/run.xen.arm64 +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -if test ! -f "out/cpp-bye_xen-arm64"; then - echo "No kernel file out/cpp-bye_xen-arm64." 1>&2 - echo "Did you run ./build.xen.arm64 ?" 1>&2 - exit 1 -fi - -sudo xl create -c xen.arm64.cfg diff --git a/cpp-bye/run.xen.x86_64 b/cpp-bye/run.xen.x86_64 deleted file mode 100755 index adb05da..0000000 --- a/cpp-bye/run.xen.x86_64 +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -if test ! -f "out/cpp-bye_xen-x86_64"; then - echo "No kernel file out/cpp-bye_xen-x86_64." 1>&2 - echo "Did you run ./build.xen.x86_64 ?" 1>&2 - exit 1 -fi - -sudo xl create -c xen.x86_64.cfg diff --git a/cpp-bye/test.all.sh b/cpp-bye/test.all.sh deleted file mode 100755 index 70b746d..0000000 --- a/cpp-bye/test.all.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -test_build() -{ - printf "%-46s ... " build."$1" - ./build."$1" > log.build."$1" 2>&1 - if test $? -eq 0; then - echo "PASSED" - else - echo "FAILED" - fi -} - -test_build_run() -{ - printf "%-46s ... " build."$1" - ./build."$1" > log.build."$1" 2>&1 - if test $? -eq 0; then - echo "PASSED" - else - echo "FAILED" - fi - - printf " %-42s ... " run."$1" - ./test.wrapper.sh ./run."$1" 2> log.run."$1" -} - -test_build_run qemu.x86_64 -test_build_run qemu.arm64 -test_build_run fc.x86_64 -test_build fc.arm64 -test_build xen.x86_64 -test_build xen.arm64 diff --git a/cpp-bye/test.common.sh b/cpp-bye/test.common.sh deleted file mode 100644 index 897205b..0000000 --- a/cpp-bye/test.common.sh +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/bash - -if test -z "$log_file"; then - log_file="/dev/null" -fi - -clean_up() -{ - { - # Clean up any previous instances. - sudo pkill -9 qemu-system - sudo pkill -9 firecracker - kraft stop --all - kraft rm --all - sudo kraft stop --all - sudo kraft rm --all - - # Remove previously created network interfaces. - sudo ip link set dev tap0 down - sudo ip link del dev tap0 - sudo ip link set dev virbr0 down - sudo ip link del dev virbr0 - } > /dev/null 2>&1 -} - -start_instance() -{ - # Start instance. - setsid --fork "$start_command" 1>&2 & - if test $? -ne 0; then - echo "Cannot start instance" 1>&2 - echo "FAILED" - clean_up - exit 1 - fi -} - -test_ping() -{ - host="$1" - - # Connect to instance. - ping -c 1 "$host" 1>&2 - if test $? -ne 0; then - echo "Cannot ping $host" 1>&2 - echo "FAILED" - clean_up - exit 1 - fi -} - -test_curl_connect() -{ - host="$1" - port="$2" - - # Query instance. - curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" 1>&2 - if test $? -ne 0; then - echo "Cannot connect to $host:$port" 1>&2 - echo "FAILED" - clean_up - exit 1 - fi -} - -test_curl_check_reply() -{ - host="$1" - port="$2" - message="$3" - - # Check server message contents. - curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" | grep "$message" 1>&2 - if test $? -ne 0; then - echo "Wrong message from $host:$port" 1>&2 - echo "FAILED" - clean_up - exit 1 - fi -} - -test_netcat_connect() -{ - host="$1" - port="$2" - - # Check connection. - netcat -w 3 "$host" "$port" < /dev/null 1>&2 - if test $? -ne 0; then - echo "Cannot connect to $host:$port" 1>&2 - echo "FAILED" - clean_up - exit 1 - fi -} - -test_redis_connect() -{ - host="$1" - port="$2" - - redis-cli -h "$host" -p "$port" < /dev/null 1>&2 - if test $? -ne 0; then - echo "Cannot connect client to Redis server at $host:$port" 1>&2 - echo "FAILED" - clean_up - exit 1 - fi -} - -test_redis_cli() -{ - host="$1" - port="$2" - - redis-cli -h "$host" -p "$port" set a 1 1>&2 - redis-cli -h "$host" -p "$port" get a 1>&2 - if test $? -eq 1; then - echo "FAILED" - echo "Cannot talk to Redis server at $host:$port" 1>&2 - clean_up - exit 1 - fi -} - -end_with_success() -{ - echo "PASSED" - clean_up - exit 0 -} - -start_command="$1" diff --git a/cpp-bye/test.sh b/cpp-bye/test.sh deleted file mode 100755 index c18e81e..0000000 --- a/cpp-bye/test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -. ./test.common.sh - diff --git a/cpp-bye/test.wrapper.sh b/cpp-bye/test.wrapper.sh deleted file mode 100755 index 7182d26..0000000 --- a/cpp-bye/test.wrapper.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. ./test.common.sh - -if test $# -ne 1; then - echo "Unknown arguments." 1>&2 - echo "Usage: $0 " 1>&2 - exit 1 -fi - -# Clean up previous instances. -clean_up - -# Start instance. -start_instance 2>&1 | grep "Hello from Unikraft!" 1>&2 -if test $? -ne 0; then - echo "Wrong message printed." 1>&2 - echo "FAILED" - clean_up - exit 1 -fi - -# Stop instance. -end_with_success diff --git a/cpp-bye/xen.arm64.cfg b/cpp-bye/xen.arm64.cfg deleted file mode 100644 index c860dc9..0000000 --- a/cpp-bye/xen.arm64.cfg +++ /dev/null @@ -1,5 +0,0 @@ -name = "cpp-bye" -vcpus = "1" -kernel = "./out/cpp-bye_xen-arm64" -memory = "8" -type = "pv" diff --git a/cpp-bye/xen.x86_64.cfg b/cpp-bye/xen.x86_64.cfg deleted file mode 100644 index 8faf6c2..0000000 --- a/cpp-bye/xen.x86_64.cfg +++ /dev/null @@ -1,5 +0,0 @@ -name = "cpp-bye" -vcpus = "1" -kernel = "./out/cpp-bye_xen-x86_64" -memory = "8" -type = "pv"