Skip to content

Commit

Permalink
Merge branch 'main' into feat/update-deps-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno authored Feb 13, 2024
2 parents a77b931 + 7e5bcbe commit c1d9358
Show file tree
Hide file tree
Showing 47 changed files with 1,104 additions and 695 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-prisma-schema-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24

- run: nix build .#prisma-schema-wasm
- run: nix flake check
- uses: ./.github/workflows/include/rust-wasm-setup

- run: make check-schema-wasm-package PROFILE=release
25 changes: 25 additions & 0 deletions .github/workflows/include/rust-wasm-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Rust + WASM common deps

runs:
using: "composite"
steps:
- name: Set default toolchain
shell: bash
run: rustup default stable

- name: Add WASM target
shell: bash
run: rustup target add wasm32-unknown-unknown

- uses: cargo-bins/cargo-binstall@main

- name: Install wasm-bindgen, wasm-opt
shell: bash
run: |
cargo binstall -y \
[email protected] \
[email protected]
- name: Install bc
shell: bash
run: sudo apt update && sudo apt-get install -y bc
3 changes: 0 additions & 3 deletions .github/workflows/on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ jobs:
git config user.email "[email protected]"
git config user.name "prisma-bot"
- name: Generate cargo docs for the workspace to gh-pages branch
run: nix run .#publish-cargo-docs

- name: Publish engines size to gh-pages branch
run: nix run .#publish-engine-size
13 changes: 6 additions & 7 deletions .github/workflows/publish-prisma-schema-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.enginesHash }}
- uses: cachix/install-nix-action@v24

- uses: ./.github/workflows/include/rust-wasm-setup

- name: Build
run: nix build .#prisma-schema-wasm
run: make build-schema-wasm PROFILE=release SCHEMA_WASM_VERSION=${{ github.event.inputs.enginesWrapperVersion }}

- uses: actions/setup-node@v4
with:
Expand All @@ -45,11 +46,9 @@ jobs:
- name: Set up NPM token for publishing later
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Update version in package.json & Publish @prisma/prisma-schema-wasm
run: |
# Update version in package.json and return directory for later usage
PACKAGE_DIR=$( nix run .#renderPrismaSchemaWasmPackage ${{ github.event.inputs.enginesWrapperVersion }})
npm publish "$PACKAGE_DIR" --access public --tag ${{ github.event.inputs.npmDistTag }}
- name: Publish @prisma/prisma-schema-wasm
run: npm publish --access public --tag ${{ github.event.inputs.npmDistTag }}
working-directory: target/prisma-schema-wasm
#
# Failure handlers
#
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/publish-query-engine-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ on:
inputs:
packageVersion:
required: true
description: 'New @prisma/query-engine-wasm package version'
description: "New @prisma/query-engine-wasm package version"
enginesHash:
required: true
description: 'prisma-engines commit to build'
description: "prisma-engines commit to build"
npmDistTag:
required: true
default: 'latest'
description: 'npm dist-tag (e.g. latest or integration)'
default: "latest"
description: "npm dist-tag (e.g. latest or integration)"

jobs:
build:
Expand All @@ -30,22 +30,24 @@ jobs:
with:
ref: ${{ github.event.inputs.enginesHash }}

- uses: cachix/install-nix-action@v24
- uses: ./.github/workflows/include/rust-wasm-setup

- name: Build @prisma/query-engine-wasm
run: nix run .#export-query-engine-wasm "${{ github.event.inputs.packageVersion }}" package
run: make build-qe-wasm
env:
QE_WASM_VERSION: ${{ github.event.inputs.packageVersion }}

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: "20.x"

- name: Set up NPM token for publishing
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Publish @prisma/query-engine-wasm
run: npm publish --access public --tag ${{ github.event.inputs.npmDistTag }}
working-directory: package
working-directory: query-engine/query-engine-wasm/pkg

#
# Failure handlers
Expand All @@ -57,7 +59,7 @@ jobs:
if: ${{ failure() }}
uses: rtCamp/[email protected]
env:
SLACK_TITLE: 'Building and publishing @prisma/query-engine-wasm failed :x:'
SLACK_COLOR: '#FF0000'
SLACK_TITLE: "Building and publishing @prisma/query-engine-wasm failed :x:"
SLACK_COLOR: "#FF0000"
SLACK_CHANNEL: feed-prisma-query-engine-wasm-publish-failures
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_WASM_FAILING }}
2 changes: 1 addition & 1 deletion .github/workflows/test-query-engine-driver-adapters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
echo "DRIVER_ADAPTERS_BRANCH=$branch" >> "$GITHUB_ENV"
fi
- uses: cachix/install-nix-action@v24
- uses: ./.github/workflows/include/rust-wasm-setup
- uses: taiki-e/install-action@nextest

