diff --git a/CHANGELOG.md b/CHANGELOG.md index e728802d..c27a9a07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed * `buildTrunkPackage` will pass in `--release=true` (instead of just `--release`) for trunk versions 0.21 or higher to avoid argument ambiguities +* `buildTrunkPackage` will now correctly honor `buildPhaseCargoCommand` if + specified (previously the value of `buildPhaseCommand` was incorrectly being + used) * `removeReferencesToVendoredSourcesHook` avoids referencing `/dev/fd` directly since it may not be present on certain platforms diff --git a/checks/trunk-outdated-bindgen/Cargo.lock b/checks/trunk-outdated-bindgen/Cargo.lock deleted file mode 100644 index 3cd365fd..00000000 --- a/checks/trunk-outdated-bindgen/Cargo.lock +++ /dev/null @@ -1,154 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bumpalo" -version = "3.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "console_log" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8aed40e4edbf4d3b4431ab260b63fdc40f5780a4766824329ea0f1eefe3c0f" -dependencies = [ - "log", - "web-sys", -] - -[[package]] -name = "js-sys" -version = "0.3.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68c16e1bfd491478ab155fd8b4896b86f9ede344949b641e61501e07c2b8b4d5" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "proc-macro2" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "2.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "trunk" -version = "0.1.0" -dependencies = [ - "console_log", - "log", - "wasm-bindgen", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasm-bindgen" -version = "0.2.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b6cb788c4e39112fbe1822277ef6fb3c55cd86b95cb3d3c4c1c9597e4ac74b4" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e522ed4105a9d626d885b35d62501b30d9666283a5c8be12c14a8bdafe7822" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358a79a0cb89d21db8120cbfb91392335913e4890665b1a7981d9e956903b434" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a901d592cafaa4d711bc324edfaff879ac700b19c3dfd60058d2b445be2691eb" - -[[package]] -name = "web-sys" -version = "0.3.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b5f940c7edfdc6d12126d98c9ef4d1b3d470011c47c76a6581df47ad9ba721" -dependencies = [ - "js-sys", - "wasm-bindgen", -] diff --git a/checks/trunk-outdated-bindgen/Cargo.toml b/checks/trunk-outdated-bindgen/Cargo.toml deleted file mode 100644 index 3f935707..00000000 --- a/checks/trunk-outdated-bindgen/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "trunk" -version = "0.1.0" -edition = "2021" - -[dependencies] -console_log = "1.0.0" -log = "0.4.17" -wasm-bindgen = "=0.2.85" diff --git a/checks/trunk-outdated-bindgen/index.html b/checks/trunk-outdated-bindgen/index.html deleted file mode 100644 index 06501e80..00000000 --- a/checks/trunk-outdated-bindgen/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Trunk App - - -

Hello world!

- - diff --git a/checks/trunk-outdated-bindgen/src/main.rs b/checks/trunk-outdated-bindgen/src/main.rs deleted file mode 100644 index 1ad0b817..00000000 --- a/checks/trunk-outdated-bindgen/src/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - console_log::init().unwrap(); - log::debug!("Hi, this can run on the browser"); -} diff --git a/checks/trunk.nix b/checks/trunk.nix index b1568888..a37e2f2a 100644 --- a/checks/trunk.nix +++ b/checks/trunk.nix @@ -39,22 +39,10 @@ let trunkSimpleNoArtifacts = myLibWasm.buildTrunkPackage (defaultArgs // { pname = "trunk-simple-no-artifacts"; }); - - trunkOutdatedBindgen = myLibWasm.buildTrunkPackage { - pname = "trunk-outdated-bindgen"; - src = ./trunk-outdated-bindgen; - doCheck = false; - wasm-bindgen-cli = pkgs.wasm-bindgen-cli.override { - version = "0.2.85"; - hash = "sha256-0pTIzpu7dJM34CXmi83e8UV0E3N2bKJiOMw5WJQ2s/Y="; - cargoHash = "sha256-ZwmoFKmGaf5VvTTXjLyb2714Pu536E/8UxUzxI40ID8="; - }; - }; in runCommand "trunkTests" { } '' test -f ${trunkSimple}/*.wasm test -f ${trunkSimple}/*.css test -f ${trunkSimpleNoArtifacts}/*.wasm - test -f ${trunkOutdatedBindgen}/*.wasm mkdir -p $out '' diff --git a/examples/trunk-workspace/flake.nix b/examples/trunk-workspace/flake.nix index cea69391..7b126b08 100644 --- a/examples/trunk-workspace/flake.nix +++ b/examples/trunk-workspace/flake.nix @@ -4,10 +4,6 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - # The version of wasm-bindgen-cli needs to match the version in Cargo.lock - # Update this to include the version you need - nixpkgs-for-wasm-bindgen.url = "github:NixOS/nixpkgs/4e6868b1aa3766ab1de169922bb3826143941973"; - crane.url = "github:ipetkov/crane"; flake-utils.url = "github:numtide/flake-utils"; @@ -18,7 +14,7 @@ }; }; - outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, nixpkgs-for-wasm-bindgen, ... }: + outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { @@ -33,11 +29,7 @@ # wasm32-unknown-unknown is required for trunk. targets = [ "wasm32-unknown-unknown" ]; }; - craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchainFor).overrideScope (_final: _prev: { - # The version of wasm-bindgen-cli needs to match the version in Cargo.lock. You - # can unpin this if your nixpkgs commit contains the appropriate wasm-bindgen-cli version - inherit (import nixpkgs-for-wasm-bindgen { inherit system; }) wasm-bindgen-cli; - }); + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor; # When filtering sources, we want to allow assets other than .rs files unfilteredRoot = ./.; # The original, unfiltered source @@ -107,12 +99,26 @@ myClient = craneLib.buildTrunkPackage (wasmArgs // { pname = "trunk-workspace-client"; cargoArtifacts = cargoArtifactsWasm; - trunkIndexPath = "client/index.html"; + # Trunk expects the current directory to be the crate to compile + preBuild = '' + cd ./client + ''; + # After building, move the `dist` artifacts and restore the working directory + postBuild = '' + mv ./dist .. + cd .. + ''; # The version of wasm-bindgen-cli here must match the one from Cargo.lock. wasm-bindgen-cli = pkgs.wasm-bindgen-cli.override { version = "0.2.93"; hash = "sha256-DDdu5mM3gneraM85pAepBXWn3TMofarVR4NbjMdz3r0="; cargoHash = "sha256-birrg+XABBHHKJxfTKAMSlmTVYLmnmqMDfRnmG6g/YQ="; + # When updating to a new version comment out the above two lines and + # uncomment the bottom two lines. Then try to do a build, which will fail + # but will print out the correct value for `hash`. Replace the value and then + # repeat the process but this time the printed value will be for `cargoHash` + # hash = lib.fakeHash; + # cargoHash = lib.fakeHash; }; }); in diff --git a/examples/trunk/flake.nix b/examples/trunk/flake.nix index 2b2de6e2..a31a565c 100644 --- a/examples/trunk/flake.nix +++ b/examples/trunk/flake.nix @@ -4,10 +4,6 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - # The version of wasm-bindgen-cli needs to match the version in Cargo.lock - # Update this to include the version you need - nixpkgs-for-wasm-bindgen.url = "github:NixOS/nixpkgs/4e6868b1aa3766ab1de169922bb3826143941973"; - crane.url = "github:ipetkov/crane"; flake-utils.url = "github:numtide/flake-utils"; @@ -18,7 +14,7 @@ }; }; - outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, nixpkgs-for-wasm-bindgen, ... }: + outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { @@ -33,11 +29,7 @@ # wasm32-unknown-unknown is required for trunk targets = [ "wasm32-unknown-unknown" ]; }; - craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchainFor).overrideScope (_final: _prev: { - # The version of wasm-bindgen-cli needs to match the version in Cargo.lock. You - # can unpin this if your nixpkgs commit contains the appropriate wasm-bindgen-cli version - inherit (import nixpkgs-for-wasm-bindgen { inherit system; }) wasm-bindgen-cli; - }); + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor; # When filtering sources, we want to allow assets other than .rs files unfilteredRoot = ./.; # The original, unfiltered source @@ -87,6 +79,12 @@ version = "0.2.93"; hash = "sha256-DDdu5mM3gneraM85pAepBXWn3TMofarVR4NbjMdz3r0="; cargoHash = "sha256-birrg+XABBHHKJxfTKAMSlmTVYLmnmqMDfRnmG6g/YQ="; + # When updating to a new version comment out the above two lines and + # uncomment the bottom two lines. Then try to do a build, which will fail + # but will print out the correct value for `hash`. Replace the value and then + # repeat the process but this time the printed value will be for `cargoHash` + # hash = lib.fakeHash; + # cargoHash = lib.fakeHash; }; }); diff --git a/lib/buildTrunkPackage.nix b/lib/buildTrunkPackage.nix index e2c7d4d6..3bf5ba17 100644 --- a/lib/buildTrunkPackage.nix +++ b/lib/buildTrunkPackage.nix @@ -20,9 +20,9 @@ let buildTrunkPackage { wasm-bindgen-cli = pkgs.wasm-bindgen-cli.override { - version = "0.2.84"; - hash = "sha256-0rK+Yx4/Jy44Fw5VwJ3tG243ZsyOIBBehYU54XP/JGk="; - cargoHash = "sha256-vcpxcRlW1OKoD64owFF6mkxSqmNrvY+y3Ckn5UwEQ50="; + version = "${default-wasm-bindgen-cli.version}"; + hash = "${default-wasm-bindgen-cli.hash or "lib.fakeHash"}"; + cargoHash = "${default-wasm-bindgen-cli.cargoHash or "lib.fakeHash"}"; }; ... } @@ -81,7 +81,7 @@ mkCargoDerivation (args // { echo "TRUNK_TOOLS_WASM_OPT=''${TRUNK_TOOLS_WASM_OPT}" ''; - buildPhaseCargoCommand = args.buildPhaseCommand or '' + buildPhaseCargoCommand = args.buildPhaseCargoCommand or '' local profileArgs="" if [[ "$CARGO_PROFILE" == "release" ]]; then profileArgs="--release${lib.optionalString (lib.versionAtLeast trunk.version "0.21") "=true"}" diff --git a/test/flake.lock b/test/flake.lock index 5e23166f..eada5f1b 100644 --- a/test/flake.lock +++ b/test/flake.lock @@ -102,22 +102,6 @@ "type": "github" } }, - "nixpkgs-for-wasm-bindgen": { - "locked": { - "lastModified": 1691495139, - "narHash": "sha256-+zZIRTtXlA8gN8HPzczphPnB9L+yYpidBmFxKqWQy+A=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4e6868b1aa3766ab1de169922bb3826143941973", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4e6868b1aa3766ab1de169922bb3826143941973", - "type": "github" - } - }, "nixpkgs-latest-release": { "locked": { "lastModified": 1730651795, @@ -142,7 +126,6 @@ "flake-compat": "flake-compat", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "nixpkgs-for-wasm-bindgen": "nixpkgs-for-wasm-bindgen", "nixpkgs-latest-release": "nixpkgs-latest-release", "rust-overlay": "rust-overlay" } diff --git a/test/flake.nix b/test/flake.nix index 79e53970..131564c4 100644 --- a/test/flake.nix +++ b/test/flake.nix @@ -4,10 +4,6 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs-latest-release.url = "github:NixOS/nixpkgs/release-24.05"; - # The version of wasm-bindgen-cli needs to match the version in Cargo.lock - # Update this to include the version you need - nixpkgs-for-wasm-bindgen.url = "github:NixOS/nixpkgs/4e6868b1aa3766ab1de169922bb3826143941973"; - advisory-db = { url = "github:rustsec/advisory-db"; flake = false;