diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fb3a52..986d6a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. `crateNameFromCargoToml`) if they are not specified * `mkCargoDerivation` now defaults to an empty `checkPhaseCargoCommand` if not specified +* `cargoFmt` now delegates to `mkCargoDerivation` instead of `cargoBuild` ### Fixed * Installing binaries now uses the same version of cargo as was used to build diff --git a/docs/API.md b/docs/API.md index fbd6460..c6b3bd0 100644 --- a/docs/API.md +++ b/docs/API.md @@ -402,20 +402,18 @@ Create a derivation which will run a `cargo fmt` invocation in a cargo workspace. 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 -* `cargoBuildCommand` will be set to run `cargo fmt` in the workspace. -* `cargoExtraArgs` will have `rustFmtExtraArgs` appended to it - - Default value: `""` * `cargoVendorDir` is disabled/cleared -* `doCheck` is disabled * `pnameSuffix` will be set to `"-fmt"` #### Optional attributes -* `rustFmtExtraArgs`: additional flags to be passed in the rustfmt invocation - - Default value: `""` * `cargoExtraArgs`: additional flags to be passed in the cargo invocation - Default value: `""` +* `rustFmtExtraArgs`: additional flags to be passed in the rustfmt invocation + - Default value: `""` #### Native build dependencies 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 environment variables during the build, you can bring them back via `.overrideAttrs`. +* `cargoExtraArgs` * `rustFmtExtraArgs` ### `lib.cargoNextest` diff --git a/lib/cargoFmt.nix b/lib/cargoFmt.nix index eb478d9..9c0799b 100644 --- a/lib/cargoFmt.nix +++ b/lib/cargoFmt.nix @@ -1,4 +1,4 @@ -{ cargoBuild +{ mkCargoDerivation , rustfmt }: @@ -7,16 +7,17 @@ , ... }@origArgs: let - args = builtins.removeAttrs origArgs [ "rustFmtExtraArgs" ]; + args = builtins.removeAttrs origArgs [ + "cargoExtraArgs" + "rustFmtExtraArgs" + ]; in -cargoBuild (args // { +mkCargoDerivation (args // { cargoArtifacts = null; cargoVendorDir = null; - doCheck = false; pnameSuffix = "-fmt"; - cargoBuildCommand = "cargo fmt"; - cargoExtraArgs = "${cargoExtraArgs} -- --check ${rustFmtExtraArgs}"; + buildPhaseCargoCommand = "cargo fmt ${cargoExtraArgs} -- --check ${rustFmtExtraArgs}"; nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ rustfmt ];