Use a nix flake
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/target
|
||||
/dist
|
||||
/result
|
||||
|
||||
|
||||
Generated
+98
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1771121070,
|
||||
"narHash": "sha256-aIlv7FRXF9q70DNJPI237dEDAznSKaXmL5lfK/Id/bI=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "a2812c19f1ed2e5ed5ce2ef7109798b575c180e1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1770843696,
|
||||
"narHash": "sha256-LovWTGDwXhkfCOmbgLVA10bvsi/P8eDDpRudgk68HA8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2343bbb58f99267223bc2aac4fc9ea301a155a16",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1771125043,
|
||||
"narHash": "sha256-ldf/s49n6rOAxl7pYLJGGS1N/assoHkCOWdEdLyNZkc=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "4912f951a26dc8142b176be2c2ad834319dc06e8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"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",
|
||||
"version": 7
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
{
|
||||
description = "3D demo";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
crane.url = "github:ipetkov/crane";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
crane,
|
||||
flake-utils,
|
||||
rust-overlay,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [(import rust-overlay)];
|
||||
};
|
||||
|
||||
inherit (pkgs) lib;
|
||||
|
||||
rustToolchainFor = p:
|
||||
p.rust-bin.stable.latest.default.override {
|
||||
# Set the build targets supported by the toolchain,
|
||||
# wasm32-unknown-unknown is required for trunk
|
||||
targets = ["wasm32-unknown-unknown"];
|
||||
};
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor;
|
||||
|
||||
# When filtering sources, we want to allow assets other than .rs files
|
||||
unfilteredRoot = ./.; # The original, unfiltered source
|
||||
src = lib.fileset.toSource {
|
||||
root = unfilteredRoot;
|
||||
fileset = lib.fileset.unions [
|
||||
# Default files from crane (Rust and cargo files)
|
||||
(craneLib.fileset.commonCargoSources unfilteredRoot)
|
||||
(lib.fileset.fileFilter (
|
||||
file:
|
||||
lib.any file.hasExt [
|
||||
"html"
|
||||
"scss"
|
||||
"wgsl"
|
||||
]
|
||||
)
|
||||
unfilteredRoot)
|
||||
# Example of a folder for images, icons, etc
|
||||
(lib.fileset.maybeMissing ./assets)
|
||||
];
|
||||
};
|
||||
|
||||
# Common arguments can be set here to avoid repeating them later
|
||||
commonArgs = {
|
||||
inherit src;
|
||||
strictDeps = true;
|
||||
# We must force the target, otherwise cargo will attempt to use your native target
|
||||
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
|
||||
|
||||
buildInputs =
|
||||
[
|
||||
# Add additional build inputs here
|
||||
]
|
||||
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||
# Additional darwin specific inputs can be set here
|
||||
pkgs.libiconv
|
||||
];
|
||||
};
|
||||
|
||||
# Build *just* the cargo dependencies, so we can reuse
|
||||
# all of that work (e.g. via cachix) when running in CI
|
||||
cargoArtifacts = craneLib.buildDepsOnly (
|
||||
commonArgs
|
||||
// {
|
||||
# You cannot run cargo test on a wasm build
|
||||
doCheck = false;
|
||||
}
|
||||
);
|
||||
|
||||
# Build the actual crate itself, reusing the dependency
|
||||
# artifacts from above.
|
||||
# This derivation is a directory you can put on a webserver.
|
||||
my-app = craneLib.buildTrunkPackage (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
# The version of wasm-bindgen-cli here must match the one from Cargo.lock.
|
||||
# When updating to a new version replace the hash values with lib.fakeHash,
|
||||
# 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 the second `hash` below
|
||||
wasm-bindgen-cli = pkgs.wasm-bindgen-cli_0_2_108;
|
||||
}
|
||||
);
|
||||
|
||||
# Quick example on how to serve the app,
|
||||
# This is just an example, not useful for production environments
|
||||
serve-app = pkgs.writeShellScriptBin "serve-app" ''
|
||||
${pkgs.python3Minimal}/bin/python3 -m http.server --directory ${my-app} 8080
|
||||
'';
|
||||
in {
|
||||
checks = {
|
||||
# Build the crate as part of `nix flake check` for convenience
|
||||
inherit my-app;
|
||||
|
||||
# Run clippy (and deny all warnings) on the crate source,
|
||||
# again, reusing the dependency artifacts from above.
|
||||
#
|
||||
# Note that this is done as a separate derivation so that
|
||||
# we can block the CI if there are issues here, but not
|
||||
# prevent downstream consumers from building our crate by itself.
|
||||
my-app-clippy = craneLib.cargoClippy (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
}
|
||||
);
|
||||
|
||||
# Check formatting
|
||||
my-app-fmt = craneLib.cargoFmt {
|
||||
inherit src;
|
||||
};
|
||||
};
|
||||
|
||||
packages.default = my-app;
|
||||
|
||||
apps.default = flake-utils.lib.mkApp {
|
||||
drv = serve-app;
|
||||
};
|
||||
|
||||
devShells.default = craneLib.devShell {
|
||||
# Inherit inputs from checks.
|
||||
checks = self.checks.${system};
|
||||
|
||||
# Additional dev-shell environment variables can be set directly
|
||||
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
|
||||
|
||||
# Extra inputs can be added here; cargo and rustc are provided by default.
|
||||
packages = [
|
||||
pkgs.trunk
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>wgpu demo</title>
|
||||
<link data-trunk rel="rust" data-wasm-opt="z" />
|
||||
<link data-trunk rel="rust" data-wasm-opt="0" />
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
|
||||
Reference in New Issue
Block a user