-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace.nix
86 lines (76 loc) · 2.61 KB
/
workspace.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# This file defines the actual package.
#
# We want to be able to run commands from a nix shell using this package
# definition.
{
lib,
stdenv,
craneLib,
libffi,
bzip2,
libiconv,
libxml2,
llvmPackages_19,
}:
let
workspaceToml = lib.importTOML ./Cargo.toml;
# nb: if any crates set `version.workspace = false`, this will need to be updated,
# but otherwise we can use the workspace version for every crate.
version = workspaceToml.workspace.package.version;
workspaceMemberPaths = workspaceToml.workspace.members;
# Attrsets in this will add additional arguments to craneLib.buildPackage for the
# crate with the matching package name.
crateSpecificArgs = {
hieratika = {
meta.mainProgram = "hieratika";
};
};
# These are added as arguments to both the Cargo dependencies and each crate in the
# workspace.
commonArgs = {
src = craneLib.cleanCargoSource ./.;
# Disallow confusing buildInputs and nativeBuildInputs for sanity.
strictDeps = true;
# Things that are needed at build time on the system doing building.
nativeBuildInputs = [
llvmPackages_19.llvm
];
# The things that we need available at build and runtime on the target system.
buildInputs = [
libffi
libxml2
llvmPackages_19.llvm
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
bzip2
libiconv
];
};
# The Cargo.lock dependencies are global to the workspace, so we can build them
# separately, and thus only build them once for the whole workspace.
workspaceDeps = craneLib.buildDepsOnly (commonArgs // {
# Workspaces don't have names, so we'll give it the repo name for the dependencies.
pname = "hieratika-deps";
inherit version;
});
# A list of all the crates in this workspace, where each item in the list is a
# name-value pair for `lib.listToAttrs`. That way we get the crate names as the
# attrset keys.
memberCrates = lib.forEach workspaceMemberPaths (cratePath:
let
# The syntax for dynamic relative paths is weird, I know.
crateToml = lib.importTOML (./. + "/${cratePath}/Cargo.toml");
pname = crateToml.package.name;
# Add any arguments specific to this crate's args, if there are any.
crateOverrideArgs = crateSpecificArgs.${pname} or { };
in {
name = pname;
value = craneLib.buildPackage (commonArgs // {
inherit pname version;
# Note that `-p` takes the Cargo package name, not the workspace member path.
cargoExtraArgs = "-p ${pname}";
cargoArtifacts = workspaceDeps;
} // crateOverrideArgs);
}
);
in
lib.listToAttrs memberCrates