|
| 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 | +``` |
0 commit comments