From 8254bb21d3329ff86059c68e38d8e259d84f28bd Mon Sep 17 00:00:00 2001 From: Flaki Date: Tue, 4 Apr 2023 00:15:43 +0300 Subject: [PATCH] Classic wit-bindgen setup --- bindings/.gitignore | 2 ++ bindings/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ bindings/bindings.sh | 8 ++++++++ bindings/env.wit | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 bindings/.gitignore create mode 100644 bindings/Dockerfile create mode 100755 bindings/bindings.sh create mode 100644 bindings/env.wit diff --git a/bindings/.gitignore b/bindings/.gitignore new file mode 100644 index 0000000..5b43bd3 --- /dev/null +++ b/bindings/.gitignore @@ -0,0 +1,2 @@ +bindings + diff --git a/bindings/Dockerfile b/bindings/Dockerfile new file mode 100644 index 0000000..cfbfdc5 --- /dev/null +++ b/bindings/Dockerfile @@ -0,0 +1,36 @@ +# Download and build a compatible version wit-bindgen +# Originally from: +# https://github.com/ospencer/witx-bindgen/tree/oscar/js-buffer-size +FROM rust:slim-bullseye AS tooling + +RUN apt update && apt install -y git + +WORKDIR /tmp + +RUN mkdir witx-bindgen && \ + git clone https://github.com/bytecodealliance/wit-bindgen.git --single-branch wit-bindgen && \ + cd wit-bindgen && \ + git checkout 48f364d1d4e42275b219d0862af8aa8b17c49d51 && \ + cargo build --release + +# Executable in /tmp/wit-bindgen/target/release/wit-bindgen + + +FROM rust:slim-bullseye AS sdk + +#RUN mkdir wit-bindgen && \ +# git clone https://github.com/suborbital/sdk.git --single-branch --branch v0.16.3 && \ +# cd wit-bindgen && \ + +WORKDIR /tmp + +COPY --from=tooling /tmp/wit-bindgen/target/release/wit-bindgen /usr/bin/ +COPY env.wit . + +# Generate JS & TS bindings +RUN wit-bindgen js --import env.wit + +# Generate Rust bindings +RUN wit-bindgen rust-wasm --import env.wit + +CMD wit-bindgen --help diff --git a/bindings/bindings.sh b/bindings/bindings.sh new file mode 100755 index 0000000..0fa3e08 --- /dev/null +++ b/bindings/bindings.sh @@ -0,0 +1,8 @@ +# Build and test +docker build . -t se2-sdk-bindings +docker run -t se2-sdk-bindings ls -a /tmp + +# Extract the built files +id=$(docker create se2-sdk-bindings:latest) +docker cp $id:/tmp ./bindings +docker rm -v $id diff --git a/bindings/env.wit b/bindings/env.wit new file mode 100644 index 0000000..19ed5ae --- /dev/null +++ b/bindings/env.wit @@ -0,0 +1,36 @@ +enum log-level { + null, + error, + warn, + info, + debug +} +enum http-method { + get, + head, + options, + post, + put, + patch, + delete +} +enum field-type { + meta, + body, + header, + params, + state, + query +} + +return-result: function(res: list, ident: u32) +return-error: function(code: s32, res: string, ident: u32) +log-msg: function(msg: string, level: log-level, ident: u32) +fetch-url: function(method: http-method, url: string, body: list, ident: u32) -> s32 +graphql-query: function(endpoint: string, query: string, ident: u32) -> s32 +request-get-field: function(field-type: field-type, key: string, ident: u32) -> s32 +request-set-field: function(field-type: field-type, key: string, value: list, ident: u32) -> s32 +resp-set-header: function(key: string, value: string, ident: u32) +get-ffi-result: function(ptr: u32, ident: u32) -> s32 +add-ffi-var: function(name: string, val: string, ident: u32) -> s32 +return-abort: function(msg: string, file: string, line-num: u32, col-num: u32, ident: u32)