mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-22 23:17:15 +03:00
Add cargoFmt
This commit is contained in:
parent
e457182093
commit
438154f265
37
README.md
37
README.md
@ -242,6 +242,43 @@ environment variables during the build, you can bring them back via
|
||||
`.overrideAttrs`.
|
||||
* `cargoClippyExtraArgs`
|
||||
|
||||
### `lib.cargoFmt`
|
||||
|
||||
`cargoFmt :: set -> drv`
|
||||
|
||||
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.
|
||||
* `cargoArtifacts` is disabled/cleared
|
||||
* `cargoBuildCommand` will be set to run `cargo fmt` for all targets in the
|
||||
workspace.
|
||||
* `cargoExtraArgs` will have `rustFmtExtraArgs` appended to it
|
||||
- Default value: `""`
|
||||
* `cargoVendorDir` is disabled/cleared
|
||||
* `doCheck` is disabled
|
||||
* `doInstallCargoArtifacts` is disabled
|
||||
* `doRemapSourcePathPrefix` 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: `""`
|
||||
|
||||
#### Native build dependencies
|
||||
The `rustfmt` package is automatically appended as a native build input to any
|
||||
other `nativeBuildInputs` specified by the caller.
|
||||
|
||||
#### Remove attributes
|
||||
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`.
|
||||
* `rustFmtExtraArgs`
|
||||
|
||||
### `lib.cleanCargoToml`
|
||||
|
||||
`cleanCargoToml :: set -> set`
|
||||
|
@ -15,6 +15,10 @@ onlyDrvs (lib.makeScope myLib.newScope (self:
|
||||
|
||||
clippy = callPackage ./clippy { };
|
||||
|
||||
cargoFmt = myLib.cargoFmt {
|
||||
src = ./simple;
|
||||
};
|
||||
|
||||
compilesFresh = callPackage ./compilesFresh.nix { };
|
||||
compilesFreshSimple = self.compilesFresh ./simple "simple" { };
|
||||
compilesFreshOverlappingTargets = self.compilesFresh
|
||||
|
@ -36,6 +36,7 @@
|
||||
craneLib = (crane.mkLib pkgs).overrideScope' (final: prev: {
|
||||
rustc = rustWithWasiTarget;
|
||||
cargo = rustWithWasiTarget;
|
||||
rustfmt = rustWithWasiTarget;
|
||||
});
|
||||
|
||||
my-crate = craneLib.buildPackage {
|
||||
|
24
lib/cargoFmt.nix
Normal file
24
lib/cargoFmt.nix
Normal file
@ -0,0 +1,24 @@
|
||||
{ cargoBuild
|
||||
, rustfmt
|
||||
}:
|
||||
|
||||
{ cargoExtraArgs ? ""
|
||||
, rustFmtExtraArgs ? ""
|
||||
, ...
|
||||
}@origArgs:
|
||||
let
|
||||
args = builtins.removeAttrs origArgs [ "rustFmtExtraArgs" ];
|
||||
in
|
||||
cargoBuild (args // {
|
||||
cargoArtifacts = null;
|
||||
cargoVendorDir = null;
|
||||
doCheck = false;
|
||||
doInstallCargoArtifacts = false;
|
||||
doRemapSourcePathPrefix = false;
|
||||
pnameSuffix = "-fmt";
|
||||
|
||||
cargoBuildCommand = "cargo fmt";
|
||||
cargoExtraArgs = "${cargoExtraArgs} -- --check ${rustFmtExtraArgs}";
|
||||
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ rustfmt ];
|
||||
})
|
@ -16,6 +16,7 @@ lib.makeScope newScope (self:
|
||||
buildPackage = callPackage ./buildPackage.nix { };
|
||||
cargoBuild = callPackage ./cargoBuild.nix { };
|
||||
cargoClippy = callPackage ./cargoClippy.nix { };
|
||||
cargoFmt = callPackage ./cargoFmt.nix { };
|
||||
cleanCargoToml = callPackage ./cleanCargoToml.nix { };
|
||||
crateNameFromCargoToml = callPackage ./crateNameFromCargoToml.nix { };
|
||||
downloadCargoPackage = callPackage ./downloadCargoPackage.nix { };
|
||||
|
Loading…
Reference in New Issue
Block a user