fix(rust): add rust standard library deps to the environment when the toolchain needs it
This is a fix for "error: no matching package named `rustc-literal-escaper` found" when adding "rust-src" to the components array in the toolchain file
This commit is contained in:
+38
-12
@@ -25,20 +25,39 @@
|
||||
}: let
|
||||
cfg = config.krantz.rust;
|
||||
|
||||
src = cfg.srcFiltered;
|
||||
manifest = (lib.importTOML "${src}/Cargo.toml").package;
|
||||
manifest = (lib.importTOML "${cfg.srcFiltered}/Cargo.toml").package;
|
||||
|
||||
craneLib =
|
||||
if cfg.srcToolchain != null && builtins.pathExists cfg.srcToolchain
|
||||
then
|
||||
(inputs.crane.mkLib (pkgs.extend inputs.rust-overlay.overlays.default)).overrideToolchain (
|
||||
p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain
|
||||
)
|
||||
if hasToolchain
|
||||
then (inputs.crane.mkLib rustPkgs).overrideToolchain mkRustToolchain
|
||||
else inputs.crane.mkLib pkgs;
|
||||
|
||||
# Attrs to be included for all crane functions that build our crate
|
||||
cargoBuildAttrs = let
|
||||
# Include the standard library Cargo.lock if we have the "rust-src" component in our toolchain
|
||||
cargoVendorDir =
|
||||
lib.optionalAttrs (
|
||||
hasToolchain
|
||||
&& lib.pipe cfg.srcToolchain [
|
||||
builtins.readFile
|
||||
fromTOML
|
||||
(t: t ? toolchain.components && builtins.elem "rust-src" t.toolchain.components)
|
||||
]
|
||||
) {
|
||||
cargoVendorDir = craneLib.vendorMultipleCargoDeps {
|
||||
inherit (craneLib.findCargoFiles cfg.srcFiltered) cargoConfigs;
|
||||
cargoLockList = [
|
||||
"${cfg.srcFiltered}/Cargo.lock"
|
||||
"${(mkRustToolchain rustPkgs).passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library/Cargo.lock"
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
rec {
|
||||
src = cfg.srcFiltered;
|
||||
|
||||
buildInputs = cfg.runtimeDeps;
|
||||
|
||||
# build dependencies
|
||||
nativeBuildInputs = cfg.buildDeps;
|
||||
|
||||
# Build *just* the cargo dependencies, so we can reuse
|
||||
@@ -46,7 +65,14 @@
|
||||
cargoArtifacts = craneLib.buildDepsOnly ({
|
||||
inherit src buildInputs nativeBuildInputs;
|
||||
}
|
||||
// cargoVendorDir
|
||||
// cfg.cargoArtifacts.extraAttrs);
|
||||
}
|
||||
// cargoVendorDir;
|
||||
|
||||
hasToolchain = cfg.srcToolchain != null && builtins.pathExists cfg.srcToolchain;
|
||||
rustPkgs = pkgs.extend inputs.rust-overlay.overlays.default;
|
||||
mkRustToolchain = p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain;
|
||||
in {
|
||||
options.krantz.rust = {
|
||||
enable = lib.mkEnableOption "building a cargo project with crane";
|
||||
@@ -206,8 +232,8 @@
|
||||
# Accessible through 'nix build', 'nix shell', 'nix run', etc
|
||||
packages = lib.mkIf cfg.package.enable {
|
||||
${cfg.package.name} = craneLib.buildPackage ({
|
||||
inherit src buildInputs nativeBuildInputs cargoArtifacts;
|
||||
}
|
||||
// cargoBuildAttrs
|
||||
// cfg.package.extraAttrs);
|
||||
};
|
||||
|
||||
@@ -224,10 +250,10 @@
|
||||
};
|
||||
|
||||
checks = lib.mkIf cfg.checks.enable {
|
||||
clippy = lib.mkIf cfg.checks.linter (craneLib.cargoClippy {
|
||||
inherit src buildInputs nativeBuildInputs cargoArtifacts;
|
||||
clippy = lib.mkIf cfg.checks.linter (craneLib.cargoClippy ({
|
||||
cargoClippyExtraArgs = "-- --deny warnings";
|
||||
});
|
||||
}
|
||||
// cargoBuildAttrs));
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user