-
-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
buildGoModule: find build/test targets with go list
#284568
base: staging
Are you sure you want to change the base?
Conversation
I like the idea, it should speed up Go builds. Thank you! |
Signed-off-by: Paul Meyer <[email protected]>
Most packages should specify subPackages instead of excludedPackages, as it makes the build more precise and is clearer in general.
df5e213
to
d930472
Compare
Signed-off-by: Paul Meyer <[email protected]>
d930472
to
d1a7158
Compare
I've implemented One point I thought about is whether we should move most of the functions we define in the builder into the configure flag. Currently, the |
You mean configurePhase? I think it might be preferable to put this into a setup hook and add this via Also, @Mic92 has brought up the valid concern about too long argument lists which I agree with. I think testing whether this would happen with e.g. kubernetes is a good indication on whether we need to take care of that or not. See also my suggestion about how to do that in #285362 (comment). When these two things are done - I'm happy to assist if needed - I'm happy to help finding and fixing regressions, this is a very nice change that I'd really love to see in 24.05. [1] Sure, there's still the topic on how to get dependencies then, but it's still a step forward. |
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568.
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
FWIW given what I've learned in #292997 I'm wondering if there's any case where you actually want |
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568.
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
@Ma27 Thanks for your feedback, and sorry for reaching back late.
I won't/didn't find much time for working on nixpkgs this month as I'm moving. Also, the breakage that his PR causes is quite huge. I thought I could handle this with some support, but I didn't even to get my previous PRs on the builder merged that had far less impact, so I'm not that optimistic anymore. I don't think there is much chance to get it into 24.05, and I'm not even sure I'll continue work on this at all.
I had similar thoughts while working on this PR. I'd love to work on a design for a build hook or buildGoModule2, but I'd likely draft that out of tree. If you'd like to collaborate on that let me know. |
No worries! I don't really mind if this will be delayed to 24.11 (or even 25.05 though I don't hope it'll take that long) as long as the situation improves eventually.
Is that a prerequisite for this? Would you mind linking to it? I've not been too involved with Go stuff, but after being diving into how our current builder works (after being too often too annoyed by how long Grafana used to take for a build), I'm rather interested in getting these improvements out. My next todo for this will be to take a closer look what we're doing here. Is there anything important (short of fixing the fallout) do be done? Otherwise we might want to request a Hydra jobset so we can compare against staging-next which packages regressed
I'd certainly be interested. |
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
checkFlags = | ||
let | ||
skippedTests = [ | ||
# Tests panic for unknown reason. | ||
"TestPostWorkflowHookRunner_Run" | ||
"TestPreWorkflowHookRunner_Run" | ||
"TestNewServer" | ||
"TestCommandRunnerVCSClientInitialized" | ||
# Tests require Terraform, which is unfree. | ||
"TestGitHubWorkflow" | ||
"TestSimpleWorkflow_terraformLockFile" | ||
"TestGitHubWorkflowWithPolicyCheck" | ||
"TestDefaultProjectCommandBuilder_TerraformVersion" | ||
]; | ||
in | ||
[ "-skip=^${lib.concatStringsSep "$|^" skippedTests}$" ]; |
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.
We should probably add something like skipTestNames or so to automatically populate this like pytestCheckHook is doing
lib.warnIf (buildFlags != "" || buildFlagsArray != "") | ||
lib.warnIf | ||
(buildFlags != "" || buildFlagsArray != "") | ||
"Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" | ||
lib.warnIf (builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule" | ||
lib.warnIf | ||
(builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule" | ||
package |
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.
Please undo the formatting, to have less noise
go list \ | ||
-f '{{ .Dir }}' \ | ||
"''${flags[@]}" \ | ||
"''${subPkgs[@]}" | \ |
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.
Can we fallback this to ./... to avoid the duplication?
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
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.
I tested those changes in some Go packages (downstream in flakes and the ones I maintain in nixpkgs). It should speed up builds / tests and I think this should be implemented (after being rebased).
The build itself is pretty quick now: buildPhase completed in 2 minutes 46 seconds in contrast to buildPhase completed in 5 minutes 22 seconds before on the same machine (Hetzner AX41 NVMe with AMD Ryzen 5 3600 6-Core Processor and 64GiB RAM). Downside of that is that no tests are now executed, but I'm inclined to make that sacrifice for now. Especially considering that a fix for that is on the horizon with NixOS#284568. (cherry picked from commit f220ea4)
Description of problem
buildGoModule
uses the internalgetGoDirs
function to find targets to build/test:nixpkgs/pkgs/build-support/go/module.nix
Lines 224 to 232 in b914a99
No/not all relevant tests executed when
subPackage
is setIf the
subPackages
attribute is set, we will callgo test
on the specified subpackages.This problematic as a common pattern in Go is to place the
main
packages of binaries in acmd
directory, often without test files. The most common pattern to test Go could is likely executinggo test ./...
in the module root directory to recursively tests all packages of the module. When we only test themain
packages, we are likely missing many relevant tests for that binary.Using
find
to find targets for Go does not respect Go conventionsWhen using
find
to discover packages to build, Go conventions will be ignored. Most Go commands will stop to recurse into submodules, and the dependency derivation will only contain the dependencies of the main module.As a result, such packages must currently be explicitly excluded. In the following example,
vendored/toml
is a submodule:nixpkgs/pkgs/by-name/gl/glauth/package.nix
Lines 31 to 33 in 26f8f97
Test performance
Right now we test each package in separate as we invoke the
go test
command for each package. This is slow and really bad for build time in cases where there are many packages but each package has only a few or no fast tests. While packages from different tests can run in parallel, tests within a package are executed sequentially by default. When we pass all the packages to the go command and just invoke it once, Go has the chance to parallelize test execution.Description of changes
go list
to discover packages, both for builds and tests.go list
expression to identify the packages that our built targets actually depend on. This is an optimization over running tests for the full module which will save us some time when building a binary with only some local dependencies in a bigger Go module.Open TODOs
excludedPackages
go list
excludedPackage
tosubPackages
(followup PR) and document thatsubPackages
is preferedThings done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.