Skip to content

Commit 22a5ffd

Browse files
committed
chore(lua): introduce Lua 5.4 application and add .gitignore
- Add `lua/` directory: - `Config.uk`: application configuration with Nginx-style comments - `Makefile`: flatten rules under all/clean/% targets, remove commented lines - `Makefile.uk`: placeholder required by the build system - `README.md`: clean formatting (one sentence per line, inline code, tabs) - `fc.arm64.json`: Firecracker configuration for ARM64 target - Add `.gitignore` for `lua/` directory to: - Ignore workdir/build artifacts - Ignore Kconfig-generated files and editor junk Signed-off-by: Dana-Maria04 <caruntudana@yahoo.com>
1 parent 3c8ca01 commit 22a5ffd

File tree

12 files changed

+286
-0
lines changed

12 files changed

+286
-0
lines changed

lua/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/9pfs-rootfs/
2+
/workdir/

lua/Config.uk

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Configure Lua Hello example
2+
# A minimal Unikraft unikernel that runs a Lua script.
3+
# Enable core Lua runtime, filesystem and POSIX environment support.
4+
5+
config APPLUA
6+
bool "Lua Hello example"
7+
default y
8+
9+
# Select the core Lua runtime library.
10+
select LIBLUA
11+
# Select the application’s main function entrypoint (Lua interpreter)
12+
select LIBLUA_MAIN_FUNCTION
13+
14+
# Select filesystem core components:
15+
# vfscore + automount, CPIO support, ramfs, devfs.
16+
# These provide an in-memory filesystem and device nodes.
17+
select LIBVFSCORE
18+
select LIBVFSCORE_AUTOMOUNT_UP
19+
select LIBUKCPIO
20+
select LIBRAMFS
21+
select LIBDEVFS
22+
select LIBDEVFS_AUTOMOUNT
23+
select LIBDEVFS_DEVSTDOUT
24+
25+
# Select POSIX environment support for getenv/putenv.
26+
select LIBPOSIX_ENVIRON
27+
# Use library-parameter parsing for environment variables.
28+
select LIBPOSIX_ENVIRON_LIBPARAM

lua/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
UK_ROOT ?= $(PWD)/../repos/unikraft
2+
UK_BUILD ?= $(PWD)/workdir/build
3+
UK_APP ?= $(PWD)
4+
LIBS_BASE := $(PWD)/../repos/libs
5+
6+
UK_LIBS ?= $(LIBS_BASE)/musl:$(LIBS_BASE)/lua
7+
8+
.PHONY: all clean run
9+
10+
all:
11+
@$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD)
12+
13+
clean:
14+
@$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) properclean
15+
@rm -rf $(UK_BUILD)
16+
17+
%:
18+
@$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) $@

lua/Makefile.uk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$(eval $(call addlib,applua))

