Skip to content

Commit

Permalink
nix: add prisma-schema-wasm.dev derivation (#4600)
Browse files Browse the repository at this point in the history
Make it possible to conjure a local debug build of
`@prisma/prisma-schema-wasm` npm package with `nix build
.#prisma-schema-wasm.dev` command.

Normal `nix build .#prisma-schema-wasm` still builds in release profile
by default.

This makes it easier to test local changes to DMMF end-to-end with
TypeScript client generator.
  • Loading branch information
aqrln authored Dec 20, 2023
1 parent f8ac68b commit 388f03a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
26 changes: 17 additions & 9 deletions nix/prisma-schema-wasm.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, system, self', ... }:
{ pkgs, lib, self', ... }:

let
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../prisma-schema-wasm/rust-toolchain.toml;
Expand All @@ -7,14 +7,22 @@ let
inherit (builtins) readFile replaceStrings;
in
{
packages.prisma-schema-wasm = stdenv.mkDerivation {
name = "prisma-schema-wasm";
nativeBuildInputs = with pkgs; [ git wasm-bindgen-cli toolchain ];
inherit (self'.packages.prisma-engines) configurePhase src;

buildPhase = "cargo build --release --target=wasm32-unknown-unknown -p prisma-schema-build";
installPhase = readFile "${scriptsDir}/install.sh";
};
packages.prisma-schema-wasm = lib.makeOverridable
({ profile }: stdenv.mkDerivation {
name = "prisma-schema-wasm";
nativeBuildInputs = with pkgs; [ git wasm-bindgen-cli toolchain ];
inherit (self'.packages.prisma-engines) configurePhase src;

buildPhase = "cargo build --profile=${profile} --target=wasm32-unknown-unknown -p prisma-schema-build";
installPhase = readFile "${scriptsDir}/install.sh";

WASM_BUILD_PROFILE = profile;

passthru = {
dev = self'.packages.prisma-schema-wasm.override { profile = "dev"; };
};
})
{ profile = "release"; };

# Takes a package version as its single argument, and produces
# prisma-schema-wasm with the right package.json in a temporary directory,
Expand Down
12 changes: 11 additions & 1 deletion prisma-schema-wasm/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

set -euo pipefail

if [[ -z "${WASM_BUILD_PROFILE:-}" ]]; then
WASM_BUILD_PROFILE="release"
fi

if [[ $WASM_BUILD_PROFILE == "dev" ]]; then
TARGET_DIR="debug"
else
TARGET_DIR=$WASM_BUILD_PROFILE
fi

printf '%s\n' "entering install.sh"

printf '%s\n' " -> Creating out dir..."
Expand All @@ -18,4 +28,4 @@ printf '%s\n' " -> Generating node package"
wasm-bindgen \
--target nodejs \
--out-dir "$out"/src \
target/wasm32-unknown-unknown/release/prisma_schema_build.wasm
"target/wasm32-unknown-unknown/$TARGET_DIR/prisma_schema_build.wasm"

0 comments on commit 388f03a

Please sign in to comment.