Skip to content

[stb] Add option for precompiled image#29686

Open
benjiwolff wants to merge 2 commits intoconan-io:masterfrom
benjiwolff:add-precompiled-image-option-to-stb
Open

[stb] Add option for precompiled image#29686
benjiwolff wants to merge 2 commits intoconan-io:masterfrom
benjiwolff:add-precompiled-image-option-to-stb

Conversation

@benjiwolff
Copy link
Contributor

@benjiwolff benjiwolff commented Mar 1, 2026

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:

  • Should the various pieces like stb_image and stb_truetype be individual options? -> I think yes
  • Should everything be included by default? -> I think no
  • Should the individual stb_image.h header 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.

@benjiwolff benjiwolff changed the title Add precompiled image option to stb [stb] Add option for precompiled image Mar 1, 2026
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:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the stb_image.h header is a breaking change I guess. Feel free to drop it.

@benjiwolff benjiwolff marked this pull request as ready for review March 1, 2026 15:00
def generate(self):
tc = CMakeToolchain(self)
if self.options.image:
tc.variables["STB_IMAGE"] = "ON"
Copy link
Contributor Author

@benjiwolff benjiwolff Mar 1, 2026

Choose a reason for hiding this comment

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

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

@uilianries uilianries self-assigned this Mar 2, 2026
Copy link
Member

@uilianries uilianries left a comment

Choose a reason for hiding this comment

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

@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:


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!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants