TOOLCHAIN := x86_64-unknown-linux-musl
VPATH = target/system target/$(TOOLCHAIN)/debug target/$(TOOLCHAIN)/release
SRCS := $(shell find . -type f -name '*.rs' | grep -v 'tests')
ID := $(shell date +%s)
.PHONY: all check clean vsock kmod vm
all: vsock echo_server
check: vsock echo_server test
test:
cargo test --all
fmt:
cargo fmt --all -- --check
clippy:
cargo clippy --all-targets --all-features -- -D warnings
clean:
cargo clean
vsock: $(SRCS)
cargo build --lib
echo_server: vsock echo_server/src/main.rs
cargo build --manifest-path=echo_server/Cargo.toml
kmod:
sudo /sbin/modprobe -r vmw_vsock_vmci_transport
sudo /sbin/modprobe -r vmw_vsock_virtio_transport_common
sudo /sbin/modprobe -r vsock
sudo /sbin/modprobe vhost_vsock
vm: initrd.cpio
sudo qemu-system-x86_64 -kernel test_fixture/bzImage -initrd target/$(TOOLCHAIN)/debug/initrd.cpio \
-enable-kvm -m 256 -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3 -nographic -append "console=ttyS0"
vm-for-action: initrd.cpio
sudo qemu-system-x86_64 -kernel test_fixture/bzImage -initrd target/$(TOOLCHAIN)/debug/initrd.cpio \
-m 256 -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3 -display none -daemonize -append "console=ttyS0"
initrd.cpio: echo_server
-rm -f target/$(TOOLCHAIN)/debug/initrd.cpio
mkdir -p /tmp/$(ID)
cp test_fixture/busybox.cpio /tmp/$(ID)/initrd.cpio
cp test_fixture/init /tmp/$(ID)/init
cp echo_server/target/$(TOOLCHAIN)/debug/echo_server /tmp/$(ID)/
(cd '/tmp/$(ID)' && find . | grep -v 'initrd.cpio' | cpio -H newc -o --append -F initrd.cpio)
mv /tmp/$(ID)/initrd.cpio target/$(TOOLCHAIN)/debug/
rm -Rf /tmp/$(ID)