diff --git a/.github/workflows/wasi-bindings.yml b/.github/workflows/wasi-bindings.yml new file mode 100644 index 00000000000..8bc5142e16e --- /dev/null +++ b/.github/workflows/wasi-bindings.yml @@ -0,0 +1,43 @@ +name: WASI Bindings + +on: + push: + paths: + - ".github/workflows/wasi-bindings.yml" + - "include/" + - "src/" + - "*akefile*" + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: head + bundler-cache: true + + - name: rake templates + run: bundle exec rake templates + + - name: Create build directory + run: mkdir -p build + + - name: Set up WASI-SDK + run: | + wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz + tar xvf wasi-sdk-20.0-linux.tar.gz + + - name: Build the project + run: make wasm WASI_SDK_PATH=$(pwd)/wasi-sdk-20.0 + + - uses: actions/upload-artifact@v3 + with: + name: prism.wasm + path: build/prism.wasm diff --git a/Makefile b/Makefile index 8e1c4b20d47..d64d968656f 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]') CPPFLAGS := -Iinclude CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -fPIC -fvisibility=hidden CC := cc +WASI_SDK_PATH := /opt/wasi-sdk HEADERS := $(shell find include -name '*.h') SOURCES := $(shell find src -name '*.c') @@ -23,6 +24,7 @@ all: shared static shared: build/librubyparser.$(SOEXT) static: build/librubyparser.a +wasm: build/prism.wasm build/librubyparser.$(SOEXT): $(SHARED_OBJECTS) $(ECHO) "linking $@" @@ -32,6 +34,10 @@ build/librubyparser.a: $(STATIC_OBJECTS) $(ECHO) "building $@" $(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null) +build/prism.wasm: Makefile $(SOURCES) $(HEADERS) + $(ECHO) "building $@" + $(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES) + build/shared/%.o: src/%.c Makefile $(HEADERS) $(ECHO) "compiling $@" $(Q) mkdir -p $(@D) diff --git a/templates/src/serialize.c.erb b/templates/src/serialize.c.erb index e985e72ec38..9528496c7df 100644 --- a/templates/src/serialize.c.erb +++ b/templates/src/serialize.c.erb @@ -150,11 +150,11 @@ static void pm_serialize_magic_comment(pm_parser_t *parser, pm_magic_comment_t *magic_comment, pm_buffer_t *buffer) { // serialize key location pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(magic_comment->key_start - parser->start)); - pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(magic_comment->key_length)); + pm_buffer_append_u32(buffer, pm_sizet_to_u32(magic_comment->key_length)); // serialize value location pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(magic_comment->value_start - parser->start)); - pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(magic_comment->value_length)); + pm_buffer_append_u32(buffer, pm_sizet_to_u32(magic_comment->value_length)); } static void