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

cmake: setup-hook.sh: add genCmakeDefaultFlags() #335682

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from

Conversation

ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Aug 18, 2024

Description of changes

This PR extracts the default CMake flags pretending code into its own Bash function genCmakeDefaultFlags(). Instead of pretending the flags to cmakeFlags, it collects them into a global Bash array cmakeDefaultFlags.

Original discussions:
#318614 (comment)
#299622 (comment)

Cc: @AndersonTorres @jtojnar @wolfgangwalther

Things done

  • Built on platform(s)
    • x86_64-linux (built cmakeMinimal)
    • 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.

@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch 2 times, most recently from 52ec97d to f118c78 Compare August 18, 2024 22:01
@ShamrockLee
Copy link
Contributor Author

@ofborg build cmake

@ShamrockLee
Copy link
Contributor Author

@ofborg build cmakeMinimal

pkgs/by-name/cm/cmake/setup-hook.sh Outdated Show resolved Hide resolved
pkgs/by-name/cm/cmake/setup-hook.sh Show resolved Hide resolved
Format with `shfmt -i 4 -w pkgs/by-name/cm/cmake/setup-hook.sh`.

Keeping the code auto-formatted makes refactoring easier.
@ShamrockLee
Copy link
Contributor Author

I adjusted the style and changed the order to group all the non-conditional flags.

@wolfgangwalther, what do you think about the current style?

Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

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

The first two commits LGTM. We'll need to assume that the order of flags for cmake doesn't matter, though.

The last commit says:

This enables developers to get the default CMake flags provided by Nixpkgs without having to use cmakeConfigurePhase.

I don't understand the reason for that last commit, yet. Why is that important, what would you do with those flags?

pkgs/by-name/cm/cmake/setup-hook.sh Outdated Show resolved Hide resolved
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Aug 21, 2024

The last commit says:

This enables developers to get the default CMake flags provided by Nixpkgs without having to use cmakeConfigurePhase.

I don't understand the reason for that last commit, yet. Why is that important, what would you do with those flags?

In a build flow where other build tools control CMake, the package developer needs to configure the command-line arguments for CMake without executing CMake itself. A Bash function to provide the flags without running the whole cmakeConfigurePhase might be helpful in such circumstances.

Update: Such use cases are essentially edge cases. I shouldn't emphasize them too much.

Collect the default CMake configure flags collected by
cmakeConfigurePhase into a Bash array named cmakeDefaultFlags.
Extract the code constructing the cmakeDefaultFlags into a Bash function
genCmakeDefaultFlags.
Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

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

First two commits LGTM. Only eye-balled the changes, did not build anything with it.

Last commit I can't say much about the usefulness, but it shouldn't do any harm.

@ShamrockLee
Copy link
Contributor Author

Would it sound more clearly if the function is called setCmakeDefaultFlags?

@wegank wegank added the 12.approvals: 2 This PR was reviewed and approved by two reputable people label Aug 31, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 1, 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 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 12.approvals: 2 This PR was reviewed and approved by two reputable people
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants