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

Add option to link SSL libs statically #72

Closed
berndv opened this issue May 12, 2020 · 3 comments
Closed

Add option to link SSL libs statically #72

berndv opened this issue May 12, 2020 · 3 comments
Milestone

Comments

@berndv
Copy link

berndv commented May 12, 2020

Currently it is not possible to link SSL libs on or for Linux systems statically.

Please add configuration option to enable static linking.

Proposal (based on tag 0.7.1):

diff --git a/paho-mqtt-sys/build.rs b/paho-mqtt-sys/build.rs
index 9c4a942..8af5dce 100644
--- a/paho-mqtt-sys/build.rs
+++ b/paho-mqtt-sys/build.rs
@@ -175,6 +175,7 @@
     use std::path::Path;
     use std::process::Command;
     use std::env;
+    use std::str::FromStr;
 
     pub fn main() {
         println!("debug:Running the bundled build for Paho C");
@@ -250,9 +251,19 @@
 
         // Link in the SSL libraries if configured for it.
         if cfg!(feature = "ssl") {
+            let ssl_link_static = match env::var("OPENSSL_LINK_STATIC") {
+                Ok(value) => bool::from_str(value.as_str()).unwrap(),
+                Err(_) => cfg!(windows),
+            };
+
+            let ssl_link_kind = match ssl_link_static {
+                true => "static",
+                false => "dylib",
+            };
+
             if cfg!(windows) {
-                println!("cargo:rustc-link-lib=libssl");
-                println!("cargo:rustc-link-lib=libcrypto");
+                println!("cargo:rustc-link-lib={}=libssl", ssl_link_kind);
+                println!("cargo:rustc-link-lib={}=libcrypto", ssl_link_kind);
                 if let Ok(ssl_sp) = env::var("OPENSSL_ROOT_DIR") {
                     println!("cargo:rustc-link-search={}\\lib", ssl_sp);
                 }
@@ -265,8 +276,8 @@
                 };
             }
             else {
-                println!("cargo:rustc-link-lib=ssl");
-                println!("cargo:rustc-link-lib=crypto");
+                println!("cargo:rustc-link-lib={}=ssl", ssl_link_kind);
+                println!("cargo:rustc-link-lib={}=crypto", ssl_link_kind);
                 if let Ok(ssl_sp) = env::var("OPENSSL_ROOT_DIR") {
                     println!("cargo:rustc-link-search={}/lib", ssl_sp);
                 }
@@ -340,4 +351,3 @@
         bindings::place_bindings(&Path::new(&inc_dir));
     }
 }
-
@fpagliughi
Copy link
Contributor

Thanks! Could you submit this as a Pull Request?

berndv pushed a commit to sourcepit/paho.mqtt.rust that referenced this issue May 12, 2020
@ryankurte
Copy link
Contributor

would it perhaps be useful to farm out the openssl building/linking to openssl-sys? this already basically works with the usual OPENSSL_STATIC / OPENSSL_DIR args (though at this time you have to add openssl-sys to your crate to aid this resolution)

@fpagliughi
Copy link
Contributor

OK. PR #92 added the openssl-sys to the build which should now allow static linking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants