Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Add csr wasm module to repo (#67)
Browse files Browse the repository at this point in the history
* Add csr wasm module to repo

* Add install wasm32-unknown-unknown target to makefile

* Add rustup to all linux users
  • Loading branch information
baluchicken authored Sep 28, 2023
1 parent 931a329 commit 9d56fb0
Show file tree
Hide file tree
Showing 9 changed files with 60,712 additions and 64,920 deletions.
421 changes: 421 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]

members = [
"wasm-modules/csr-rust",
]

[profile.release]
lto = 'thin'
opt-level = "s"
debug = false
22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,24 @@ nasp-objs := third-party/wasm3/source/m3_api_libc.o \
# Set the path to the Kernel build utils.
KBUILD=/lib/modules/$(shell uname -r)/build/

default: static/socket_wasm.h
default: static/socket_wasm.h static/module_csr.h
cd third-party/BearSSL && $(MAKE) linux-km
$(MAKE) -C $(KBUILD) M=$(PWD) V=$(VERBOSE) modules

static/socket_wasm.h: socket.rego
opa build -t wasm -e "socket/allow" socket.rego -o bundle.tar.gz
tar zxvf bundle.tar.gz /policy.wasm
tar zxf bundle.tar.gz /policy.wasm
mv policy.wasm socket.wasm
xxd -i socket.wasm static/socket_wasm.h

CSR_MODULE_DIRS = $(shell find wasm-modules/csr-rust -type d)
CSR_MODULE_FILES = $(shell find wasm-modules/csr-rust -type f -name '*')

static/module_csr.h: wasm-modules/csr-rust $(CSR_MODULE_DIRS) $(CSR_MODULE_FILES)
cargo build --release --target=wasm32-unknown-unknown
cp target/wasm32-unknown-unknown/release/csr-rust.wasm module_csr.wasm
xxd -i module_csr.wasm static/module_csr.h

opa-test:
opa test *.rego -v

Expand Down Expand Up @@ -120,7 +128,15 @@ _install_opa:
sudo curl -L -o /usr/bin/opa https://openpolicyagent.org/downloads/v0.56.0/opa_linux_$(shell go version | cut -f2 -d'/')_static
sudo chmod +x /usr/bin/opa

setup-vm: _debian_deps _install_opa
_install_wasm_target:
sudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
sudo ln -s $$HOME/.cargo/bin/* /usr/bin/
rustup default stable
rustup target add wasm32-unknown-unknown
sudo rustup default stable
sudo rustup target add wasm32-unknown-unknown

setup-vm: _debian_deps _install_opa _install_wasm_target
sudo cp /sys/kernel/btf/vmlinux /usr/lib/modules/`uname -r`/build/

setup-archlinux-vm: _archlinux_deps _install_opa
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int __init nasp_init(void)
}
}

result = load_module("csr_module", module_csr, size_module_csr, NULL);
result = load_module("csr_module", module_csr_wasm, module_csr_wasm_len, NULL);
if (result.err)
{
FATAL("load_module -> csr_module: %s", result.err);
Expand Down
124,463 changes: 59,547 additions & 64,916 deletions static/module_csr.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions wasm-modules/csr-rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
# rustflags = ["-C", "target-feature=+multivalue"]
target = "wasm32-unknown-unknown"
Loading

0 comments on commit 9d56fb0

Please sign in to comment.