Skip to content

Commit

Permalink
Compile with WASI
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Oct 24, 2023
1 parent 3c4b3b5 commit bd4fdad
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/wasi-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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: 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: librubyparser.wasm
path: build/librubyparser.wasm
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -23,6 +24,7 @@ all: shared static

shared: build/librubyparser.$(SOEXT)
static: build/librubyparser.a
wasm: build/librubyparser.wasm

build/librubyparser.$(SOEXT): $(SHARED_OBJECTS)
$(ECHO) "linking $@"
Expand All @@ -32,6 +34,10 @@ build/librubyparser.a: $(STATIC_OBJECTS)
$(ECHO) "building $@"
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)

build/librubyparser.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 $(CPPFLAGS) $(CFLAGS) -o $@ $(SOURCES)

build/shared/%.o: src/%.c Makefile $(HEADERS)
$(ECHO) "compiling $@"
$(Q) mkdir -p $(@D)
Expand Down

0 comments on commit bd4fdad

Please sign in to comment.