Skip to content

Commit

Permalink
Add support for passing options to the Clippy command
Browse files Browse the repository at this point in the history
  • Loading branch information
iensu authored and Patryk27 committed Jul 1, 2023
1 parent a8906d2 commit 714e701
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ process, rest is passed-through into `mkDerivation`.
| `remapPathPrefix` | When `true`, rustc remaps the (`/nix/store`) source paths to `/sources` to reduce the number of dependencies in the closure. Default: `true` |
| `cargoTestCommands` | The commands to run in the `checkPhase`. Do not forget to set [`doCheck`](https://nixos.org/nixpkgs/manual/#ssec-check-phase). The argument must be a function modifying the default value. <br/> Default: `[ ''cargo $cargo_options test $cargo_test_options'' ]` |
| `cargoTestOptions` | Options passed to cargo test, i.e. `cargo test <OPTS>`. These options can be accessed during the build through the environment variable `cargo_test_options`. <br/> Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces. <br/> The argument must be a function modifying the default value. <br/> Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' ]` |
| `cargoClippyOptions` | Options passed to cargo clippy, i.e. `cargo clippy -- <OPTS>`. These options can be accessed during the build through the environment variable `cargo_clippy_options`. <br /> Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces. <br/> The argument must be a function modifying the default value. <br/> Default: `[ "-D warnings" ]` |
| `nativeBuildInputs` | Extra `nativeBuildInputs` to all derivations. Default: `[]` |
| `buildInputs` | Extra `buildInputs` to all derivations. Default: `[]` |
| `cargoOptions` | Options passed to all cargo commands, i.e. `cargo <OPTS> ...`. These options can be accessed during the build through the environment variable `cargo_options`. <br/> Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces. <br/> The argument must be a function modifying the default value. <br/> Default: `[ ]` |
Expand Down
2 changes: 2 additions & 0 deletions build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# Which drops the run-time dependency on the crates-io source thereby
# significantly reducing the Nix closure size.
, removeReferencesToSrcFromDocs
, cargoClippyOptions
, mode ? "build" # `build`, `check`, `test` or `clippy`
, gitDependencies
, pname
Expand Down Expand Up @@ -140,6 +141,7 @@ let
cargo_options = cargoOptions;
cargo_build_options = cargoBuildOptions;
cargo_test_options = cargoTestOptions;
cargo_clippy_options = cargoClippyOptions;
cargo_doc_options = cargoDocOptions;
cargo_bins_jq_filter = copyBinsFilter;
cargo_libs_jq_filter = copyLibsFilter;
Expand Down
12 changes: 11 additions & 1 deletion config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ let
cargoTestOptions =
allowFun attrs0 "cargoTestOptions" [ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' ];

# Options passed to cargo clippy, i.e. `cargo clippy -- <OPTS>`. These options
# can be accessed during the build through the environment variable
# `cargo_clippy_options`. <br />
# Note: these values are not (shell) escaped, meaning that you can use
# environment variables but must be careful when introducing e.g. spaces. <br/>
cargoClippyOptions =
allowFun attrs0 "cargoClippyOptions" [ "-D warnings" ];

# Extra `nativeBuildInputs` to all derivations.
nativeBuildInputs = attrs0.nativeBuildInputs or [];

Expand Down Expand Up @@ -248,7 +256,7 @@ let
else if (mode == "test") then
''cargo $cargo_options test $cargo_test_options >> $cargo_build_output_json''
else if (mode == "clippy") then
''cargo $cargo_options clippy $cargo_build_options -- -D warnings >> $cargo_build_output_json''
''cargo $cargo_options clippy $cargo_build_options -- $cargo_clippy_options >> $cargo_build_output_json''
else throw "Unknown mode ${mode}, allowed modes: build, check, test, clippy";

# config used during build the prebuild and the final build
Expand All @@ -275,6 +283,8 @@ let
cargoTestCommands
cargoTestOptions

cargoClippyOptions

doDoc
doDocFail
cargoDocCommands
Expand Down

0 comments on commit 714e701

Please sign in to comment.