cargoFmt: use mkCargoDerivation instead of cargoBuild

This commit is contained in:
Ivan Petkov 2022-10-09 11:45:27 -07:00
parent cc7d69f1ed
commit 51bbfae3f6
3 changed files with 14 additions and 13 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
`crateNameFromCargoToml`) if they are not specified `crateNameFromCargoToml`) if they are not specified
* `mkCargoDerivation` now defaults to an empty `checkPhaseCargoCommand` if not * `mkCargoDerivation` now defaults to an empty `checkPhaseCargoCommand` if not
specified specified
* `cargoFmt` now delegates to `mkCargoDerivation` instead of `cargoBuild`
### Fixed ### Fixed
* Installing binaries now uses the same version of cargo as was used to build * Installing binaries now uses the same version of cargo as was used to build

View File

@ -402,20 +402,18 @@ Create a derivation which will run a `cargo fmt` invocation in a cargo
workspace. workspace.
Except where noted below, all derivation attributes are delegated to Except where noted below, all derivation attributes are delegated to
`cargoBuild`, and can be used to influence its behavior. `mkCargoDerivation`, and can be used to influence its behavior.
* `buildPhaseCargoCommand` will be set to run `cargo fmt` (in check mode) in the
workspace.
* `cargoArtifacts` is disabled/cleared * `cargoArtifacts` is disabled/cleared
* `cargoBuildCommand` will be set to run `cargo fmt` in the workspace.
* `cargoExtraArgs` will have `rustFmtExtraArgs` appended to it
- Default value: `""`
* `cargoVendorDir` is disabled/cleared * `cargoVendorDir` is disabled/cleared
* `doCheck` is disabled
* `pnameSuffix` will be set to `"-fmt"` * `pnameSuffix` will be set to `"-fmt"`
#### Optional attributes #### Optional attributes
* `rustFmtExtraArgs`: additional flags to be passed in the rustfmt invocation
- Default value: `""`
* `cargoExtraArgs`: additional flags to be passed in the cargo invocation * `cargoExtraArgs`: additional flags to be passed in the cargo invocation
- Default value: `""` - Default value: `""`
* `rustFmtExtraArgs`: additional flags to be passed in the rustfmt invocation
- Default value: `""`
#### Native build dependencies #### Native build dependencies
The `rustfmt` package is automatically appended as a native build input to any The `rustfmt` package is automatically appended as a native build input to any
@ -426,6 +424,7 @@ The following attributes will be removed before being lowered to
`cargoBuild`. If you absolutely need these attributes present as `cargoBuild`. If you absolutely need these attributes present as
environment variables during the build, you can bring them back via environment variables during the build, you can bring them back via
`.overrideAttrs`. `.overrideAttrs`.
* `cargoExtraArgs`
* `rustFmtExtraArgs` * `rustFmtExtraArgs`
### `lib.cargoNextest` ### `lib.cargoNextest`

View File

@ -1,4 +1,4 @@
{ cargoBuild { mkCargoDerivation
, rustfmt , rustfmt
}: }:
@ -7,16 +7,17 @@
, ... , ...
}@origArgs: }@origArgs:
let let
args = builtins.removeAttrs origArgs [ "rustFmtExtraArgs" ]; args = builtins.removeAttrs origArgs [
"cargoExtraArgs"
"rustFmtExtraArgs"
];
in in
cargoBuild (args // { mkCargoDerivation (args // {
cargoArtifacts = null; cargoArtifacts = null;
cargoVendorDir = null; cargoVendorDir = null;
doCheck = false;
pnameSuffix = "-fmt"; pnameSuffix = "-fmt";
cargoBuildCommand = "cargo fmt"; buildPhaseCargoCommand = "cargo fmt ${cargoExtraArgs} -- --check ${rustFmtExtraArgs}";
cargoExtraArgs = "${cargoExtraArgs} -- --check ${rustFmtExtraArgs}";
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ rustfmt ]; nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ rustfmt ];