Skip to content

Commit

Permalink
udate nix build
Browse files Browse the repository at this point in the history
  • Loading branch information
rambip committed Nov 30, 2023
1 parent 8eb4f1b commit bbb19b0
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
description = "random leptos project";
description = "a dioxus markdown component";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
Expand All @@ -13,7 +14,6 @@
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs = { self, rust-overlay, nixpkgs, flake-utils, crane }:
Expand All @@ -35,25 +35,62 @@
);
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;

# discard the directories inside examples to build the library less often
libSrc = lib.cleanSourceWith {
src = ./.;
filter = path: type:
(builtins.match ".*examples/.*" path == null)
&& (craneLib.filterCargoSources path type)
;
};

fullSrc = lib.cleanSourceWith {
src = ./.;
filter = path: type:
(lib.hasSuffix "\.html" path) || (lib.hasSuffix "\.css" path)
|| (craneLib.filterCargoSources path type)
;
};

CARGO_BUILD_TARGET = "wasm32-unknown-unknown";

# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly {
inherit CARGO_BUILD_TARGET;
src = libSrc;
doCheck = false;
};

buildExample = name: craneLib.buildTrunkPackage {
inherit CARGO_BUILD_TARGET cargoArtifacts;
src = fullSrc;
pname = "dioxus-markdown-${name}";
trunkIndexPath = "examples/${name}/index.html";
cargoExtraArgs = "--package=./examples/${name}";
# RELATIVE URLS are a MESS
# https://github.com/thedodd/trunk/pull/470
trunkExtraBuildArgs = "--public-url=/dioxus-markdown/${name}";

nativeBuildInputs = [
(pkgs.wasm-bindgen-cli.override {
version = "0.2.87";
hash = "sha256-0u9bl+FkXEK2b54n7/l9JOCtKo+pb42GF9E1EnAUQa0=";
cargoHash = "sha256-AsZBtE2qHJqQtuCt/wCAgOoxYMfvDh8IzBPAOkYSYko=";
})
];
};
example_names = builtins.attrNames(builtins.readDir ./examples);
attr_examples = builtins.map
(name: {inherit name; path=buildExample name; value=buildExample name;})
example_names;

examples = builtins.listToAttrs attr_examples;
in
{
checks = {};
packages = {
default = craneLib.buildTrunkPackage {
inherit CARGO_BUILD_TARGET;
src=./.;
pname = "random-leptos-project";
trunkIndexPath = "./index.html";
# trunkExtraBuildArgs = "--public-url=...";
nativeBuildInputs = [
(pkgs.wasm-bindgen-cli.override {
version = "0.2.87";
hash = "sha256-0u9bl+FkXEK2b54n7/l9JOCtKo+pb42GF9E1EnAUQa0=";
cargoHash = "sha256-AsZBtE2qHJqQtuCt/wCAgOoxYMfvDh8IzBPAOkYSYko=";
})
];
};
packages = examples // {
default = pkgs.linkFarm "dioxus-markdown examples" attr_examples;
};

devShells.default = pkgs.mkShell {
Expand All @@ -64,10 +101,9 @@
pkg-config
trunk
rust-analyzer
cargo-expand
dioxus-cli
];
};
}
);
}

0 comments on commit bbb19b0

Please sign in to comment.