Skip to content

Commit

Permalink
Initial support for WASI WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
tliron committed Aug 23, 2023
1 parent eab22da commit 241465c
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 23 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Overview
Each tool is a self-contained executable file, allowing them to be easily distributed with and
embedded in toolchains, orchestration, and development environments. They are coded in 100%
[Go](https://golang.org/) and are very portable, even available for
[WebAssembly](https://webassembly.org/) (which is how the in-browser demo linked above works).
[WebAssembly](https://webassembly.org/), which is how the in-browser demo linked above works.

You can also embed Puccini into your program as a library. Puccini is immediately usable from Go,
but can be used in many other programming languages via self-contained shared C libraries. See
Expand All @@ -76,15 +76,16 @@ Additionally, Puccini can parse the following TOSCA-like dialects:
* [OpenStack Heat Orchestration Template language (HOT) 2021-04-16](https://docs.openstack.org/heat/wallaby/template_guide/hot_guide.html)

TOSCA is a complex object-oriented language. We put considerable effort into adhering to every
aspect of the grammar, especially in regards to value type checking and type inheritance contracts,
aspect of the grammar, especially in regards to data type checking and type inheritance contracts,
which are key to delivering the object-oriented promise of extensibility while maintaining reliable
base type compatibility. Unfortunately, the TOSCA specification can be inconsistent and imprecise.
For this reason, Puccini also supports [quirk modes](tosca/parsing/QUIRKS.md) that enable alternative
behaviors based on differing interpretations of the spec.
base-type compatibility. Unfortunately, in earlier versions of TOSCA some grammatical features and
even some syntax have been specified in ways that are open to interpretation. Puccini picks one
interpretation by default, but also supports [quirk modes](tosca/parsing/QUIRKS.md) that enable
alternative behaviors.

### Packaging

The TOSCA source can be accessed by URL, on the local file systems or via HTTP/HTTPS, as
The TOSCA source can be accessed by URL, either on the local file systems or via HTTP/HTTPS, as
individual files as well as packaged in
[CSAR files](https://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.3/TOSCA-Simple-Profile-YAML-v1.3.html#_Toc302251718).

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/tliron/commonjs-goja v0.1.0
github.com/tliron/commonlog v0.1.1
github.com/tliron/exturl v0.2.7
github.com/tliron/exturl v0.2.9
github.com/tliron/go-ard v0.1.3
github.com/tliron/kutil v0.2.11
github.com/tliron/yamlkeys v1.3.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ github.com/tliron/commonjs-goja v0.1.0 h1:BF1NitaiHl2RLxqjp9lGNXx2eiJtTKKk3UFpSE
github.com/tliron/commonjs-goja v0.1.0/go.mod h1:mgGnXjwqvLSzMqsfLpwFGKS5qz40b66rE97IWHLQUSA=
github.com/tliron/commonlog v0.1.1 h1:bCkNKk+O5ciKBFxnjcMGLR79TGCq8hMSh5DfaeRJQHk=
github.com/tliron/commonlog v0.1.1/go.mod h1:qswie0h44wu9XrQ8sGOtmOjVVgI5qbU4Dl4wbi1b/w0=
github.com/tliron/exturl v0.2.7 h1:N0vqejQtxDIrQMxwATcg5rrZO5fAhcQGqeEze9KHC/E=
github.com/tliron/exturl v0.2.7/go.mod h1:2KiA4H2ok1smoLbTCVhy4WZxy+xXJ0uOSZtdsvbGy5A=
github.com/tliron/exturl v0.2.9 h1:7utvDHC9d1tqC/eHmiZvzklCn/ZRH7+/5QvjAU5+4Vc=
github.com/tliron/exturl v0.2.9/go.mod h1:FoKROnSga8WXPeDHQTFPTaQPAyeJTR3PVGhycvM2hhg=
github.com/tliron/go-ard v0.1.3 h1:E7M2Bpyb51wplLJGf5A4NqaOGoQqf2HuMwlmOGSi+Ig=
github.com/tliron/go-ard v0.1.3/go.mod h1:zhlpib5+3HdpBEfTyU+KZ6XskBf2az8up4ZgJyT9hVw=
github.com/tliron/kutil v0.2.11 h1:DtYxIcABJK1sdDn6F5Fbth6LezbnWuVQQYu5z+rAU7E=
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-wasm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e
HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
. "$HERE/_env"

GOOS=${GOOS:-js} # try wasip1

git_version

mkdir --parents "$ROOT/dist"
Expand All @@ -12,7 +14,7 @@ function build () {
local TOOL=$1
local WASM=$ROOT/dist/$TOOL.wasm
pushd "$ROOT/$TOOL" > /dev/null
GOOS=js GOARCH=wasm go build \
GOOS="$GOOS" GOARCH=wasm go build \
-o "$WASM" \
-ldflags " \
-X 'github.com/tliron/kutil/version.GitVersion=$VERSION' \
Expand Down
22 changes: 14 additions & 8 deletions scripts/test-all
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@ m 'build-csars...'

export NOBUILD=true

m 'test-parse...'
"$HERE/test-parse"

m 'test-formats...'
"$HERE/test-formats"
m 'test-js...'
"$HERE/test-js"
m 'test-https...'
"$HERE/test-https"

m 'test-csar...'
"$HERE/test-csar"
m 'test-csar-http...'
"$HERE/test-csar-http"

m 'test-https-url...'
"$HERE/test-https-url"
m 'test-git-url...'
"$HERE/test-git-url"
m 'test-csar-http-url...'
"$HERE/test-csar-http-url"
m 'test-archive-url...'
"$HERE/test-archive-url"
m 'test-archive-url-http...'
"$HERE/test-archive-url-http"
m 'test-git...'
"$HERE/test-git"

m 'test-wasm...'
"$HERE/test-wasm"
m 'test-wasip1...'
"$HERE/test-wasip1"
m 'test-java...'
"$HERE/test-java"
m 'test-python...'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/test-git → scripts/test-git-url
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
"$HERE/build"

puccini-tosca compile \
'git:https://github.com/tliron/puccini.git#main!examples/openstack/hello-world.yaml' "$@"
'git:https://github.com/tliron/puccini.git#main!examples/tosca/data-types.yaml' "$@"
2 changes: 1 addition & 1 deletion scripts/test-https → scripts/test-https-url
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
"$HERE/build"

puccini-tosca compile \
https://raw.githubusercontent.com/apache/incubator-ariatosca/master/examples/hello-world/hello-world.yaml "$@"
https://raw.githubusercontent.com/tliron/puccini/main/examples/tosca/data-types.yaml "$@"
2 changes: 1 addition & 1 deletion scripts/test-js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")

"$HERE/build"

puccini-tosca compile "$ROOT/examples/openstack/hello-world.yaml" "$@" | \
puccini-tosca compile "$ROOT/examples/tosca/requirements-and-capabilities.yaml" "$@" | \
puccini-clout scriptlet exec tosca.resolve
2 changes: 1 addition & 1 deletion scripts/test-parse
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")

"$HERE/build"

puccini-tosca parse "$ROOT/examples/openstack/hello-world.yaml" "$@"
puccini-tosca parse "$ROOT/examples/tosca/data-types.yaml" "$@"
28 changes: 28 additions & 0 deletions scripts/test-wasi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -e

HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
. "$HERE/_env"

GOOS=wasip1 "$HERE/build-wasm"

RUNTIME=${RUNTIME:-wasmtime} # TODO: broken with wasmer

if ! command -v "$RUNTIME" > /dev/null 2>&1; then
m "$RUNTIME must be installed" "$RED"
exit 1
fi

function run () {
local TOOL=$1
"$RUNTIME" run --dir=/ "$ROOT/dist/$TOOL.wasm" "${@:2}"
}

run puccini-tosca compile \
"$ROOT/examples/tosca/data-types.yaml" "$@"

run puccini-tosca compile \
"$ROOT/dist/cloud.csar" "$@"

#run puccini-tosca compile \
#https://raw.githubusercontent.com/tliron/puccini/main/examples/tosca/data-types.yaml "$@"
6 changes: 5 additions & 1 deletion scripts/test-wasm
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ function run () {
env --ignore-environment "$WASM_EXEC" "$ROOT/dist/$TOOL.wasm" "${@:2}"
}

run puccini-tosca compile "$ROOT/examples/openstack/hello-world.yaml" "$@"
run puccini-tosca compile \
"$ROOT/examples/tosca/data-types.yaml" "$@"

run puccini-tosca compile \
"$ROOT/dist/cloud.csar" "$@"

0 comments on commit 241465c

Please sign in to comment.