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 12, 2024
1 parent ad7fd2a commit 9796dfc
Show file tree
Hide file tree
Showing 48 changed files with 7,183 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ jobs:
uses: cashapp/[email protected]
- name: Test Scripts
run: just test-scripts
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 internal/sqlc-gen-ftl && cargo test --features ci --test sqlc_gen_ftl_test -- --nocapture
sql:
name: SQL
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ charts/**/output/
__pycache__/
*.pyc
*.pyo
.venv/
.venv/

# Rust
!internal/sqlc-gen-ftl/dist/
24 changes: 22 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 := "internal/sqlc-gen-ftl/dist"
PROTOS_IN := "backend/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 internal/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}} -- "just build-sqlc && ftl dev --plain {{args}}"

# Build everything
build-all: build-protos-unconditionally build-backend build-frontend build-backend-tests build-generate build-sqlc 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-sqlc 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 @@ -176,6 +178,14 @@ 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
@mk {{SQLC_GEN_FTL_OUT}} : internal/sqlc-gen-ftl/src -- \
"cd internal/sqlc-gen-ftl && \
rustup target add wasm32-wasip1 && \
cargo build --target wasm32-wasip1 --release && \
cp target/wasm32-wasip1/release/sqlc-gen-ftl.wasm ../../{{SQLC_GEN_FTL_OUT}}"

# Install development version of VSCode extension
install-extension: build-extension
@cd frontend/vscode && vsce package && code --install-extension ftl-*.vsix
Expand All @@ -200,6 +210,16 @@ 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 internal/sqlc-gen-ftl/target : internal/sqlc-gen-ftl/Cargo.toml -- \
"cd internal/sqlc-gen-ftl && \
cargo install protoc-gen-prost && \
cargo build"

update-sqlc-plugin-codegen-proto:
curl -L --fail --show-error --silent "https://raw.githubusercontent.com/sqlc-dev/sqlc/main/protos/plugin/codegen.proto" -o "internal/sqlc-gen-ftl/proto/codegen.proto"

# Regenerate protos
build-protos:
@mk {{SCHEMA_OUT}} : internal/schema -- "@just go2proto"
Expand All @@ -213,7 +233,7 @@ go2proto:
xyz.block.ftl.schema.v1 {{GO_SCHEMA_ROOTS}} && buf format -w && buf lint && bin/gofmt -w internal/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 backend/protos && buf generate

# Run integration test(s)
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: ../../internal/sqlc-gen-ftl/src/protos
opt:
- bytes=.
1 change: 1 addition & 0 deletions bin/.rust-1.83.0.pkg
1 change: 1 addition & 0 deletions bin/.rust-src-1.83.0.pkg
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/rust-src
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
Loading

0 comments on commit 9796dfc

Please sign in to comment.