Skip to content

Commit 9b628c1

Browse files
committed
Build ggsql playground into quarto documentation
1 parent fe5052e commit 9b628c1

6 files changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11+
build-wasm:
12+
uses: ./.github/workflows/wasm.yaml
13+
1114
publish-website:
15+
needs: build-wasm
1216
runs-on: ubuntu-latest
1317
permissions:
1418
contents: write
@@ -22,6 +26,12 @@ jobs:
2226
sudo docker image prune --all --force
2327
sudo docker builder prune -a
2428
29+
- name: Download WASM demo artifact
30+
uses: actions/download-artifact@v4
31+
with:
32+
name: wasm-demo
33+
path: doc/playground
34+
2535
- name: Setup Node.js
2636
uses: actions/setup-node@v4
2737
with:

.github/workflows/wasm.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
pull_request:
77
branches: [main]
88
workflow_dispatch:
9+
workflow_call:
910

1011
jobs:
1112
build:
@@ -47,10 +48,24 @@ jobs:
4748
- name: Install wasm-pack
4849
run: cargo install wasm-pack
4950

51+
- name: Build WASM library
52+
working-directory: ggsql-wasm/library
53+
run: npm install && npm run build
54+
5055
- name: Build WASM package
5156
working-directory: ggsql-wasm
5257
run: wasm-pack build --target web --profile wasm --no-opt
5358

5459
- name: Optimise WASM binary
5560
working-directory: ggsql-wasm
5661
run: wasm-opt pkg/ggsql_wasm_bg.wasm -o pkg/ggsql_wasm_bg.wasm -Oz --all-features
62+
63+
- name: Build WASM demo
64+
working-directory: ggsql-wasm/demo
65+
run: npm install && npm run build
66+
67+
- name: Upload demo artifact
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: wasm-demo
71+
path: ggsql-wasm/demo/dist/

doc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.quarto/
22
**/*.quarto_ipynb
33
_site
4+
playground

doc/_quarto.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
project:
22
type: website
3+
resources:
4+
- playground/**
35

46
website:
57
title: "ggsql"
@@ -48,6 +50,8 @@ website:
4850
- text: "`LABEL`"
4951
href: syntax/clause/label.qmd
5052
- examples.qmd
53+
- text: Playground
54+
href: playground/index.html
5155
tools:
5256
- icon: github
5357
menu:

doc/index.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ A declarative visualization language that extends SQL with powerful data visuali
1616
::: {.hero-buttons}
1717
[Get Started](installation.qmd){.btn .btn-secondary .btn-lg}
1818
[View Examples](examples.qmd){.btn .btn-outline-secondary .btn-lg}
19+
[Playground](playground/index.html){.btn .btn-outline-secondary .btn-lg}
1920
:::
2021

2122
:::

ggsql-wasm/build-wasm.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
6+
7+
SKIP_BINARY=false
8+
for arg in "$@"; do
9+
case "$arg" in
10+
--skip-binary) SKIP_BINARY=true ;;
11+
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
12+
esac
13+
done
14+
15+
check_wasm32_support() {
16+
local cc="${CC:-clang}"
17+
if ! echo "int main(){return 0;}" | \
18+
"$cc" -target wasm32-unknown-unknown -c -o /dev/null -x c - 2>/dev/null; then
19+
echo "Error: '$cc' does not support the wasm32-unknown-unknown target." >&2
20+
echo "Install an LLVM/clang toolchain with wasm backend support (e.g. 'sudo apt-get install llvm' on Debian/Ubuntu)." >&2
21+
exit 1
22+
fi
23+
}
24+
25+
echo "Building WASM library..."
26+
(cd "$SCRIPT_DIR/library" && npm install && npm run build)
27+
28+
if [ "$SKIP_BINARY" = false ]; then
29+
echo "Checking wasm32 compiler support..."
30+
check_wasm32_support
31+
32+
echo "Building WASM binary..."
33+
(cd "$SCRIPT_DIR" && wasm-pack build --target web --profile wasm --no-opt)
34+
35+
echo "Optimising WASM binary..."
36+
(cd "$SCRIPT_DIR" && wasm-opt pkg/ggsql_wasm_bg.wasm -o pkg/ggsql_wasm_bg.wasm -Oz --all-features)
37+
else
38+
echo "Skipping WASM binary build (--skip-binary)."
39+
fi
40+
41+
echo "Building WASM demo..."
42+
(cd "$SCRIPT_DIR/demo" && npm install && npm run build)
43+
44+
echo "Copying demo to doc/playground..."
45+
rm -rf "$REPO_ROOT/doc/playground"
46+
cp -r "$SCRIPT_DIR/demo/dist" "$REPO_ROOT/doc/playground"
47+
48+
echo "Done! Demo output is in: $REPO_ROOT/doc/playground"

0 commit comments

Comments
 (0)