| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
TOOLCHAIN := x86_64-unknown-linux-musl |
| 17 |
VPATH = target/system target/$(TOOLCHAIN)/debug target/$(TOOLCHAIN)/release |
| 18 |
|
| 19 |
SRCS := $(shell find . -type f -name '*.rs' | grep -v 'tests') |
| 20 |
ID := $(shell date +%s) |
| 21 |
|
| 22 |
.PHONY: all check clean vsock kmod vm |
| 23 |
|
| 24 |
all: vsock echo_server |
| 25 |
|
| 26 |
check: vsock echo_server test |
| 27 |
|
| 28 |
test: |
| 29 |
cargo test --all |
| 30 |
|
| 31 |
fmt: |
| 32 |
cargo fmt --all -- --check |
| 33 |
|
| 34 |
clippy: |
| 35 |
cargo clippy --all-targets --all-features -- -D warnings |
| 36 |
|
| 37 |
clean: |
| 38 |
cargo clean |
| 39 |
|
| 40 |
vsock: $(SRCS) |
| 41 |
cargo build --lib |
| 42 |
|
| 43 |
echo_server: vsock echo_server/src/main.rs |
| 44 |
cargo build --manifest-path=echo_server/Cargo.toml |
| 45 |
|
| 46 |
|
| 47 |
kmod: |
| 48 |
sudo /sbin/modprobe -r vmw_vsock_vmci_transport |
| 49 |
sudo /sbin/modprobe -r vmw_vsock_virtio_transport_common |
| 50 |
sudo /sbin/modprobe -r vsock |
| 51 |
sudo /sbin/modprobe vhost_vsock |
| 52 |
|
| 53 |
|
| 54 |
vm: initrd.cpio |
| 55 |
sudo qemu-system-x86_64 -kernel test_fixture/bzImage -initrd target/$(TOOLCHAIN)/debug/initrd.cpio \ |
| 56 |
-enable-kvm -m 256 -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3 -nographic -append "console=ttyS0" |
| 57 |
|
| 58 |
|
| 59 |
vm-for-action: initrd.cpio |
| 60 |
sudo qemu-system-x86_64 -kernel test_fixture/bzImage -initrd target/$(TOOLCHAIN)/debug/initrd.cpio \ |
| 61 |
-m 256 -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3 -display none -daemonize -append "console=ttyS0" |
| 62 |
|
| 63 |
|
| 64 |
initrd.cpio: echo_server |
| 65 |
-rm -f target/$(TOOLCHAIN)/debug/initrd.cpio |
| 66 |
mkdir -p /tmp/$(ID) |
| 67 |
cp test_fixture/busybox.cpio /tmp/$(ID)/initrd.cpio |
| 68 |
cp test_fixture/init /tmp/$(ID)/init |
| 69 |
cp echo_server/target/$(TOOLCHAIN)/debug/echo_server /tmp/$(ID)/ |
| 70 |
(cd '/tmp/$(ID)' && find . | grep -v 'initrd.cpio' | cpio -H newc -o --append -F initrd.cpio) |
| 71 |
mv /tmp/$(ID)/initrd.cpio target/$(TOOLCHAIN)/debug/ |
| 72 |
rm -Rf /tmp/$(ID) |