diff --git a/nix/prisma-schema-wasm.nix b/nix/prisma-schema-wasm.nix index b0f0c3d2d54a..602e59b48ea5 100644 --- a/nix/prisma-schema-wasm.nix +++ b/nix/prisma-schema-wasm.nix @@ -1,4 +1,4 @@ -{ pkgs, system, self', ... }: +{ pkgs, lib, self', ... }: let toolchain = pkgs.rust-bin.fromRustupToolchainFile ../prisma-schema-wasm/rust-toolchain.toml; @@ -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, diff --git a/prisma-schema-wasm/scripts/install.sh b/prisma-schema-wasm/scripts/install.sh index 541eca728805..992dbd1ac380 100755 --- a/prisma-schema-wasm/scripts/install.sh +++ b/prisma-schema-wasm/scripts/install.sh @@ -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..." @@ -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"