Skip to content

Commit

Permalink
build/ci: add dependency downloading to Makefile, add ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi committed Sep 13, 2024
1 parent a0faf79 commit bfb2f17
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 30 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Release

on:
release:
types:
- created

jobs:
build-and-release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Extism
run: |
curl -O https://raw.githubusercontent.com/extism/js-pdk/main/install.sh
sh install.sh
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # Specify the Node.js version you need

- name: Build
run: |
npm i
npm run build
- name: Run bundle script
run: ./bundle.sh

- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./bundle.zip
asset_name: bundle.zip
asset_content_type: application/zip

63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Run Tests

on:
workflow_dispatch:
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Extism and XTP
run: |
curl -O https://raw.githubusercontent.com/extism/js-pdk/main/install.sh
sh install.sh
curl https://static.dylibso.com/cli/install.sh | sh
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '21'

- name: Install
run: |
npm ci
- name: Build
run: |
npm run build
- name: Run test script
run: |
cd tests && ./test.sh
- name: Run Bindgen Test
run: |
# we already have a folder named bundle
# move it before we get the simulation bundle
# TODO change the name
mv bundle template-bundle
# get the latest release
RELEASE_INFO=$(curl -s "https://api.github.com/repos/dylibso/xtp-bindgen-test/releases/latest")
ASSET_URL=$(echo $RELEASE_INFO | grep -oP '"browser_download_url": "\K(.*bundle.zip)(?=")')
if [ -z "$ASSET_URL" ]; then
echo "Asset URL not found. Please check the asset name or the repository."
exit 1
fi
# download and unzip the bundle
curl -L -o bundle.zip "$ASSET_URL"
unzip bundle.zip
cd bundle/
# Using ../template-bundle so we test the head template
xtp plugin init --schema-file schema.yaml --template ../template-bundle --path exampleplugin --name exampleplugin --feature stub-with-code-samples
xtp plugin build --path exampleplugin
xtp plugin test exampleplugin/dist/plugin.wasm --with test.wasm --mock-host mock.wasm
Empty file modified bindgen-test.sh
100644 → 100755
Empty file.
2 changes: 0 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
template-suffix: ejs
dependencies:
- tinygo

available-feature-flags:
- name: stub-with-code-samples
Expand Down
61 changes: 39 additions & 22 deletions template/Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
WASI_SDK_PATH?=../../wasi-sdk
ifeq ($(origin WASI_SDK_PATH),undefined)
WASI_SDK_PATH=./wasi-sdk
ifeq ("$(wildcard ./wasi-sdk)","")
$(shell chmod +x ./install-wasi-sdk.sh)
$(shell ./install-wasi-sdk.sh)
endif
endif

.PHONY: build
build: dist/plugin.wasm

.PHONY: run
run: dist/plugin.wasm
extism call ./dist/plugin.wasm referenceTypes --log-level debug --wasi --input "\"apple\""
.PHONY: format
format:
$(WASI_SDK_PATH)/bin/clang-format -i *.cpp *.hpp

.PHONY: clean
clean:
rm -f *.wasm *.o

.PHONY: veryclean
veryclean: clean
rm -rf include ./wasi-sdk

.PHONY: run-bad-input
run-bad-input: dist/plugin.wasm
extism call ./dist/plugin.wasm referenceTypes --log-level debug --wasi --input "\"steak\""

.PHONY: run-top
run-top: dist/plugin.wasm
extism call ./dist/plugin.wasm topLevelPrimitives --log-level debug --wasi --input "\"hello\""
include/extism-pdk.hpp:
mkdir -p include
cd include && \
wget -q https://raw.githubusercontent.com/extism/cpp-pdk/695c794d2f3a42dff8c6f37e1902ad0dee9ff29a/extism-pdk.hpp

.PHONY: run-void
run-void: dist/plugin.wasm
extism call ./dist/plugin.wasm voidFunc --log-level debug --wasi
include/magic_enum/include/magic_enum:
mkdir -p include/magic_enum
cd include/magic_enum && \
wget -q https://github.com/Neargye/magic_enum/releases/download/v0.9.6/magic_enum-v0.9.6.tar.gz && \
tar xf magic_enum-v0.9.6.tar.gz

