8000 GitHub - SumairShergill/app-helloworld: A simple "Hello World" application written in C
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A simple "Hello World" application written in C

License

Notifications You must be signed in to change notification settings

SumairShergill/app-helloworld

 
 

Repository files navigation

A "Hello, world!" Application on Unikraft

This application starts a Helloworld application with Unikraft. Follow the instructions below to set up, configure, build and run Helloworld.

To get started immediately, you can use Unikraft's companion command-line companion tool, kraft. Start by running the interactive installer:

curl --proto '=https' --tlsv1.2 -sSf https://get.kraftkit.sh | sudo sh

Once installed, clone this repository and run kraft build:

git clone https://github.com/unikraft/app-helloworld helloworld
cd helloworld/
kraft build

This will guide you through an interactive build process where you can select one of the available targets (architecture/platform combinations). Otherwise, we recommend building for qemu/x86_64 like so:

kraft build --arch x86_64 --plat qemu

Once built, you can instantiate the unikernel via:

kraft run

When left without any input flags, you'll be queried for the desired target architecture/platform.

Work with the Basic Build & Run Toolchain (Advanced)

You ca 8000 n set up, configure, build and run the application from grounds up, without using the companion tool kraft.

Quick Setup (aka TLDR)

For a quick setup, run the commands below. Note that you still need to install the requirements.

For building and running everything for x86_64, follow the steps below:

git clone https://github.com/unikraft/app-helloworld helloworld
cd helloworld/
mkdir .unikraft
git clone https://github.com/unikraft/unikraft .unikraft/unikraft
UK_DEFCONFIG=$(pwd)/.config.helloworld-qemu-x86_64 make defconfig
make -j $(nproc)
/usr/bin/qemu-system-x86_64 -kernel build/helloworld_qemu-x86_64 -nographic

This will configure, build and run the helloworld application, resulting in a Hello world! message being printed, along with the Unikraft banner.

The same can be done for AArch64, by running the commands below:

make properclean
UK_DEFCONFIG=$(pwd)/.config.helloworld-qemu-aarch64 make defconfig
make -j $(nproc)
/usr/bin/qemu-system-aarch64 -kernel build/helloworld_qemu-arm64 -nographic -machine virt -cpu cortex-a57

Similar to the x86_64 build, this will result in a Hello world! message being printed. Information about every step is detailed below.

Requirements

In order to set up, configure, build and run helloworld on Unikraft, the following packages are required:

  • build-essential / base-devel / @development-tools (the meta-package that includes make, gcc and other development-related packages)
  • sudo
  • flex
  • bison
  • git
  • wget
  • uuid-runtime
  • qemu-system-x86
  • qemu-system-arm
  • qemu-kvm
  • sgabios
  • gcc-aarch64-linux-gnu

GCC >= 8 is required to build helloworld on Unikraft.

On Ubuntu/Debian or other apt-based distributions, run the following command to install the requirements:

sudo apt install -y --no-install-recommends \
  build-essential \
  sudo \
  gcc-aarch64-linux-gnu \
  libncurses-dev \
  libyaml-dev \
  flex \
  bison \
  git \
  wget \
  uuid-runtime \
  qemu-kvm \
  qemu-system-x86 \
  qemu-system-arm \
  sgabios

Set Up

The following repositories are required for helloworld:

Follow the steps below for the setup:

  1. First clone the app-helloworld repository in the helloworld/ directory:

    git clone https://github.com/unikraft/app-helloworld helloworld

    Enter the helloworld/ directory:

    cd helloworld/
    
    ls -F

    You will see the contents of the repository:

    .config.helloworld-fc-x86_64  .config.helloworld-qemu-aarch64  .config.helloworld-qemu-x86_64  helloworld-fc-x86_64.json  kraft.yaml  Makefile  Makefile.uk  README.md [...]
    
  2. While inside the helloworld/ directory, create the .unikraft/ directory:

    mkdir .unikraft

    Enter the .unikraft/ directory:

    cd .unikraft/
  3. While inside the .unikraft directory, clone the unikraft repository:

    git clone https://github.com/unikraft/unikraft unikraft
  4. Get back to the application directory:

    cd ../

    Use the tree command to inspect the contents of the .unikraft/ directory. It should print something like this:

    tree -F -L 2 .unikraft/

    You should see the following layout:

    .unikraft/
    `-- unikraft/
        |-- arch/
        |-- Config.uk
        |-- CONTRIBUTING.md
        |-- COPYING.md
        |-- include/
        |-- lib/
        |-- Makefile
        |-- Makefile.uk
        |-- plat/
        |-- README.md
        |-- support/
        `-- version.mk
    
    10 directories, 7 files
    

Configure

Configuring, building and running a Unikraft application depends on our choice of platform and architecture. Currently, supported platforms are QEMU (KVM), Firecaker (KVM), Xen and linuxu. QEMU (KVM) is known to be working, so we focus on that.

Supported architectures are x86_64 and AArch64.

Use the corresponding the configuration files (config-...), according to your choice of platform and architecture.

QEMU x86_64

Use the .config.helloworld-qemu-x86_64 configuration file together with make defconfig to create the configuration file:

UK_DEFCONFIG=$(pwd)/.config.helloworld-qemu-x86_64 make defconfig

This results in the creation of the .config file:

ls .config
.config

The .config file will be used in the build step.

QEMU AArch64

Use the .config.helloworld-qemu-aarch64 configuration file together with make defconfig to create the configuration file:

UK_DEFCONFIG=$(pwd)/.config.helloworld-qemu-aarch64 make defconfig

Similar to the x86_64 configuration, this results in the creation of the .config file that will be used in the build step.

Build

Building uses as input the .config file from above, and results in a unikernel image as output. The unikernel output image, together with intermediary build files, are stored in the build/ directory.

Clean Up

Before starting a build on a different platform or architecture, you must clean up the build output. This may also be required in case of a new configuration.

Cleaning up is done with 3 possible commands:

  • make clean: cleans all actual build output files (binary files, including the unikernel image)
  • make properclean: removes the entire build/ directory
  • make distclean: removes the entire build/ directory and the .config file

Typically, you would use make properclean to remove all build artifacts, but keep the configuration file.

QEMU x86_64

Building for QEMU x86_64 assumes you did the QEMU x86_64 configuration step above. Build the Unikraft helloworld image for QEMU AArch64 by using the command below:

make -j $(nproc)

You will see a list of all the files generated by the build system:

[...]
  LD      helloworld_qemu-x86_64.dbg
  UKBI    helloworld_qemu-x86_64.dbg.bootinfo
  SCSTRIP helloworld_qemu-x86_64
  GZ      helloworld_qemu-x86_64.gz
make[1]: Leaving directory '/media/stefan/projects/unikraft/scripts/workdir/apps/app-helloworld/.unikraft/unikraft'

At the end of the build command, the helloworld_qemu-x86_64 unikernel image is generated. This image is to be used in the run step.

QEMU AArch64

If you had configured and build a unikernel image for another platform or architecture (such as x86_64) before, then:

  1. Do a cleanup step with make properclean.

  2. Configure for QEMU AAarch64, as shown above.

  3. Follow the instructions below to build for QEMU AArch64.

Building for QEMU AArch64 assumes you did the QEMU AArch64 configuration step above. Build the Unikraft helloworld image for QEMU AArch64 by using the same command as for x86_64:

make -j $(nproc)

Same as in the x86_64 setup, you will see a list of all the files generated by the build system:

[...]
  LD      helloworld_qemu-arm64.dbg
  UKBI    helloworld_qemu-arm64.dbg.bootinfo
  SCSTRIP helloworld_qemu-arm64
  GZ      helloworld_qemu-arm64.gz
make[1]: Leaving directory '/media/stefan/projects/unikraft/scripts/workdir/apps/app-helloworld/.unikraft/unikraft'

Similarly to x86_64, at the end of the build command, the helloworld_qemu-arm64 unikernel image is generated. This image is to be used in the run step.

Run

Run the resulting image using qemu-system.

QEMU x86_64

To run the QEMU x86_64 build, use:

/usr/bin/qemu-system-x86_64 -kernel build/helloworld_qemu-x86_64 -nographic

You will be met by the Unikraft banner, along with the Hello, world! message:

qemu-system-x86_64: warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
Powered by
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                  Atlas 0.13.1~5eb820bd
Hello world!

QEMU AArch64

To run the AArch64 build, use:

/usr/bin/qemu-system-aarch64 -kernel build/helloworld_qemu-arm64 -nographic -machine virt -cpu cortex-a57

Same as running on x86_64, the application will start:

Powered by
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                  Atlas 0.13.1~5eb820bd
Hello world!

Building and Running with Firecracker

Firecracker is a lightweight VMM (virtual machine manager) that can be used as more efficient alternative to QEMU.

Configure and build commands are similar to a QEMU-based build with an initrd-based filesystem:

make distclean
UK_DEFCONFIG=$(pwd)/.config.helloworld-fc-x86_64 make defconfig
make -j $(nproc)

To use Firecraker, you need to download a Firecracker release. You can use the commands below to make the firecracker-x86_64 executable from release v1.4.0 available globally in the command line:

cd /tmp
wget https://github.com/firecracker-microvm/firecracker/releases/download/v1.4.0/firecracker-v1.4.0-x86_64.tgz
tar xzf firecracker-v1.4.0-x86_64.tgz
sudo cp release-v1.4.0-x86_64/firecracker-v1.4.0-x86_64 /usr/local/bin/firecracker-x86_64

To run a unikernel image, you need to configure a JSON file. This is the helloworld-fc-x86_64.json file. Pass this file to the firecracker-x86_64 command to run the Unikernel instance:

rm /tmp/firecracker.socket
firecracker-x86_64 --api-sock /tmp/firecracker.socket --config-file helloworld-fc-x86_64.json

Same as running with QEMU, the application will start:

546C
Powered by
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                  Atlas 0.13.1~2f2ecc9f
Hello world!

About

A simple "Hello World" application written in C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 98.3%
  • Makefile 1.7%
0