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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ruby-hello/Config.uk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config APPRUBYHELLO
bool "ruby-hello"
default y
select LIBRUBY
select LIBNEWLIBC
select LIBLWIP
select LIBPTHREAD_EMBEDDED
9 changes: 9 additions & 0 deletions ruby-hello/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
UK_ROOT ?= $(PWD)/workdir/unikraft
UK_LIBS ?= $(PWD)/workdir/libs
LIBS := $(UK_LIBS)/newlib:$(UK_LIBS)/lwip:$(UK_LIBS)/pthread-embedded:$(UK_LIBS)/ruby:$(UK_LIBS)/compiler-rt

all:
@make -C $(UK_ROOT) A=$(PWD) L=$(LIBS)

$(MAKECMDGOALS):
@make -C $(UK_ROOT) A=$(PWD) L=$(LIBS) $(MAKECMDGOALS)
4 changes: 4 additions & 0 deletions ruby-hello/Makefile.uk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$(eval $(call addlib,apprubyhello))

# Adding the rootfs directory as the filesystem entry point
APP_ROOTFS_FLAGS-y += -DROOTFS_DIR=\"$(APP_BASE)/rootfs\"
51 changes: 51 additions & 0 deletions ruby-hello/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Ruby Hello on Unikraft

Build and run a Ruby Hello program as a Unikraft unikernel. Follow the instructions below to set up, configure, build, and run the application using the standard Makefile-based workflow.

## Set Up

Set up the required repositories by creating symbolic links to the central resource directory. Be sure to run the top-level setup.sh script first to populate the global repos/ directory.

## Shell

```console
./setup.sh
```

## Clean

While not strictly required, it is safest to clean the previous build artifacts before a new configuration:

```console
make distclean
```

## Configure

To configure the unikernel, use the standard menu interface:

```console
make menuconfig
```

In the menu, select the target architecture (e.g., x86_64) and the platform (e.g., KVM guest). Under Library Configuration, ensure ruby is selected and configure any necessary extensions.

## Build

Build the application for the current configuration:

```console
make -j $(nproc)
```

The resulting unikernel image will be created in the build/ directory as ruby-hello_kvm-x86_64.

## Run
To run the resulting image on Firecracker (x86_64), use the following command:

```console
rm -f firecracker.socket
firecracker-x86_64 --config-file fc.x86_64.json --api-sock firecracker.socket
```

A successful run will start the Ruby interpreter and execute the helloworld.rb script inside the unikernel.
12 changes: 12 additions & 0 deletions ruby-hello/fc.x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"boot-source": {
"kernel_image_path": "build/ruby-hello_kvm-x86_64",
"boot_args": "ruby-hello_kvm-x86_64 -- /helloworld.rb"
},
"drives": [],
"machine-config": {
"vcpu_count": 1,
"mem_size_mib": 256,
"ht_enabled": false
}
}
1 change: 1 addition & 0 deletions ruby-hello/helloworld.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts 'Hello, world!'
37 changes: 37 additions & 0 deletions ruby-hello/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

check_exists_and_create_symlink()
{
path="$1"

if ! test -d workdir/"$path"; then
if ! test -d ../repos/"$path"; then
echo "No directory ../repos/$path. Run the top-level setup.sh script first." 1>&2
exit 1
fi
depth=$(echo "$path" | awk -F / '{ print NF }')
if test "$depth" -eq 1; then
ln -sfn ../../repos/"$path" workdir/"$path"
elif test "$depth" -eq 2; then
ln -sfn ../../../repos/"$path" workdir/"$path"
else
echo "Unknown depth of path $path." 1>&2
exit 1
fi
fi
}

if ! test -d workdir; then
mkdir workdir
fi

if ! test -d workdir/libs; then
mkdir workdir/libs
fi

check_exists_and_create_symlink "unikraft"
check_exists_and_create_symlink "libs/newlib"
check_exists_and_create_symlink "libs/lwip"
check_exists_and_create_symlink "libs/compiler-rt"
check_exists_and_create_symlink "libs/pthread-embedded"
check_exists_and_create_symlink "libs/ruby"
5 changes: 5 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ test -d repos/apps/elfloader || git clone https://github.com/unikraft/app-elfloa
test -d repos/libs/redis || git clone https://github.com/unikraft/lib-redis repos/libs/redis
test -d repos/libs/wamr || git clone https://github.com/unikraft/lib-wamr repos/libs/wamr
test -d repos/libs/sqlite || git clone https://github.com/unikraft/lib-sqlite repos/libs/sqlite

# for ruby
test -d repos/libs/newlib || git clone https://github.com/unikraft/lib-newlib repos/libs/newlib
test -d repos/libs/pthread-embedded || git clone https://github.com/unikraft/lib-pthread-embedded repos/libs/pthread-embedded
test -d repos/libs/ruby || git clone https://github.com/unikraft/lib-ruby repos/libs/ruby