Skip to content

Commit

Permalink
waPC support (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkedy committed Oct 4, 2022
1 parent 5a93589 commit 7d1bfdc
Show file tree
Hide file tree
Showing 12 changed files with 3,017 additions and 296 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,50 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: '1.19'

- uses: acifani/setup-tinygo@v1
with:
tinygo-version: 0.25.0

- uses: actions/setup-go@v3
with:
go-version: '1.19'

- name: Install wasm-opt
run: |
wget https://github.com/WebAssembly/binaryen/releases/download/version_110/binaryen-version_110-x86_64-linux.tar.gz
tar -xvzf binaryen-version_110-x86_64-linux.tar.gz
rm -rf binaryen-version_110-x86_64-linux.tar.gz
cp binaryen-version_110/bin/wasm-opt /usr/local/bin
rm -Rf binaryen-version_110
- name: Install tinyjson
run: go install github.com/CosmWasm/tinyjson/...@latest

- name: Install Apex CLI
run: wget -q https://apexlang.io/install.sh -O - | /bin/bash
run: |
wget -q https://apexlang.io/install.sh -O - | /bin/bash
apex install @wapc/codegen
- name: Apex code generation
run: apex generate

- name: Build WebAssembly parser
run: |
tinygo build -o apex-parser.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/apex-api/main.go
wasm-opt -O apex-parser.wasm -o apex-parser.wasm
- name: Build waPC module
run: |
tinygo build -o apex-wapc.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/wapc/main.go
wasm-opt -O apex-wapc.wasm -o apex-wapc.wasm
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
apex-parser.wasm
apex-wapc.wasm
model.apexlang
LICENSE.txt
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all wasm-cli wasm-api codegen
.PHONY: all wasm-cli wasm-api wasm-wapc wasm-host codegen

all: codegen wasm-cli wasm-api wasm-host
all: codegen wasm-cli wasm-api wasm-wapc wasm-host

wasm-cli:
tinygo build -o apex-cli.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/apex-cli/main.go
Expand All @@ -11,6 +11,10 @@ wasm-api:
wasm-opt -O apex-api.wasm -o apex-api.wasm
cp apex-api.wasm cmd/host/apex-api.wasm

wasm-wapc:
tinygo build -o apex-wapc.wasm -scheduler=none -target=wasi -wasm-abi=generic -no-debug cmd/wapc/main.go
wasm-opt -O apex-wapc.wasm -o apex-wapc.wasm

wasm-host:
go build -o apex-host cmd/host/main.go

Expand Down
14 changes: 13 additions & 1 deletion apex.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spec: model.apexlang
config:
package: model
module: github.com/apexlang/apex-wasm
module: github.com/apexlang/apex-go
generates:
model/model.go:
module: '@apexlang/codegen/go'
Expand All @@ -10,3 +10,15 @@ generates:
writeTypeInfo: false
runAfter:
- command: tinyjson -all model/model.go
model/msgpack.go:
module: '@apexlang/codegen/go'
visitorClass: MsgPackVisitor
model/wapc.go:
module: '@wapc/codegen/tinygo'
visitorClass: ExportVisitor
cmd/wapc/main.go:
module: '@wapc/codegen/tinygo'
visitorClass: MainVisitor
config:
import: github.com/apexlang/apex-go/model
package: model
16 changes: 16 additions & 0 deletions cmd/wapc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"github.com/apexlang/apex-go/model"
)

func main() {
// Create providers
resolverProvider := model.NewResolver()

// Create services
parserService := model.NewParser(resolverProvider)

// Register services
model.RegisterParser(parserService)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require (
github.com/CosmWasm/tinyjson v0.9.0
github.com/iancoleman/strcase v0.2.0
github.com/tetratelabs/tinymem v0.1.0
github.com/wapc/tinygo-msgpack v0.1.4
github.com/wapc/wapc-guest-tinygo v0.3.3
)

require github.com/josharian/intern v1.0.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107 h1:GljFiJysL3S8SBhXWU47Emj34D3pVZgJ+Amj+jhM4fQ=
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107/go.mod h1:5+7QnSKrkIWnpIdhUT2t2EYzXnII3/3MlM0oDsBSbc8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/tetratelabs/tinymem v0.1.0 h1:Qza1JAg9lquPPJ/CIei5qQYx7t18KLie83O2WR6CM58=
github.com/tetratelabs/tinymem v0.1.0/go.mod h1:WFFTZFhLod6lTL+UetFAopVbGaB+KFsVcIY+RUv7NeY=
github.com/wapc/tinygo-msgpack v0.1.4 h1:oiwtclAGh/A+x024gCFXxey/iNtRmGaE+nvtyAw2vvo=
github.com/wapc/tinygo-msgpack v0.1.4/go.mod h1:2P4rQimy/6oQAkytwC2LdtVjLJ2D1dYkQHejfCtZXZQ=
github.com/wapc/wapc-guest-tinygo v0.3.3 h1:jLebiwjVSHLGnS+BRabQ6+XOV7oihVWAc05Hf1SbeR0=
github.com/wapc/wapc-guest-tinygo v0.3.3/go.mod h1:mzM3CnsdSYktfPkaBdZ8v88ZlfUDEy5Jh5XBOV3fYcw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
24 changes: 24 additions & 0 deletions model.apexlang
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
namespace "apexlang.v1"

interface Parser @service @uses([Resolver]) {
parse(source: string): ParserResult
}

interface Resolver @dependency {
resolve(location: string, from: string): string
}

type ParserResult {
namespace: Namespace?
errors: [Error]?
}

type Error {
message: string
positions: [u32]
locations: [Location]
}

type Location {
line: u32
column: u32
}

"Namespace encapsulates is used to identify and refer to elements contained in the Apex specification."
type Namespace {
name: string @quoted
Expand Down
28 changes: 28 additions & 0 deletions model/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d1bfdc

Please sign in to comment.