[stb] Add option for precompiled image#29686
[stb] Add option for precompiled image#29686benjiwolff wants to merge 2 commits intoconan-io:masterfrom
Conversation
| copy(self, "*.h", src=os.path.join(self.source_folder, "deprecated"), dst=os.path.join(self.package_folder, "include")) | ||
| copy(self, "stb_image.c", src=os.path.join(self.source_folder, "deprecated"), dst=os.path.join(self.package_folder, "include")) | ||
| copy(self, "lib*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib")) | ||
| if not self.options.image: |
There was a problem hiding this comment.
Removing the stb_image.h header is a breaking change I guess. Feel free to drop it.
| def generate(self): | ||
| tc = CMakeToolchain(self) | ||
| if self.options.image: | ||
| tc.variables["STB_IMAGE"] = "ON" |
There was a problem hiding this comment.
I am aware, that we are setting this variable and invoking cmake, just to compile 1 file.. I would prefer doing it without a build system, but I don't think conan offers something like that.
https://docs.conan.io/2/reference/tools.html
There was a problem hiding this comment.
@benjiwolff Hello! 👋
Thank you for addressing issue #8398 and exploring the possibility of incorporating STB as a pre-built library.
However, we cannot accept this Pull Request at this time. The stb project is intentionally designed to be consumed as a header-only library where the user explicitly defines the implementation in a single source file (e.g., #define STB_IMAGE_IMPLEMENTATION). This is the official and supported usage model defined by the upstream author: https://github.com/nothings/stb#how-do-i-use-these-libraries
The current recipe results in a link error by default. Then, you have to read the docs of stb to realize that you have to compile the implementation yourself with a custom #define STB_IMAGE_IMPLEMENTATION
I can understand your initial frustration with a link error when using a “first build” with a package; it not only results in a bad experience for the package manager, but also looks like something is broken. Still, it’s expected for users that are consuming a package, they are familiarized with the project itself; it’s not a reponsability of the package manager adding a custom build features to improve the build steps, instead, it’s recommended discussing with the upstream first, to obtain a not only author’s insights, but to have the change of improving the project for the entire community.
Plus, accepting this PR would diverge from the upstream, resulting in increased maintenance: We would be responsible for maintaining a build system (CMake) that the original author does not provide or support.
The issue was mentioned a while ago in #8398
Well observed with the issue, but we cannot accept this change into the main index, mostly because not only does the upstream not support it, but also other package managers are doing the same: They package only the sources, and the consumer is responsible for building and using the expected compiler definitions. As concrete examples, I can point to these package managers/Linux distros with STB support already:
- Arch Linux: https://archlinux.org/packages/extra/any/stb/
- Nix: https://github.com/NixOS/nixpkgs/blob/release-25.11/pkgs/by-name/st/stb/package.nix
- Vcpkg: https://github.com/microsoft/vcpkg/blob/master/ports/stb/portfile.cmake
- Gentoo: https://www.portagefilelist.de/index.php?p=package&id=2327ef4163941b0e1daa69a6a0379fcb
On the other hand, it does not stop you from distributing this change for STB Conan recipe to other users around GitHub who are using Conan: You can use a few features that may make this possible across your own fork:
- Consumers can use a local recipes index and point your GitHub fork as a new remote: They will be able to consume your changed recipes, not only for STB, but for any other customization around. Initially, it will make only the Conan recipe available, so they can export and build it locally or under a build machine/service.
- Use an Artifactory instance to publish your pre-built packages if operating it in an enterprise. So your teammates can download from a centralized instance, instead of consuming from Conan Center and being dependent of internet connection.
- For small experiments, or even very small teams, you may find Conan Server enough if you want to distribute artifacts, include pre-built packages, but running a small server on your machine, for instance.
This decision is not a blocker for future contributions. Please feel free to comment on #8398 (or open a new issue) to discuss your needs or propose alternative approaches. We welcome future PRs and appreciate your involvement. Regards!
The current recipe results in a link error by default. Then, you have to read the docs of stb to realize, that you have to compile the implementation yourself with a custom
#define STB_IMAGE_IMPLEMENTATION. I want this to be handled by my package manager.The issue was mentioned a while ago in #8398
Considerations:
stb_imageandstb_truetypebe individual options? -> I think yesstb_image.hheader be removed if the option is not set? -> I think yes. Missing headers is a more familiar prompt to check dependency options, than a link error.