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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

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.

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

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

pkgs/development/libraries/imgui/default.nix Show resolved Hide resolved
pkgs/development/libraries/imgui/default.nix Outdated Show resolved Hide resolved
@SomeoneSerge SomeoneSerge changed the title imgui: ship vcpkg' (cmake) distribution info [rebase --autosquash before merging] imgui: ship vcpkg' (cmake) distribution info May 23, 2024
@SomeoneSerge SomeoneSerge marked this pull request as ready for review May 23, 2024 11:36
Comment on lines +18 to +33
# [^1]: https://github.com/microsoft/vcpkg/blob/095ee06e7f60dceef7d713e3f8b1c2eb10d650d7/ports/imgui/CMakeLists.txt#L33-L108
IMGUI_BUILD_ALLEGRO5_BINDING ? false,
IMGUI_BUILD_ANDROID_BINDING ? stdenv.hostPlatform.isAndroid,
IMGUI_BUILD_DX9_BINDING ? false,
IMGUI_BUILD_DX10_BINDING ? false,
IMGUI_BUILD_DX11_BINDING ? false,
IMGUI_BUILD_DX12_BINDING ? false,
IMGUI_BUILD_GLFW_BINDING ? !glfw.meta.unsupported && !libGL.meta.unsupported,
IMGUI_BUILD_GLUT_BINDING ? false,
IMGUI_BUILD_METAL_BINDING ? stdenv.isDarwin,
IMGUI_BUILD_OPENGL2_BINDING ? false,
IMGUI_BUILD_OPENGL3_BINDING ?
IMGUI_BUILD_SDL2_BINDING || IMGUI_BUILD_GLFW_BINDING || IMGUI_BUILD_GLUT_BINDING,
IMGUI_BUILD_OSX_BINDING ? false,
IMGUI_BUILD_SDL2_BINDING ?
!IMGUI_BUILD_GLFW_BINDING && !SDL2.meta.unsupported && !libGL.meta.unsupported,
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 decided to replace lists and maps with the boilerplate. It's stupid and easy to get lost in when editing, but it makes more sense as an interface and mimics vcpkg options exactly. Most of these options currently set broken = true, but the default instantiations like SDL/glfw3 on linux work as expected

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
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.

None yet

5 participants