diff --git a/Cargo.toml b/Cargo.toml index ddac5a0b26..c037d22347 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index 4c442e5104..a30bc9a62d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/curl-sys/Cargo.toml b/curl-sys/Cargo.toml index 3b8247ce54..97551d74d8 100644 --- a/curl-sys/Cargo.toml +++ b/curl-sys/Cargo.toml @@ -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"] } @@ -50,3 +50,4 @@ static-curl = [] static-ssl = ["openssl-sys/vendored"] spnego = [] force-system-lib-on-osx = [] +static-openssl = ["openssl-sys/vendored"] diff --git a/curl-sys/build.rs b/curl-sys/build.rs index 59c23b0c09..4de46c6469 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -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"); + 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) { @@ -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"); + } } }