Skip to content

Commit

Permalink
feat: add sqlc-gen-ftl WASM plugin (#3607)
Browse files Browse the repository at this point in the history
next step will be hooking this up in the release

design: https://hackmd.io/09Z3vZJ0SxyIdCiQTSbVkg?view

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
worstell and github-actions[bot] authored Dec 13, 2024
1 parent 0ef8d89 commit 3ee16bc
Show file tree
Hide file tree
Showing 47 changed files with 7,219 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/frontend/console/src/protos/**/* linguist-generated=true
go.sum linguist-generated=true
go.work.sum linguist-generated=true
/python-runtime/ftl/src/ftl/protos/**/* linguist-generated=true
/python-runtime/ftl/src/ftl/protos/**/* linguist-generated=true
/sqlc-gen-ftl/src/protos/**/* linguist-generated=true
/sqlc-gen-ftl/src/protos/mod.rs linguist-generated=false
/sqlc-gen-ftl/src/protos/plugin.rs linguist-generated=false
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ jobs:
run: just build-frontend
- name: Console Test
run: just test-frontend
test-wasm:
name: Test sqlc-gen-ftl
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/[email protected]
- name: Build Cache
uses: ./.github/actions/build-cache
- name: Test WASM
run: cd sqlc-gen-ftl && cargo test --features ci --test sqlc_gen_ftl_test -- --nocapture
extension:
name: VSCode Extension
runs-on: ubuntu-latest
Expand Down
21 changes: 19 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ZIP_DIRS := "go-runtime/compile/build-template " + \
CONSOLE_ROOT := "frontend/console"
FRONTEND_OUT := CONSOLE_ROOT + "/dist/index.html"
EXTENSION_OUT := "frontend/vscode/dist/extension.js"
SQLC_GEN_FTL_OUT := "sqlc-gen-ftl/target/wasm32-wasip1/release/sqlc-gen-ftl.wasm"
PROTOS_IN := "common/protos"
PROTOS_OUT := "backend/protos/xyz/block/ftl/console/v1/console.pb.go " + \
"backend/protos/xyz/block/ftl//v1/ftl.pb.go " + \
Expand Down Expand Up @@ -73,6 +74,7 @@ clean:
rm -rf python-runtime/ftl/.venv
find . -name '*.zip' -exec rm {} \;
mvn -f jvm-runtime/ftl-runtime clean
cd sqlc-gen-ftl && cargo clean

# Live rebuild the ftl binary whenever source changes.
live-rebuild:
Expand All @@ -83,7 +85,7 @@ dev *args:
watchexec -r {{WATCHEXEC_ARGS}} -- "ftl dev --plain {{args}}"

# Build everything
build-all: build-protos-unconditionally build-backend build-frontend build-backend-tests build-generate build-zips lsp-generate build-jvm build-language-plugins build-go2proto-testdata
build-all: build-protos-unconditionally build-backend build-frontend build-backend-tests build-generate build-zips lsp-generate build-jvm build-language-plugins build-go2proto-testdata build-sqlc-gen-ftl

# Run "go generate" on all packages
build-generate:
Expand Down Expand Up @@ -162,6 +164,18 @@ build-frontend: pnpm-install
build-extension: pnpm-install
@mk {{EXTENSION_OUT}} : frontend/vscode/src frontend/vscode/package.json -- "cd frontend/vscode && rm -f ftl-*.vsix && pnpm run compile"

# Build the sqlc-ftl-gen plugin, used to generate FTL schema from SQL
build-sqlc-gen-ftl: build-protos
@mk {{SQLC_GEN_FTL_OUT}} : sqlc-gen-ftl/src -- \
"cd sqlc-gen-ftl && \
cargo build --target wasm32-wasip1 --release"

cargo-install:
@mk sqlc-gen-ftl/target : sqlc-gen-ftl/Cargo.toml -- \
"cd sqlc-gen-ftl && \
cargo install protoc-gen-prost && \
cargo build"

# Install development version of VSCode extension
install-extension: build-extension
@cd frontend/vscode && vsce package && code --install-extension ftl-*.vsix
Expand All @@ -186,6 +200,10 @@ format-frontend:
pnpm-install:
@for i in {1..3}; do mk frontend/**/node_modules : frontend/**/package.json -- "pnpm install --frozen-lockfile" && break || sleep 5; done

# Copy plugin protos from the SQLC release
update-sqlc-plugin-codegen-proto:
@bash scripts/sqlc-codegen-proto

# Regenerate protos
build-protos: go2proto
@mk {{PROTOS_OUT}} : {{PROTOS_IN}} -- "@just build-protos-unconditionally"
Expand All @@ -200,7 +218,6 @@ go2proto:
# Unconditionally rebuild protos
build-protos-unconditionally: go2proto lint-protos pnpm-install
cd common/protos && buf generate
cd backend/protos && buf generate

# Run integration test(s)
integration-tests *test:
Expand Down
4 changes: 4 additions & 0 deletions backend/protos/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ plugins:
out: ../../python-runtime/ftl/src/ftl/protos
opt:
- pyi_out=../../python-runtime/ftl/src/ftl/protos
- plugin: prost
out: ../../sqlc-gen-ftl/src/protos
opt:
- bytes=.
1 change: 1 addition & 0 deletions bin/.rustup-1.25.2.pkg
1 change: 1 addition & 0 deletions bin/cargo
1 change: 1 addition & 0 deletions bin/cargo-clippy
1 change: 1 addition & 0 deletions bin/cargo-fmt
1 change: 1 addition & 0 deletions bin/cargo-miri
1 change: 1 addition & 0 deletions bin/clippy-driver
1 change: 1 addition & 0 deletions bin/rls
1 change: 1 addition & 0 deletions bin/rust-analyzer
1 change: 1 addition & 0 deletions bin/rust-gdb
1 change: 1 addition & 0 deletions bin/rust-gdbgui
1 change: 1 addition & 0 deletions bin/rust-lldb
1 change: 1 addition & 0 deletions bin/rustc
1 change: 1 addition & 0 deletions bin/rustdoc
1 change: 1 addition & 0 deletions bin/rustfmt
1 change: 1 addition & 0 deletions bin/rustup
2 changes: 2 additions & 0 deletions scripts/autofmt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ find backend/protos \( -name '*.pb.go' -o -name '*.connect.go' \) -print0 | xarg

just pnpm-install

just cargo-install

(cd backend/protos && buf generate)

echo "Formatting TypeScript..."
Expand Down
13 changes: 13 additions & 0 deletions scripts/protoc-gen-prost
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

if [ ! "${HERMIT_ENV:-}" ]; then
# shellcheck disable=SC1091
. "$(dirname "$(dirname "$0")")/bin/activate-hermit"
fi

# Ensure the binary exists, install if it doesn't
mk "${HERMIT_ENV}/.hermit/rust/bin/protoc-gen-prost" : -- cargo install protoc-gen-prost

# Execute the binary with any passed arguments
exec "${HERMIT_ENV}/.hermit/rust/bin/protoc-gen-prost" "$@"
36 changes: 36 additions & 0 deletions scripts/sqlc-codegen-proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -euo pipefail

# Get sqlc version from hermit
if [ ! "${HERMIT_ENV:-}" ]; then
# shellcheck disable=SC1091
. "$(dirname "$(dirname "$0")")/bin/activate-hermit"
fi

SQLC_VERSION=$(hermit info sqlc | grep "Version:" | cut -d' ' -f2)
if [[ -z "$SQLC_VERSION" ]]; then
echo "Error: Could not determine sqlc version from hermit"
exit 1
fi

# Create temp directory
TEMP_DIR=$(mktemp -d)
trap 'rm -rf $TEMP_DIR' EXIT

# Download and extract the release source
echo "Fetching sqlc version ${SQLC_VERSION}..."
curl -L --fail --silent \
"https://github.com/sqlc-dev/sqlc/archive/refs/tags/v${SQLC_VERSION}.tar.gz" \
-o "${TEMP_DIR}/sqlc.tar.gz"

tar xzf "${TEMP_DIR}/sqlc.tar.gz" -C "${TEMP_DIR}"

# Copy the proto file
PROTO_PATH="${TEMP_DIR}/sqlc-${SQLC_VERSION}/protos/plugin/codegen.proto"
if [[ ! -f "$PROTO_PATH" ]]; then
echo "Error: Proto file not found in release archive"
exit 1
fi

cp "$PROTO_PATH" "sqlc-gen-ftl/proto/codegen.proto"
echo "Updated proto file to version ${SQLC_VERSION}"
Loading

0 comments on commit 3ee16bc

Please sign in to comment.