Specifying dependency features at compile time

Is it possible to specify a dependency's features, based on my app or lib's features?

As an example, let's say I have a Cargo.toml that has some dependencies like this:

version = "0.3.22"
features = [

But now I want to specify whether it's going to be webgl 1 or 2 at compile time (not runtime), and based on that only enable the appropriate feature in the dependency (e.g. either WebGlRenderingContext or WebGl2RenderingContext, not both). So I add some features that can be specified via passing --features:

webgl_1 = []
webgl_2 = []

Is it now possible to somehow populate dependencies.web-sys features, based on my library's features?

webgl_1 = ["web-sys/WebGlRenderingContext"]
1 Like

For more, the section of the docs you want is The Features Section from the Cargo Manifest Format docs. Look to the fourth paragraph of comments in the example.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.