Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: trunk-workspace: update for future compat #742

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
154 changes: 0 additions & 154 deletions checks/trunk-outdated-bindgen/Cargo.lock

This file was deleted.

9 changes: 0 additions & 9 deletions checks/trunk-outdated-bindgen/Cargo.toml

This file was deleted.

10 changes: 0 additions & 10 deletions checks/trunk-outdated-bindgen/index.html

This file was deleted.

4 changes: 0 additions & 4 deletions checks/trunk-outdated-bindgen/src/main.rs

This file was deleted.

12 changes: 0 additions & 12 deletions checks/trunk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
''
28 changes: 17 additions & 11 deletions examples/trunk-workspace/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions examples/trunk/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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;
};
});

Expand Down
8 changes: 4 additions & 4 deletions lib/buildTrunkPackage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"}";
};
...
}
Expand Down Expand Up @@ -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"}"
Expand Down
17 changes: 0 additions & 17 deletions test/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down