Skip to content

Commit 08d5baf

Browse files
committed
TODO fix lindera build
1 parent 7993359 commit 08d5baf

2 files changed

Lines changed: 212 additions & 42 deletions

File tree

flake.lock

Lines changed: 22 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 190 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,207 @@
11
{
2+
description = "Build a cargo workspace";
3+
24
inputs = {
3-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
7+
crane.url = "github:ipetkov/crane";
8+
49
flake-utils.url = "github:numtide/flake-utils";
5-
rust-overlay = {
6-
url = "github:oxalica/rust-overlay";
7-
inputs.nixpkgs.follows = "nixpkgs";
10+
11+
advisory-db = {
12+
url = "github:rustsec/advisory-db";
13+
flake = false;
814
};
9-
crane.url = "github:ipetkov/crane";
1015
};
16+
1117
outputs =
1218
{
19+
self,
1320
nixpkgs,
14-
flake-utils,
15-
rust-overlay,
1621
crane,
22+
flake-utils,
23+
advisory-db,
1724
...
1825
}:
1926
flake-utils.lib.eachDefaultSystem (
2027
system:
2128
let
22-
overlays = [ (import rust-overlay) ];
23-
pkgs = import nixpkgs { inherit system overlays; };
24-
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
29+
pkgs = nixpkgs.legacyPackages.${system};
2530

31+
inherit (pkgs) lib;
32+
33+
# the lindera-unidic v0.32.2 crate uses [1] an outdated unidic-mecab fork [2] and builds it in pure rust
34+
# [1] https://github.com/lindera/lindera/blob/v0.32.2/lindera-unidic/build.rs#L5-L11
35+
# [2] https://github.com/lindera/unidic-mecab
36+
lindera-unidic-src = pkgs.fetchurl {
37+
url = "https://dlwqk3ibdg1xh.cloudfront.net/unidic-mecab-2.1.2.tar.gz";
38+
hash = "sha256-JKx1/k5E2XO1XmWEfDX6Suwtt6QaB7ScoSUUbbn8EYk=";
39+
};
2640
craneLib = crane.mkLib pkgs;
41+
src = craneLib.cleanCargoSource ./.;
42+
43+
# Common arguments can be set here to avoid repeating them later
44+
commonArgs = {
45+
inherit src;
46+
strictDeps = true;
47+
48+
buildInputs =
49+
[
50+
# Add additional build inputs here
51+
]
52+
++ lib.optionals pkgs.stdenv.isDarwin [
53+
# Additional darwin specific inputs can be set here
54+
pkgs.libiconv
55+
];
56+
57+
# Additional environment variables can be set directly
58+
# MY_CUSTOM_VAR = "some value";
59+
# LINDERA_CACHE="${lindera-unidic-src}";
60+
};
61+
62+
# Build *just* the cargo dependencies (of the entire workspace),
63+
# so we can reuse all of that work (e.g. via cachix) when running in CI
64+
# It is *highly* recommended to use something like cargo-hakari to avoid
65+
# cache misses when building individual top-level-crates
66+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
67+
68+
individualCrateArgs = commonArgs // {
69+
inherit cargoArtifacts;
70+
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
71+
# NB: we disable tests since we'll run them all via cargo-nextest
72+
doCheck = false;
73+
};
74+
75+
fileSetForCrate =
76+
crate:
77+
lib.fileset.toSource {
78+
root = ./.;
79+
fileset = lib.fileset.unions [
80+
./Cargo.toml
81+
./Cargo.lock
82+
(lib.fileset.fileFilter (file: file.hasExt "md") ./.)
83+
(craneLib.fileset.commonCargoSources ./crates/wordbase)
84+
./crates/wordbase-cli
85+
(craneLib.fileset.commonCargoSources ./crates/jmdict-furigana)
86+
./crates/jmdict-furigana/README.md
87+
./crates/jmdict-furigana/src/jmdict_furigana.json.zip
88+
(craneLib.fileset.commonCargoSources ./crates/wordbase-api)
89+
./crates/wordbase/src/records.html
90+
./crates/wordbase/README.md
91+
./crates/wordbase/migrations
92+
./crates/wordbase-api/README.md
93+
./.sqlx
94+
95+
# (craneLib.fileset.commonCargoSources ./crates/my-workspace-hack)
96+
(craneLib.fileset.commonCargoSources crate)
97+
];
98+
};
99+
100+
# Build the top-level crates of the workspace as individual derivations.
101+
# This allows consumers to only depend on (and build) only what they need.
102+
# Though it is possible to build the entire workspace as a single derivation,
103+
# so this is left up to you on how to organize things
104+
#
105+
# Note that the cargo workspace must define `workspace.members` using wildcards,
106+
# otherwise, omitting a crate (like we do below) will result in errors since
107+
# cargo won't be able to find the sources for all members.
108+
wordbase-cli = craneLib.buildPackage (
109+
individualCrateArgs
110+
// {
111+
pname = "wordbase-cli";
112+
cargoExtraArgs = "-p wordbase-cli";
113+
src = fileSetForCrate ./crates/wordbase-cli;
114+
}
115+
);
116+
117+
# my-server = craneLib.buildPackage (
118+
# individualCrateArgs
119+
# // {
120+
# pname = "my-server";
121+
# cargoExtraArgs = "-p my-server";
122+
# src = fileSetForCrate ./crates/my-server;
123+
# }
124+
# );
27125
in
28126
{
29-
packages.default = craneLib.buildPackage {
30-
src = craneLib.cleanCargoSource ./.;
127+
checks = {
128+
# Build the crates as part of `nix flake check` for convenience
129+
inherit wordbase-cli;
130+
131+
# Run clippy (and deny all warnings) on the workspace source,
132+
# again, reusing the dependency artifacts from above.
133+
#
134+
# Note that this is done as a separate derivation so that
135+
# we can block the CI if there are issues here, but not
136+
# prevent downstream consumers from building our crate by itself.
137+
# my-workspace-clippy = craneLib.cargoClippy (
138+
# commonArgs
139+
# // {
140+
# inherit cargoArtifacts;
141+
# cargoClippyExtraArgs = "--all-targets -- --deny warnings";
142+
# }
143+
# );
144+
145+
wordbase-workspace-doc = craneLib.cargoDoc (
146+
commonArgs
147+
// {
148+
inherit cargoArtifacts;
149+
}
150+
);
151+
152+
# Check formatting
153+
wordbase-workspace-fmt = craneLib.cargoFmt {
154+
inherit src;
155+
};
31156

32-
# Add extra inputs here or any other derivation settings
33-
# doCheck = true;
34-
# buildInputs = [];
35-
# nativeBuildInputs = [];
157+
my-workspace-toml-fmt = craneLib.taploFmt {
158+
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
159+
# taplo arguments can be further customized below as needed
160+
# taploExtraArgs = "--config ./taplo.toml";
161+
};
162+
163+
# Ensure that cargo-hakari is up to date
164+
# my-workspace-hakari = craneLib.mkCargoDerivation {
165+
# inherit src;
166+
# pname = "my-workspace-hakari";
167+
# cargoArtifacts = null;
168+
# doInstallCargoArtifacts = false;
169+
#
170+
# buildPhaseCargoCommand = ''
171+
# cargo hakari generate --diff # workspace-hack Cargo.toml is up-to-date
172+
# cargo hakari manage-deps --dry-run # all workspace crates depend on workspace-hack
173+
# cargo hakari verify
174+
# '';
175+
#
176+
# nativeBuildInputs = [
177+
# pkgs.cargo-hakari
178+
# ];
179+
# };
180+
};
181+
182+
packages = {
183+
inherit wordbase-cli;
184+
};
185+
186+
apps = {
187+
wordbase-cli = flake-utils.lib.mkApp {
188+
drv = wordbase-cli;
189+
};
36190
};
37191

192+
# devShells.default = craneLib.devShell {
193+
# # Inherit inputs from checks.
194+
# checks = self.checks.${system};
195+
#
196+
# # Additional dev-shell environment variables can be set directly
197+
# # MY_CUSTOM_DEVELOPMENT_VAR = "something else";
198+
#
199+
# # Extra inputs can be added here; cargo and rustc are provided by default.
200+
# packages = [
201+
# pkgs.cargo-hakari
202+
# ];
203+
# };
204+
38205
devShells.default = pkgs.mkShell {
39206
buildInputs = with pkgs; [
40207
just
@@ -59,7 +226,14 @@
59226
# Binding generation
60227
ktlint
61228
];
229+
230+
# shellHook = ''
231+
# # Caching for lindera-unidic
232+
# [ "''${LINDERA_CACHE+x}" ] ||
233+
# export LINDERA_CACHE="''${XDG_CACHE_HOME:-$HOME/.cache}/lindera"
234+
# '';
62235
};
236+
63237
}
64238
);
65239
}

0 commit comments

Comments
 (0)