-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile benchmarks via Nix #1119
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,7 @@ | |
|
||
# Given a rust toolchain, provide Nickel's Rust dependencies, Nickel, as | ||
# well as rust tools (like clippy) | ||
mkCraneArtifacts = { rust ? mkRust { } }: | ||
mkCraneArtifacts = { rust ? mkRust { }, noRunBench ? false }: | ||
let | ||
craneLib = crane.lib.${system}.overrideToolchain rust; | ||
|
||
|
@@ -217,6 +217,18 @@ | |
nickel = buildPackage "nickel-lang"; | ||
lsp-nls = buildPackage "nickel-lang-lsp"; | ||
|
||
benchmarks = craneLib.mkCargoDerivation { | ||
inherit src cargoArtifacts; | ||
|
||
pnameSuffix = "-bench"; | ||
|
||
buildPhaseCargoCommand = '' | ||
cargo bench ${pkgs.lib.optionalString noRunBench "--no-run"} | ||
''; | ||
|
||
doInstallCargoArtifacts = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is here because we don't need any of the outputs. |
||
}; | ||
|
||
rustfmt = craneLib.cargoFmt { | ||
# Notice that unlike other Crane derivations, we do not pass `cargoArtifacts` to `cargoFmt`, because it does not need access to dependencies to format the code. | ||
inherit src; | ||
|
@@ -380,6 +392,7 @@ | |
packages = { | ||
inherit (mkCraneArtifacts { }) | ||
nickel | ||
benchmarks | ||
lsp-nls; | ||
default = pkgs.buildEnv { | ||
name = "nickel"; | ||
|
@@ -407,10 +420,11 @@ | |
}; | ||
|
||
checks = { | ||
inherit (mkCraneArtifacts { }) | ||
nickel | ||
lsp-nls | ||
inherit (mkCraneArtifacts { noRunBench = true; }) | ||
benchmarks | ||
clippy | ||
lsp-nls | ||
nickel | ||
rustfmt; | ||
# An optimizing release build is long: eschew optimizations in checks by | ||
# building a dev profile | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if crane had a
lib.cargoBench
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that make sense to have
benchmarks
be a function taking an attribute set{ noRun ? false }
as a parameter, and appending conditionally the--no-run
parameter? It's not very different, but somehow it confines the "domain knowledge" to themkArtifact
function (low-level commands and parameters). Any usage of benchmarks as a flake output then just has to decidenoRun = true
onnoRun = false
without having to leak the actual cargo commands to do so.I think that would solve as well your other issues: you wouldn't have to override
buildPhase
but could directly act onbuildPhaseCargoCommand
, and you would'nt have to callmkArtifacts
a second time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a very good plan! Only thing is that
benchmarks
can't be a generic function AFAICT, it needs to be a derivation, otherwise the CLI will chocke on e.g.nix flake show
.But this is solvable by moving the argument up to
mkCraneArtifacts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh indeed 👍 I thought this code was innside
mkArtifacts
, my bad.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well in fact we are in
mkArtifacts
! AFAICT,mkArtifacts
is just an internal value of the flake. It turns out right now it's only composed of derivations, but I think you can makebenchmarks
a function if you'd like to 🙂 you would just have to apply it inpackages
andchecks
. Currently it doesn't make a big difference though, you've just extruded the function at the top ofmkArtifacts
. I think that's fine too. It's theoretically less flexible (we can't reuse the samemkArtifacts
both with and without benchmark)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what it would have to look like in practice, but it doesn't work:
Seems to be caused by
benchmarks
being a function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, found the issue:
nickel/flake.nix
Line 243 in 68a7ab0
We could solve it but it's starting to drag us away from the original goal of this PR. Sorry for the ping-pong. Let's do as in your previous attempt, and we'll see later about this function stuff. In any case the current flake already applies
mkCraneArtifacts
several times, so this PR doesn't make anything worse in this respect.