alexcrichton / openssl-src-rs

Source code and logic to build OpenSSL from source
Apache License 2.0
68 stars 113 forks source link

Can I somehow point other sys crates (during compile time) to the libs build by this crate? #70

Closed svanharmelen closed 3 years ago

svanharmelen commented 4 years ago

I have a project that needs to be cross compiled which has two deps that both require SSL. So I added:

native-tls = { version = "0.2", features = ["vendored"] }

to my own project to make sure SSL is compiled and linked statically. But one of the deps is itself also a sys create that requires OPENSSL_ROOT_DIR to be set when it's compiling (for which it is using the cmake crate), so I was searching for a way to dynamically set that to the directory used by this crate to reuse the compiled artifacts.

I can make a PR to the sys package the update or change it's behaviour, but I fail to understand how (and if) I can find the value I need and how (and again if) I can provide that dynamically. Thanks!

sfackler commented 4 years ago

You would need to update that other crate to optionally depend on openssl-src. Once it does that, it can pick up the install path and set OPENSSL_ROOT_DIR properly for cmake in its build script.

svanharmelen commented 4 years ago

Wow, that is a fast response! Thanks for the hint, I'm going to test/try if I can make it work that way. Thanks!

svanharmelen commented 4 years ago

I'm trying this now, but I cannot get it to work. I first tried to add openssl-sys = { version = "0.9.58", optional = true } and then openssl-src = { version = "111.0.1", optional = true }, but both don't seem to give me any env vars I can use.

The first one should expose something like DEP_OPENSSL_ROOT according to this line. But is I write out all env vars in the build script of the sys crate, it doesn't show any DEP_XXX vars. The same when adding openssl-src directly.

I'm probably doing something wrong, but I don't know what...

svanharmelen commented 4 years ago

I moved the dependency from the build-dependencies to the dependencies and that seems to have fixed it! I did also notice that when the dependency is set to optional = true and the other dep that requires SSL is not yet compiled, it returns an error when trying to get the env var. Is that expected behavior or can I fix that? Thanks!

svanharmelen commented 3 years ago

Closing this as it "working" for me now 👍🏻