Refactor build_artifacts.sh and makefile
- Move everything to .data, .vendor, .artifacts and .bin in order to cleanly separate build input and output.
- Sprinkle some subshells on build_artifacts.sh to make it fail more gracefully.
- Fix fetch_third_party.sh check.
- GOBUILD make helper.
- Dockerfile with build dependencies.
Test Plan:
Ran `make clean` and build steps described in README.md, it boots:
{P84}
X-Origin-Diff: phab/D195
GitOrigin-RevId: 4106534c7248931b79e93e2a13153482033cd0d8
diff --git a/.bazelversion b/.bazelversion
new file mode 100644
index 0000000..3eefcb9
--- /dev/null
+++ b/.bazelversion
@@ -0,0 +1 @@
+1.0.0
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c2b0464
--- /dev/null
+++ b/README.md
@@ -0,0 +1,28 @@
+# Smalltown Operating System
+
+## Run build
+
+The build uses a Fedora 30 base image with a set of dependencies:
+
+```
+modprobe kvm
+
+podman build -t smalltown-builder .
+
+podman run -it --rm \
+ -v $(pwd):/work \
+ -v /dev/null:/work/.git \
+ -v /dev/null:/work/.idea \
+ -v /dev/null:/work/.arcconfig \
+ --device /dev/kvm \
+ smalltown-builder bash
+
+scripts/fetch_third_party.sh
+scripts/build_artifacts.sh
+
+make launch
+```
+
+Exit qemu using the monitor console: `Ctrl-A c quit`.
+
+If your host is low on entropy, consider running rngd from rng-tools for development.
diff --git a/kernel/initramfs.list b/kernel/initramfs.list
index 9bb0645..8fcb966 100644
--- a/kernel/initramfs.list
+++ b/kernel/initramfs.list
@@ -1,6 +1,6 @@
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
nod /dev/null 0644 0 0 c 1 3
-file /init ../../cmd/init/init 0755 0 0
+file /init ../../.bin/init 0755 0 0
dir /bin 0755 0 0
-file /bin/mkfs.xfs ../../third_party/xfsprogs-dev/mkfs/mkfs.xfs 0755 0 0
\ No newline at end of file
+file /bin/mkfs.xfs ../../.artifacts/mkfs.xfs 0755 0 0
diff --git a/scripts/build_artifacts.sh b/scripts/build_artifacts.sh
index 9ec4d5c..de1addc 100755
--- a/scripts/build_artifacts.sh
+++ b/scripts/build_artifacts.sh
@@ -1,47 +1,76 @@
#!/usr/bin/env bash
set -eo pipefail
-if [ ! -d "$root/linux" ] ; then
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+ROOT=$(realpath ${DIR}/../.vendor)
+
+echo "Vendor build root: $ROOT"
+
+if [ ! -d "$ROOT/linux" ] ; then
echo "Please first call scripts/fetch_third_party.sh"
+ exit 1
fi
-root=$(git rev-parse --show-toplevel)/third_party
-
-# nasm + Python 3.7 + iasl
-if [ ! -d "$root/edk2" ] ; then
- git clone --recurse-submodules https://github.com/tianocore/edk2 $root/edk2
+if [ ! -d "$ROOT/edk2" ] ; then
+ git clone --single-branch --branch edk2-stable201908 --depth=1 --recurse-submodules https://github.com/tianocore/edk2 $ROOT/edk2
fi
-cd $root/edk2
-git checkout --recurse-submodules edk2-stable201908
-. edksetup.sh
-make -C $root/edk2/BaseTools/Source/C
-build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -t GCC5 -a X64 -b RELEASE -p $PWD/OvmfPkg/OvmfPkgX64.dsc
-musl_prefix=$root/musl-prefix
+(
+ cd $ROOT/edk2
+ . edksetup.sh
+ make -C BaseTools/Source/C
+ build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE -t GCC5 -a X64 -b RELEASE -p $PWD/OvmfPkg/OvmfPkgX64.dsc
-cd $root/linux
-make headers_install ARCH=x86_64 INSTALL_HDR_PATH=$musl_prefix
+ cp Build/OvmfX64/RELEASE_GCC5/FV/{OVMF_CODE.fd,OVMF_VARS.fd} $ROOT/../.artifacts
+)
-mkdir -p $root/musl
-curl -L https://www.musl-libc.org/releases/musl-1.1.23.tar.gz | tar -xzf - -C $root/musl --strip-components 1
-cd $root/musl
+musl_prefix=$ROOT/musl-prefix
-./configure --prefix=$musl_prefix --syslibdir=$musl_prefix/lib
-make -j8
-make install
+(
+ cd $ROOT/linux
+ make headers_install ARCH=x86_64 INSTALL_HDR_PATH=$musl_prefix
+)
-mkdir -p $root/util-linux
-curl -L https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/snapshot/util-linux-2.34.tar.gz | tar -xzf - -C $root/util-linux --strip-components 1
-cd $root/util-linux
-./autogen.sh
-./configure CC=$musl_prefix/bin/musl-gcc --without-systemd --without-udev --without-btrfs --disable-pylibmount --without-tinfo --prefix=$musl_prefix --disable-makeinstall-chown --disable-makeinstall-setuid --with-bashcompletiondir=$musl_prefix/usr/share/bash-completion
-make -j8
-make install
+mkdir -p $ROOT/musl
+curl -L https://www.musl-libc.org/releases/musl-1.1.23.tar.gz | tar -xzf - -C $ROOT/musl --strip-components 1
-mkdir -p $root/xfsprogs-dev
-curl -L https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/snapshot/xfsprogs-dev-5.2.1.tar.gz | tar -xzf - -C $root/xfsprogs-dev --strip-components 1
-cd $root/xfsprogs-dev
-patch -p1 < ../../patches/xfsprogs-dev/*.patch
-./configure CC=$musl_prefix/bin/musl-gcc "CFLAGS=-static -I$musl_prefix/include -L$musl_prefix/lib" "LDFLAGS=-L$musl_prefix/lib"
-make -j8 mkfs
-cp $root/xfsprogs-dev/mkfs/mkfs.xfs
\ No newline at end of file
+(
+ cd $ROOT/musl
+
+ ./configure --prefix=$musl_prefix --syslibdir=$musl_prefix/lib
+ make -j8
+ make install
+)
+
+mkdir -p $ROOT/util-linux
+curl -L https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/snapshot/util-linux-2.34.tar.gz | tar -xzf - -C $ROOT/util-linux --strip-components 1
+
+(
+ cd $ROOT/util-linux
+ ./autogen.sh
+ ./configure \
+ CC=$musl_prefix/bin/musl-gcc \
+ --without-systemd \
+ --without-udev \
+ --without-btrfs \
+ --disable-pylibmount \
+ --without-tinfo \
+ --prefix=$musl_prefix \
+ --disable-makeinstall-chown \
+ --disable-makeinstall-setuid \
+ --with-bashcompletiondir=$musl_prefix/usr/share/bash-completion
+ make -j8
+ make install
+)
+
+mkdir -p $ROOT/xfsprogs-dev
+curl -L https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/snapshot/xfsprogs-dev-5.2.1.tar.gz | tar -xzf - -C $ROOT/xfsprogs-dev --strip-components 1
+
+(
+ cd $ROOT/xfsprogs-dev
+ patch -p1 < ../../patches/xfsprogs-dev/*.patch
+ make configure
+ ./configure CC=$musl_prefix/bin/musl-gcc "CFLAGS=-static -I$musl_prefix/include -L$musl_prefix/lib" "LDFLAGS=-L$musl_prefix/lib"
+ make -j8 mkfs
+ cp $ROOT/xfsprogs-dev/mkfs/mkfs.xfs $ROOT/../.artifacts
+)
diff --git a/scripts/fetch_third_party.sh b/scripts/fetch_third_party.sh
index c9edaca..537b19a 100755
--- a/scripts/fetch_third_party.sh
+++ b/scripts/fetch_third_party.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
-mkdir -p third_party/linux
-curl -L https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.72.tar.xz | tar -xJf - -C third_party/linux --strip-components 1
-ln -fs ../../kernel/linux-smalltown.config third_party/linux/.config
\ No newline at end of file
+mkdir -p .vendor/linux
+curl -L https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.72.tar.xz | tar -xJf - -C .vendor/linux --strip-components 1
+ln -rfs kernel/linux-smalltown.config .vendor/linux/.config
diff --git a/scripts/launch.sh b/scripts/launch.sh
index 7170bca..aad121f 100755
--- a/scripts/launch.sh
+++ b/scripts/launch.sh
@@ -1,18 +1,19 @@
#!/bin/sh
-swtpm socket --tpmstate dir=$PWD/vm/tpm --ctrl type=unixio,path=$PWD/vm/tpm/swtpm-sock --tpm2 &
+swtpm socket --tpmstate dir=$PWD/.data/tpm --ctrl type=unixio,path=$PWD/.data/swtpm-sock --tpm2 &
-qemu-system-x86_64 -cpu host -smp sockets=1,cpus=1,cores=2,threads=2,maxcpus=4 -m 1024 -machine q35 -enable-kvm -nographic -nodefaults \
- -drive if=pflash,format=raw,readonly,file=$PWD/third_party/edk2/Build/OvmfX64/RELEASE_GCC5/FV/OVMF_CODE.fd \
- -drive if=pflash,format=raw,snapshot=on,file=$PWD/third_party/edk2/Build/OvmfX64/RELEASE_GCC5/FV/OVMF_VARS.fd \
- -drive if=virtio,format=raw,cache=unsafe,file=$PWD/vm/smalltown.img \
+qemu-system-x86_64 \
+ -cpu host -smp sockets=1,cpus=1,cores=2,threads=2,maxcpus=4 -m 1024 -machine q35 -enable-kvm -nographic -nodefaults \
+ -drive if=pflash,format=raw,readonly,file=$PWD/.artifacts/OVMF_CODE.fd \
+ -drive if=pflash,format=raw,snapshot=on,file=$PWD/.artifacts/OVMF_VARS.fd \
+ -drive if=virtio,format=raw,cache=unsafe,file=$PWD/.data/smalltown.img \
-netdev user,id=net0,hostfwd=tcp::7833-:7833,hostfwd=tcp::7834-:7834 \
-device virtio-net-pci,netdev=net0 \
- -chardev socket,id=chrtpm,path=$PWD/vm/tpm/swtpm-sock \
+ -chardev socket,id=chrtpm,path=$PWD/.data/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis,tpmdev=tpm0 \
- -debugcon file:vm/debug.log \
+ -debugcon file:.data/debug.log \
-global isa-debugcon.iobase=0x402 \
-device ipmi-bmc-sim,id=ipmi0 \
-device virtio-rng-pci \
- -serial mon:stdio
\ No newline at end of file
+ -serial mon:stdio