Skip to content

Commit

Permalink
feat: add sqlc-gen-ftl WASM plugin
Browse files Browse the repository at this point in the history
next step will be hooking this up in the release
  • Loading branch information
worstell committed Dec 13, 2024
1 parent 7c87106 commit 15e2b47
Show file tree
Hide file tree
Showing 44 changed files with 7,170 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ 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: Install Rust Toolchain
run: just cargo-install
- 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
24 changes: 21 additions & 3 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,12 @@ 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 update-sqlc-plugin-codegen-proto cargo-install
@mk {{SQLC_GEN_FTL_OUT}} : sqlc-gen-ftl/src -- \
"cd sqlc-gen-ftl && \
cargo build --target wasm32-wasip1 --release"

# Install development version of VSCode extension
install-extension: build-extension
@cd frontend/vscode && vsce package && code --install-extension ftl-*.vsix
Expand All @@ -186,6 +194,17 @@ 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

# Install Rust dependencies based on Cargo.toml
cargo-install:
@mk sqlc-gen-ftl/target : sqlc-gen-ftl/Cargo.toml -- \
"cd sqlc-gen-ftl && \
cargo install protoc-gen-prost && \
cargo build"

# Copy plugin protos from the SQLC repo
update-sqlc-plugin-codegen-proto:
curl -L --fail --show-error --silent "https://raw.githubusercontent.com/sqlc-dev/sqlc/main/protos/plugin/codegen.proto" -o "sqlc-gen-ftl/proto/codegen.proto"

# Regenerate protos
build-protos: go2proto
@mk {{PROTOS_OUT}} : {{PROTOS_IN}} -- "@just build-protos-unconditionally"
Expand All @@ -198,9 +217,8 @@ go2proto:
xyz.block.ftl.schema.v1 {{GO_SCHEMA_ROOTS}} && buf format -w && buf lint && bin/gofmt -w common/schema/go2proto.to.go

# Unconditionally rebuild protos
build-protos-unconditionally: go2proto lint-protos pnpm-install
build-protos-unconditionally: go2proto lint-protos pnpm-install cargo-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
Loading

0 comments on commit 15e2b47

Please sign in to comment.