Library with optional C depdency

Hi,
Any recommendations for how best to write the build.zig for a library to support an optional C library? Specifically, I want to optionally support openssl. I think it’s best to leave it up to the application which is using my library to decide if and how to link openssl. I’m not sure how I would then detect, in my library, whether openssl is available or not.

Hi @karlseguin

You can use a lazy dependency to fetch openssl when a build option is set.

  • std.Build.lazyDependency

    When this function is called, it means that the current build does, in fact, require this dependency.

  • build.zig.zon lazy dependencies

    When lazy is set to true, a package is declared to be lazily fetched. This makes the dependency only get fetched if it is actually used.