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

imgui: ship vcpkg' (cmake) distribution info #303682

Merged
merged 11 commits into from
May 29, 2024

Conversation

SomeoneSerge
Copy link
Contributor

@SomeoneSerge SomeoneSerge commented Apr 12, 2024

Description of changes

"Dear ImGui" is one instance of a project where upstream chooses to only distribute sources and headers without any metadata related to building or packaging (cmake "modules", pkg-config, ...). In practice, building and managing the dependencies of imgui, or including imgui in projects built by common build tools (cmake, meson, ...) are not trivial. One way to consume it, besides vendoring, is via the cmake rules maintained in a centralized repository like vcpkg (conan, ...). Presumably, it's even a quite common method.

A wider adoption of the vcpkg-like approach by upstream projects would be ideal for Nixpkgs purposes: it establishes a common interface and a dependency injection mechanism that help creating consistent package sets, fix points, modeling dependencies as independent derivations, etc. This common interface is in fact pure cmake and vcpkg-agnostic. Possibly worth a mention that vcpkg is licensed under MIT.

I suggest we try out the practice of distributing vcpkg' packaging info in situations where upstream doesn't provide any.

In this PR I adapt imgui and related packages to reuse vcpkg' CMakeLists.txt instead of custom phases.

Affected packages:

  • glfw3
  • imgui
    • implot
    • imnodes

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.05 Release Notes (or backporting 23.05 and 23.11 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.

@SomeoneSerge SomeoneSerge force-pushed the feat/imgui-cmake branch 4 times, most recently from 4ac25c6 to 0cbacb0 Compare April 13, 2024 07:30
@SomeoneSerge SomeoneSerge marked this pull request as ready for review April 13, 2024 07:55
@SomeoneSerge SomeoneSerge changed the title imgui: ship vcpkg' cmake packages imgui: ship vcpkg' (cmake) distribution info Apr 16, 2024
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/3795

nixos/doc/manual/release-notes/rl-2405.section.md Outdated Show resolved Hide resolved
pkgs/by-name/im/implot/demos/default.nix Outdated Show resolved Hide resolved
pkgs/by-name/im/imnodes/package.nix Show resolved Hide resolved
pkgs/by-name/im/implot/demos/default.nix Show resolved Hide resolved
pkgs/by-name/im/implot/demos/default.nix Outdated Show resolved Hide resolved
Comment on lines +22 to +24
cmakeRules = "${vcpkg.src}/ports/implot";
postPatch = ''
cp "$cmakeRules"/CMakeLists.txt ./
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cmakeRules = "${vcpkg.src}/ports/implot";
postPatch = ''
cp "$cmakeRules"/CMakeLists.txt ./
postPatch = ''
cp "${vcpkg.src}/ports/implot"/CMakeLists.txt ./

or is this used as an env?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so as to keep phases agnostic of the hashes. I see no good reason to render the hashes into the scripts

Copy link
Member

Choose a reason for hiding this comment

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

I can't follow you.

Usually turning nix variables into bash variables is an anti pattern we try to avoid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introducing the auxiliary variable like this gives the opportunity to implot.overrideAttrs (_: { cmakeRules = ./my-custom-cmake; }) which otherwise would require a careful surgery on the postPatch. I've been following a similar pattern outside the tree and thought it wouldn't do harm to do the same here.

an anti pattern we try to avoid.

Yesssss setup-hooks are an anti-pattern, let's make nix evaluation faster and abolish setup hooks 😆

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use finalAttrs to allow overrides like that, too.

Copy link
Contributor Author

@SomeoneSerge SomeoneSerge May 23, 2024

Choose a reason for hiding this comment

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

That's an option, but it's not really any better than eliminating the template rendering and treating postPatch as a normal setup hook

EDIT: Note also, this would still require the auxiliary variable

pkgs/development/libraries/imgui/default.nix Show resolved Hide resolved
pkgs/development/libraries/imgui/default.nix Outdated Show resolved Hide resolved
Comment on lines +43 to +47
# CMake: link libGL from the "app" target
(fetchpatch {
url = "https://github.com/epezent/implot_demos/commit/6742e4202858eb85bd0d67ca5fa15a7a07e6b618.patch";
hash = "sha256-h4EJ9u1iHLYkGHgxSynskkuCGmY6mmvKdZSRwHJKerY=";
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

vcpkg' CMakeLists.txt for imgui doesn't target_link_libraries(... OpenGL::GL). I wasn't sure if it should, so for now I made the demo link libGL explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SuperSandro2000 any concerns other than hooks-vs-finalAttrs? More generally, do you have any opinion on the decision to adopt 3rd party (vcpkg) distribution information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to merge tomorrow unless there are objections.

@SuperSandro2000 we haven't reached the agreement on the finalAttrs matter but we can keep the question open and if we end up choosing against bash variables I'll just open a follow-up PR

@SomeoneSerge SomeoneSerge changed the title [rebase --autosquash before merging] imgui: ship vcpkg' (cmake) distribution info imgui: ship vcpkg' (cmake) distribution info May 24, 2024
@SomeoneSerge SomeoneSerge force-pushed the feat/imgui-cmake branch 2 times, most recently from 3baa154 to 8b68642 Compare May 27, 2024 15:13
Glfw may dlopen libwayland-client.so.
This was observed when testing .#imgui.tests.demo
@SomeoneSerge SomeoneSerge force-pushed the feat/imgui-cmake branch 3 times, most recently from 7298046 to c74ce24 Compare May 28, 2024 19:57
@SomeoneSerge
Copy link
Contributor Author

Well if there should be any objections they can be resolved in future PRs.

RE: Ofborg

  • Aarch64-linux builds fine locally (can't post a nixpkgs-review because my aarch64 builder doesn't have enough storage for the whole thing 🙈)
  • I can't test Darwin, it's something to follow up on

@SomeoneSerge SomeoneSerge merged commit 7781c1a into NixOS:master May 29, 2024
25 checks passed
@wegank
Copy link
Member

wegank commented May 30, 2024

I can't test Darwin, it's something to follow up on

And I guess this PR does break imgui on darwin....

@SomeoneSerge
Copy link
Contributor Author

And I guess this PR does break imgui on darwin....

Well, "breaks" is maybe an overly strong way to put it, given that previously this derivation didn't actually "build" imgui. As I mentioned in the update, clients that prefer the "add_subdirectory" approach can still use imgui.src.

I'll try to clean this up rn

@wegank
Copy link
Member

wegank commented May 30, 2024

Opened #315917, it's just missing some frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants