diff --git a/Makefile b/Makefile index c694e32..df44004 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ wasm: wasm-dist static-prep wasm-dist: web/src/*.rs web/src/components/*.rs cd web; sh ../scripts/wasm-build.sh debug + cd web; sh ../scripts/wasm-sourcemap.sh clean: rm -rf web/dist/* diff --git a/flake.lock b/flake.lock index 9a80f3f..fc6e540 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "cargo-wasm2map-src": { + "flake": false, + "locked": { + "lastModified": 1693927731, + "narHash": "sha256-oqJ9ZZLvUK57A9Kf6L4pPrW6nHqb+18+JGKj9HfIaaM=", + "owner": "mtolmacs", + "repo": "wasm2map", + "rev": "c7d80748b7f3af37df24770b9330b17aa9599e3e", + "type": "github" + }, + "original": { + "owner": "mtolmacs", + "repo": "wasm2map", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -31,24 +47,6 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "gitignore": { "flake": false, "locked": { @@ -114,6 +112,7 @@ }, "root": { "inputs": { + "cargo-wasm2map-src": "cargo-wasm2map-src", "flake-compat": "flake-compat", "flake-utils": "flake-utils", "gitignore": "gitignore", @@ -142,21 +141,6 @@ "repo": "rust-overlay", "type": "github" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index cd91171..3d93b23 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,9 @@ }; naersk.url = "github:nix-community/naersk"; flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; + cargo-wasm2map-src = { url = "github:mtolmacs/wasm2map"; flake = false; }; }; - outputs = {nixpkgs, flake-utils, rust-overlay, naersk, ...}: + outputs = {nixpkgs, flake-utils, rust-overlay, naersk, cargo-wasm2map-src, ...}: let kitchenGen = (import ./nix/kitchen/default.nix); kitchenWasmGen = (import ./nix/kitchenWasm/default.nix); @@ -42,9 +43,16 @@ wasm-pack = wasm-packGen { inherit rust-wasm naersk-lib pkgs; }; + cargo-wasm2map = naersk-lib.buildPackage { + pname = "cargo-wasm2map"; + version = "v0.1.0"; + build-inputs = [ rust-wasm ]; + src = cargo-wasm2map-src; + cargoBuildOptions = opts: opts ++ ["-p" "cargo-wasm2map" ]; + }; wasm-bindgen = pkgs.callPackage wasm-bindgenGen { inherit pkgs; }; kitchenWasm = kitchenWasmGen { - inherit pkgs rust-wasm wasm-bindgen version; + inherit pkgs rust-wasm wasm-bindgen version cargo-wasm2map; lockFile = ./Cargo.lock; outputHashes = { # I'm maintaining some patches for these so the lockfile hashes are a little @@ -89,7 +97,7 @@ program = "${kitchen}/bin/kitchen"; }; devShell = pkgs.callPackage ./nix/devShell/default.nix { - inherit rust-wasm wasm-bindgen; + inherit rust-wasm wasm-bindgen cargo-wasm2map; wasm-pack-hermetic = wasm-pack; }; } diff --git a/nix/devShell/default.nix b/nix/devShell/default.nix index 81aff51..9ffb60d 100644 --- a/nix/devShell/default.nix +++ b/nix/devShell/default.nix @@ -1,8 +1,8 @@ let lib = import ../lib/lib.nix; in -{ pkgs, rust-wasm, wasm-pack-hermetic, wasm-bindgen }: +{ pkgs, rust-wasm, wasm-pack-hermetic, wasm-bindgen, cargo-wasm2map }: with pkgs; mkShell { - buildInputs = (lib.darwin-sdk pkgs) ++ (with pkgs; [wasm-bindgen wasm-pack-hermetic llvm clang rust-wasm binaryen]); + buildInputs = (lib.darwin-sdk pkgs) ++ (with pkgs; [wasm-bindgen wasm-pack-hermetic llvm clang rust-wasm binaryen cargo-wasm2map]); } diff --git a/nix/kitchenWasm/default.nix b/nix/kitchenWasm/default.nix index 7a747c4..4a3b669 100644 --- a/nix/kitchenWasm/default.nix +++ b/nix/kitchenWasm/default.nix @@ -4,6 +4,7 @@ wasm-bindgen, lockFile, outputHashes, + cargo-wasm2map, }: with pkgs; let @@ -18,7 +19,7 @@ stdenv.mkDerivation { inherit src pname; version = version; # we need wasmb-bindgen v0.2.83 exactly - buildInputs = [ rust-wasm wasm-bindgen wasm-pack binaryen]; + buildInputs = [ rust-wasm wasm-bindgen wasm-pack binaryen cargo-wasm2map]; propagatedBuildInputs = [ rust-wasm wasm-bindgen wasm-pack binaryen]; phases = [ "postUnpackPhase" "buildPhase"]; postUnpackPhase = '' @@ -34,6 +35,7 @@ stdenv.mkDerivation { export project=kitchen sh ../scripts/wasm-build.sh release sh ../scripts/wasm-opt.sh release + sh ../scripts/wasm-sourcemap.sh rm -f $out/kitchen_wasm_bg.wasm cp -r index.html $out cp -r favicon.ico $out diff --git a/scripts/wasm-sourcemap.sh b/scripts/wasm-sourcemap.sh new file mode 100644 index 0000000..1f952de --- /dev/null +++ b/scripts/wasm-sourcemap.sh @@ -0,0 +1,3 @@ +set -x + +cargo-wasm2map wasm2map --patch $out/${project}_wasm_bg.wasm --base-url=http://localhost:3030