Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static OpenSSL option for MacOS and Windows #284

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ default = ["ssl"]
ssl = ["openssl-sys", "openssl-probe", "curl-sys/ssl"] # OpenSSL/system TLS backend
mesalink = ["curl-sys/mesalink"] # MesaLink TLS backend
http2 = ["curl-sys/http2"]
static-curl = ["curl-sys/static-curl"]
static-ssl = ["curl-sys/static-ssl"]
static-curl = ["curl-sys/static-curl"] # Bundle and statically link to curl
static-ssl = ["curl-sys/static-ssl"] # Bundle and statically link to OpenSSL if used
force-system-lib-on-osx = ['curl-sys/force-system-lib-on-osx']
static-openssl = ["curl-sys/static-openssl"] # Bundle and statically link to OpenSSL on all platforms

[[test]]
name = "atexit"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ with various Cargo features:
- `static-curl`: Use a bundled libcurl version and statically link to it. Disabled by default.
- `static-ssl`: Use a bundled OpenSSL version and statically link to it. Only applies on platforms that use OpenSSL. Disabled by default.
- `spnego`: Enable SPNEGO support. Disabled by default.
- `static-openssl`: Use a bundled OpenSSL version and statically link to it. Applies to all platforms. Disabled by default.

## Version Support

Expand Down
7 changes: 4 additions & 3 deletions curl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ libz-sys = "1.0.18"
libc = "0.2.2"
libnghttp2-sys = { optional = true, version = "0.1" }

[target.'cfg(any(all(unix, not(target_os = "macos")), feature = "static-openssl"))'.dependencies]
openssl-sys = { version = "0.9", optional = true }

[dependencies.mesalink]
version = "1.1.0-cratesio"
optional = true
default-features = false
features = ["client_apis", "error_strings", "tls13", "aesgcm", "chachapoly", "x25519", "ecdh", "ecdsa", "verifier"]

[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
openssl-sys = { version = "0.9", optional = true }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winsock2", "ws2def"] }

Expand All @@ -50,3 +50,4 @@ static-curl = []
static-ssl = ["openssl-sys/vendored"]
spnego = []
force-system-lib-on-osx = []
static-openssl = ["openssl-sys/vendored"]
31 changes: 23 additions & 8 deletions curl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,25 @@ fn main() {
}
} else if cfg!(feature = "ssl") {
if windows {
cfg.define("USE_WINDOWS_SSPI", None)
.define("USE_SCHANNEL", None)
.file("curl/lib/x509asn1.c")
.file("curl/lib/curl_sspi.c")
.file("curl/lib/socks_sspi.c")
.file("curl/lib/vtls/schannel.c")
.file("curl/lib/vtls/schannel_verify.c");
} else if target.contains("-apple-") {
if !cfg!(feature = "static-openssl") {
cfg.define("USE_WINDOWS_SSPI", None)
.define("USE_SCHANNEL", None)
.file("curl/lib/x509asn1.c")
.file("curl/lib/curl_sspi.c")
.file("curl/lib/socks_sspi.c")
.file("curl/lib/vtls/schannel.c")
.file("curl/lib/vtls/schannel_verify.c");
} else {
cfg.define("USE_OPENSSL", None)
.file("curl/lib/vtls/openssl.c");

if let Some(path) = env::var_os("DEP_OPENSSL_INCLUDE") {
cfg.include(path);
}
println!("cargo:rustc-link-lib=ssl");
Copy link
Owner

Choose a reason for hiding this comment

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

I think this should be covered by openssl-sys right?

println!("cargo:rustc-link-lib=crypto");
}
} else if target.contains("-apple-") && !cfg!(feature = "static-openssl") {
cfg.define("USE_SECTRANSP", None)
.file("curl/lib/vtls/sectransp.c");
if xcode_major_version().map_or(true, |v| v >= 9) {
Expand Down Expand Up @@ -337,6 +348,10 @@ fn main() {
if target.contains("-apple-") {
println!("cargo:rustc-link-lib=framework=Security");
println!("cargo:rustc-link-lib=framework=CoreFoundation");
if cfg!(feature = "static-openssl") {
println!("cargo:rustc-link-lib=ssl");
println!("cargo:rustc-link-lib=crypto");
}
}
}

Expand Down