Skip to content
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

WIP: experiment with a hook based alternative to buildGoModule #353526

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TomaSajt
Copy link
Contributor

@TomaSajt TomaSajt commented Nov 3, 2024

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@TomaSajt TomaSajt marked this pull request as draft November 3, 2024 22:48
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch from 5381b6c to 1c1769a Compare November 3, 2024 22:59
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 labels Nov 4, 2024
Comment on lines +130 to +138
if [ -z "${dontGoBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=goBuildHook
fi


if [ -z "${dontGoCheck-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=goCheckHook
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the motivation of this PR is to increase composability, meaning constructing one call to stdenv.mkDerivation with functionalities provided by more than one build helpers, such as buildGoModule and rustPlatform.buildRustPackage.

Would it be more composable if we also add goBuildHook (with runHook removed, of course) to preBuildHooks or postBuildHooks?

Use case: one package, with its own buildPhase, wants to build some go stuff.

Here is my implementation of this idea for Rust: #334476.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 10, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch 2 times, most recently from cd1a821 to 4d6cb5e Compare November 13, 2024 00:21
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 13, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch from 4d6cb5e to 083a109 Compare November 15, 2024 12:30
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 15, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch from 083a109 to 9273a74 Compare November 26, 2024 15:16
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 27, 2024
@katexochen
Copy link
Contributor

I like the idea of moving to a hook based alternative, but I think it will need some discussion on how exactly such a future builder would look like. Maybe you can make your experiment consumable via an out-of-tree flake for now, so people can evaluate and test it? This is what was done for gomod2nix (which didn't end up in nixpkgs in the end).
Also, notice there is another hook-based experiment in https://github.com/adisbladis/gobuild.nix. :)

fi
exclude+='\)'

buildGoDir() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, Bash doesn't support nested function declaration. Let's flatten the definition of these Bash functions.

@@ -0,0 +1,140 @@

goBuildHook() {
Copy link
Contributor

@ShamrockLee ShamrockLee Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
goBuildHook() {
goBuildPhase() {

AFAICT, fooBarHook is meant to be run when doing runHook foo.

Also, I would propose also defining goBuild, which runs all the goBuildPhase commands except runHook preBuild and runHook postBuild. This way, goBuild could be inserted into the pre- and post-phases of other build helpers/workflows. For example, apptainer uses the stdenv.mkDerivation's Make-based workflow during configuration and build but still requires the Go modules realization from goConfigurePhase. If we have goConfigure, we could plug it into preConfigure and switch on dontGoConfigure and dontGoBuild.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: golang 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 11.by: package-maintainer This PR was created by the maintainer of the package it changes
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

5 participants