- run: make ${{ matrix.adapter.setup_task }}
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/wasm-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: ./.github/workflows/include/rust-wasm-setup

- name: "Setup Node.js"
uses: actions/setup-node@v4
Expand All @@ -30,9 +34,6 @@ jobs:
with:
version: 8

- name: Install bc
run: sudo apt update && sudo apt-get install -y bc

- name: "Login to Docker Hub"
uses: docker/login-action@v3
continue-on-error: true
Expand All @@ -43,8 +44,14 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: cachix/install-nix-action@v24

- name: Extract Branch Name
run: |
branch="$(git show -s --format=%s | grep -o "DRIVER_ADAPTERS_BRANCH=[^ ]*" | cut -f2 -d=)"
if [ -n "$branch" ]; then
echo "Using $branch branch of driver adapters"
echo "DRIVER_ADAPTERS_BRANCH=$branch" >> "$GITHUB_ENV"
fi
- name: Setup benchmark
run: make setup-pg-bench
Expand Down Expand Up @@ -122,6 +129,9 @@ jobs:

- name: Create or update report
uses: peter-evans/create-or-update-comment@v3
# Only run on our repository
# It avoids an expected failure on forks
if: github.repository == 'prisma/prisma-engines'
with:
comment-id: ${{ steps.findReportComment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
Expand Down
35 changes: 11 additions & 24 deletions .github/workflows/wasm-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,13 @@ jobs:
- name: Checkout PR branch
uses: actions/checkout@v4

- uses: cachix/install-nix-action@v24
with:
# we need internet access for the moment
extra_nix_config: |
sandbox = false
- uses: ./.github/workflows/include/rust-wasm-setup

- name: Build and measure PR branch
id: measure
run: |
nix build -L .#query-engine-wasm-gz
for provider in "postgresql" "mysql" "sqlite"; do
echo "${provider}_size=$(wc --bytes < ./result/query-engine-$provider.wasm)" >> $GITHUB_OUTPUT
echo "${provider}_size_gz=$(wc --bytes < ./result/query-engine-$provider.wasm.gz)" >> $GITHUB_OUTPUT
done
export ENGINE_SIZE_OUTPUT=$GITHUB_OUTPUT
make measure-qe-wasm
base-wasm-size:
name: calculate module sizes (base branch)
Expand All @@ -59,23 +50,16 @@ jobs:
steps:
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
# with:
# ref: ${{ github.event.pull_request.base.sha }}

- uses: cachix/install-nix-action@v24
with:
extra_nix_config: |
sandbox = false
- uses: ./.github/workflows/include/rust-wasm-setup

- name: Build and measure base branch
id: measure
run: |
nix build -L .#query-engine-wasm-gz
for provider in "postgresql" "mysql" "sqlite"; do
echo "${provider}_size=$(wc --bytes < ./result/query-engine-$provider.wasm)" >> $GITHUB_OUTPUT
echo "${provider}_size_gz=$(wc --bytes < ./result/query-engine-$provider.wasm.gz)" >> $GITHUB_OUTPUT
done
export ENGINE_SIZE_OUTPUT=$GITHUB_OUTPUT
make measure-qe-wasm
report-diff:
name: report module size
Expand Down Expand Up @@ -122,6 +106,9 @@ jobs:

- name: Create or update report
uses: peter-evans/create-or-update-comment@v3
# Only run on our repository
# It avoids an expected failure on forks
if: github.repository == 'prisma/prisma-engines'
with:
comment-id: ${{ steps.findReportComment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
Expand Down
70 changes: 52 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
REPO_ROOT := $(shell git rev-parse --show-toplevel)

CONFIG_PATH = ./query-engine/connector-test-kit-rs/test-configs
CONFIG_FILE = .test_config
SCHEMA_EXAMPLES_PATH = ./query-engine/example_schemas
DEV_SCHEMA_FILE = dev_datamodel.prisma
DRIVER_ADAPTERS_BRANCH ?= main

ifndef DISABLE_NIX
NIX := $(shell type nix 2> /dev/null)
endif
ENGINE_SIZE_OUTPUT ?= /dev/stdout
QE_WASM_VERSION ?= 0.0.0
SCHEMA_WASM_VERSION ?= 0.0.0

LIBRARY_EXT := $(shell \
case "$$(uname -s)" in \
Expand All @@ -19,6 +20,20 @@ PROFILE ?= dev

default: build

###############
# clean tasks #
###############

clean-qe-wasm:
@echo "Cleaning query-engine/query-engine-wasm/pkg" && \
cd query-engine/query-engine-wasm/pkg && find . ! -name '.' ! -name '..' ! -name 'README.md' -exec rm -rf {} +

clean-cargo:
@echo "Cleaning cargo" && \
cargo clean

clean: clean-qe-wasm clean-cargo

###################
# script wrappers #
###################
Expand All @@ -39,6 +54,29 @@ build:
build-qe:
cargo build --package query-engine

build-qe-napi:
cargo build --package query-engine-node-api --profile $(PROFILE)

build-qe-wasm:
cd query-engine/query-engine-wasm && \
./build.sh $(QE_WASM_VERSION) query-engine/query-engine-wasm/pkg

build-qe-wasm-gz: build-qe-wasm
@cd query-engine/query-engine-wasm/pkg && \
for provider in postgresql mysql sqlite; do \
tar -zcvf $$provider.gz $$provider; \
done;

build-schema-wasm:
@printf '%s\n' "🛠️ Building the Rust crate"
cargo build --profile $(PROFILE) --target=wasm32-unknown-unknown -p prisma-schema-build

@printf '\n%s\n' "📦 Creating the npm package"
WASM_BUILD_PROFILE=$(PROFILE) \
NPM_PACKAGE_VERSION=$(SCHEMA_WASM_VERSION) \
out="$(REPO_ROOT)/target/prisma-schema-wasm" \
./prisma-schema-wasm/scripts/install.sh

# Emulate pedantic CI compilation.
pedantic:
RUSTFLAGS="-D warnings" cargo fmt -- --check && RUSTFLAGS="-D warnings" cargo clippy --all-targets
Expand Down Expand Up @@ -77,6 +115,11 @@ test-qe-verbose-st:
test-qe-black-box: build-qe
cargo test --package black-box-tests -- --test-threads 1

check-schema-wasm-package: build-schema-wasm
PRISMA_SCHEMA_WASM="$(REPO_ROOT)/target/prisma-schema-wasm" \
out=$(shell mktemp -d) \
NODE=$(shell which node) \
./prisma-schema-wasm/scripts/check.sh

###########################
# Database setup commands #
Expand Down Expand Up @@ -326,21 +369,12 @@ test-driver-adapter-planetscale-wasm: test-planetscale-wasm
# Local dev commands #
######################

build-qe-napi:
cargo build --package query-engine-node-api --profile $(PROFILE)

build-qe-wasm:
ifdef NIX
@echo "Building wasm engine on nix"
rm -rf query-engine/query-engine-wasm/pkg
nix run .#export-query-engine-wasm 0.0.0 query-engine/query-engine-wasm/pkg
else
cd query-engine/query-engine-wasm && ./build.sh 0.0.0 query-engine/query-engine-wasm/pkg
endif

measure-qe-wasm: build-qe-wasm
measure-qe-wasm: build-qe-wasm-gz
@cd query-engine/query-engine-wasm/pkg; \
gzip -k -c query_engine_bg.wasm | wc -c | awk '{$$1/=(1024*1024); printf "Current wasm query-engine size compressed: %.3fMB\n", $$1}'
for provider in postgresql mysql sqlite; do \
echo "$${provider}_size=$$(cat $$provider/* | wc -c | tr -d ' ')" >> $(ENGINE_SIZE_OUTPUT); \
echo "$${provider}_size_gz=$$(cat $$provider.gz | wc -c | tr -d ' ')" >> $(ENGINE_SIZE_OUTPUT); \
done;

build-driver-adapters-kit: build-driver-adapters
cd query-engine/driver-adapters && pnpm i && pnpm build
Expand Down
Loading

0 comments on commit c1d9358

Please sign in to comment.