pdk.gen.o: pdk.gen.cpp pdk.gen.hpp extism-pdk.hpp
$(WASI_SDK_PATH)/bin/clang++ -I. -Imagic_enum -std=c++23 -fno-exceptions -O2 -g -c pdk.gen.cpp
include/jsoncons/include:
mkdir -p include
cd include && \
wget -q https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.177.0.zip && \
unzip -qq v0.177.0.zip && \
mv jsoncons-0.177.0 jsoncons

impl.o: impl.cpp pdk.gen.hpp
$(WASI_SDK_PATH)/bin/clang++ -I. -std=c++23 -fno-exceptions -O2 -g -c impl.cpp
pdk.gen.o: pdk.gen.cpp pdk.gen.hpp include/extism-pdk.hpp include/magic_enum/include/magic_enum include/jsoncons/include
$(WASI_SDK_PATH)/bin/clang++ -Iinclude -Iinclude/jsoncons/include -Iinclude/magic_enum/include/magic_enum -std=c++23 -fno-exceptions -O2 -g -c pdk.gen.cpp

impl.o: impl.cpp pdk.gen.hpp include/extism-pdk.hpp include/magic_enum/include/magic_enum include/jsoncons/include
$(WASI_SDK_PATH)/bin/clang++ -Iinclude -Iinclude/jsoncons/include -Iinclude/magic_enum/include/magic_enum -std=c++23 -fno-exceptions -O2 -g -c impl.cpp

dist/plugin.wasm: pdk.gen.o impl.o
mkdir -p dist
$(WASI_SDK_PATH)/bin/clang++ -I. -std=c++23 -fno-exceptions -O2 -g -o $@ $^ -mexec-model=reactor

.PHONY: clean
clean:
rm -f *.wasm *.o
$(WASI_SDK_PATH)/bin/clang++ -std=c++23 -fno-exceptions -O2 -g -o $@ $^ -mexec-model=reactor
19 changes: 19 additions & 0 deletions template/install-wasi-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Orignal from: https://github.com/Shopify/javy

set -euo pipefail

PATH_TO_SDK="./wasi-sdk"
if [[ ! -d $PATH_TO_SDK ]]; then
TMPGZ=$(mktemp)
VERSION_MAJOR="24"
VERSION_MINOR="0"
ARCH=$(uname -m)
if [[ "$(uname -s)" == "Darwin" ]]; then
curl --fail --location --silent https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${VERSION_MAJOR}/wasi-sdk-${VERSION_MAJOR}.${VERSION_MINOR}-${ARCH}-macos.tar.gz --output $TMPGZ
else
curl --fail --location --silent https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${VERSION_MAJOR}/wasi-sdk-${VERSION_MAJOR}.${VERSION_MINOR}-${ARCH}-linux.tar.gz --output $TMPGZ
fi
mkdir $PATH_TO_SDK
tar xf $TMPGZ -C $PATH_TO_SDK --strip-components=1
fi
4 changes: 2 additions & 2 deletions template/pdk.gen.cpp.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// THIS FILE WAS GENERATED BY `xtp-cpp-bindgen`. DO NOT EDIT.
#define EXTISM_CPP_IMPLEMENTATION
#include "extism-pdk.hpp"
#include "jsoncons/json.hpp"
#include <extism-pdk.hpp>
#include <jsoncons/json.hpp>
#include "pdk.gen.hpp"
#include <magic_enum.hpp>

Expand Down
3 changes: 1 addition & 2 deletions template/pdk.gen.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <cstddef>
#include <expected>
<% if (hasUntypedObject(objects)) { -%>
#include "extism-pdk.hpp"
#include "jsoncons/json.hpp"
#include <jsoncons/json.hpp>
<% } -%>
#include <memory>
#include <span>
Expand Down
4 changes: 2 additions & 2 deletions template/xtp.toml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "<%- project.name %>"
build = "make"

# xtp plugin init runs this script to format the code
format = "$WASI_SDK_PATH/bin/clang-format -i *.cpp *.hpp"
format = "make format"

# xtp plugin init runs this script before running the format script
#prepare = "go get ./..."
#prepare = ""

0 comments on commit bfb2f17

Please sign in to comment.