Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Include current wit-bindgen configuration #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bindings

36 changes: 36 additions & 0 deletions bindings/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions bindings/bindings.sh
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions bindings/env.wit
Original file line number Diff line number Diff line change
@@ -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<u8>, 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<u8>, 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<u8>, 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)