lua/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Lua 5.4 on Unikraft
2+
3+
Build and run a Lua 5.4 program on Unikraft.
4+
Follow the instructions below to set up, configure, build and run Lua.
5+
Make sure you installed the [requirements](../README.md#requirements).
6+
7+
## Quick Setup (aka TLDR)
8+
9+
For a quick setup, run the commands below.
10+
Note that you still need to install the [requirements](../README.md#requirements).
11+
Before everything, make sure you run the top-level `setup.sh` script:
12+
13+
```console
14+
./setup.sh
15+
```
16+
17+
To build and run the application for x86_64, use:
18+
19+
```console
20+
./setup.sh
21+
make distclean
22+
wget -O /tmp/defconfig \
23+
https://raw.githubusercontent.com/unikraft/catalog-core/refs/heads/scripts/lua/scripts/defconfig/qemu.x86_64
24+
UK_DEFCONFIG=/tmp/defconfig make defconfig
25+
make -j $(nproc)
26+
./workdir/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/
27+
qemu-system-x86_64 \
28+
-nographic \
29+
-m 32 \
30+
-cpu max \
31+
-kernel workdir/build/lua_qemu-x86_64 \
32+
-append "lua_qemu-x86_64 vfs.fstab=[\"initrd0:/:extract::ramfs=1:\"] -- /helloworld.lua" \
33+
-initrd ./initrd.cpio
34+
```
35+
36+
This will configure, build and run the Helloworld Lua app, printing “Hello, World!”.
37+
38+
To do the same for AArch64, run:
39+
```console
40+
make distclean
41+
wget -O /tmp/defconfig \
42+
https://raw.githubusercontent.com/unikraft/catalog-core/refs/heads/scripts/lua/scripts/defconfig/qemu.arm64
43+
UK_DEFCONFIG=/tmp/defconfig make defconfig
44+
make -j $(nproc)
45+
qemu-system-aarch64 -nographic -machine virt -m 128 -cpu max \
46+
-kernel workdir/build/lua_fc-arm64
47+
```
48+
Similar to the x86_64 build, this will print “Hello, World!” on ARM64.
49+
50+
Information about every step and other build types is detailed below.
51+
52+
## Set Up
53+
54+
Set up the required repositories.
55+
You have two options:
56+
57+
Use the setup.sh script:
58+
```console
59+
./setup.sh
60+
```
61+
It will clone/link `lib-lua` and any other needed libs under `repos/libs/.`
62+
63+
Manual setup:
64+
65+
```console
66+
test -d repos/libs/lua || \
67+
git clone https://github.com/unikraft/lib-lua repos/libs/lua
68+
```
69+
70+
## Clean
71+
72+
While not strictly required, it is safest to clean previous build artifacts:
73+
74+
```console
75+
make distclean
76+
```
77+
78+
## Configure
79+
80+
To configure the kernel, use:
81+
82+
```console
83+
make menuconfig
84+
```
85+
86+
Select the Architecture (x86_64 or ARM64), then platform (QEMU, Firecracker, Xen), and save to produce the `.config` file.
87+
88+
## Build
89+
90+
Build the application for the current configuration:
91+
92+
```console
93+
make -j $(nproc)
94+
```
95+
96+
This produces the unikernel at `workdir/build/lua_<plat>-<arch>`.
97+
98+
## Run
99+
100+
Run the resulting image using the corresponding platform tool.
101+
102+
### QEMU/x86_64
103+
104+
```console
105+
qemu-system-x86_64 -nographic -m 128 -cpu max \
106+
-kernel workdir/build/lua_qemu-x86_64
107+
```
108+
109+
### QEMU/ARM64
110+
111+
```console
112+
qemu-system-aarch64 -nographic -machine virt -m 128 -cpu max \
113+
-kernel workdir/build/lua_fc-arm64
114+
```
115+
116+
### Firecracker/x86_64
117+
118+
```console
119+
rm -f firecracker.socket
120+
firecracker-x86_64 --config-file fc.x86_64.json --api-sock firecracker.socket
121+
```
122+
123+
### Firecracker/ARM64
124+
125+
```console
126+
rm -f firecracker.socket
127+
firecracker-aarch64 --config-file fc.arm64.json --api-sock firecracker.socket
128+
```
129+
130+
### Xen/x86_64
131+
132+
```console
133+
sudo xl create -c xen.x86_64.cfg
134+
```
135+
136+
### Run on Xen/x86_64
137+
138+
```console
139+
sudo xl create -c xen.x86_64.cfg
140+
```
141+
142+
You need use `sudo` or the `root` account to run Xen.
143+
144+
### Run on Xen/ARM64
145+
146+
```console
147+
sudo xl create -c xen.arm64.cfg
148+
```
149+
150+
You need use `sudo` or the `root` account to run Xen.
151+
152+
## Clean Up
153+
154+
Doing a new configuration, or a new build may require cleaning up the configuration and build artifacts.
155+
156+
In order to remove the build artifacts, use:
157+
158+
```console
159+
make clean
160+
```
161+
162+
In order to remove fetched files also, that is the removal of the `workdir/build/` directory, use:
163+
164+
```console
165+
make properclean
166+
```
167+
168+
In order to remove the generated `.config` file as well, use:
169+
170+
```console
171+
make distclean
172+
```

lua/fc.arm64.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"boot-source": {
3+
"kernel_image_path": "workdir/build/lua_fc-arm64"
4+
},
5+
"drives": [],
6+
"machine-config": {
7+
"vcpu_count": 1,
8+
"mem_size_mib": 8,
9+
"smt": false,
10+
"track_dirty_pages": false
11+
}
12+
}

lua/fc.x86_64.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"boot-source": {
3+
"kernel_image_path": "workdir/build/lua_fc-x86_64"
4+
},
5+
"drives": [],
6+
"machine-config": {
7+
"vcpu_count": 1,
8+
"mem_size_mib": 8,
9+
"smt": false,
10+
"track_dirty_pages": false
11+
}
12+
}

lua/helloworld.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, World!")

lua/setup.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
check_exists_and_create_symlink()
4+
{
5+
path="$1"
6+
7+
if [ ! -d workdir/"$path" ]; then
8+
if [ ! -d ../repos/"$path" ]; then
9+
echo "No directory ../repos/$path. Run the top-level setup.sh script first." >&2
10+
exit 1
11+
fi
12+
13+
depth=$(echo "$path" | awk -F/ '{ print NF }')
14+
if [ "$depth" -eq 1 ]; then
15+
ln -sfn ../../repos/"$path" workdir/"$path"
16+
elif [ "$depth" -eq 2 ]; then
17+
ln -sfn ../../../repos/"$path" workdir/"$path"
18+
else
19+
echo "Unknown depth of path $path." >&2
20+
exit 1
21+
fi
22+
fi
23+
}
24+
25+
test -d workdir || mkdir workdir
26+
test -d workdir/libs || mkdir workdir/libs
27+
28+
check_exists_and_create_symlink "unikraft"
29+
check_exists_and_create_symlink "libs/lua"

lua/xen.arm64.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name = "applua"
2+
vcpus = "1"
3+
kernel = "./workdir/build/lua_xen-arm64"
4+
memory = "8"
5+
type = "pv"

0 commit comments

Comments
 (0)