Browse Source

vendor openssl on android

Jonathan Kelley 6 days ago
parent
commit
5c443d8038
3 changed files with 20 additions and 2 deletions
  1. 1 0
      Cargo.lock
  2. 12 0
      packages/cli/src/build/request.rs
  3. 7 2
      packages/mobile/Cargo.toml

+ 1 - 0
Cargo.lock

@@ -5616,6 +5616,7 @@ dependencies = [
  "dioxus-lib",
  "jni",
  "libc",
+ "openssl",
 ]
 
 [[package]]

+ 12 - 0
packages/cli/src/build/request.rs

@@ -2428,6 +2428,12 @@ impl BuildRequest {
         );
         env_vars.push(("PATH".into(), extended_path));
 
+        // We try to set the OPENLSSL_DIR by autodetecting it here
+        if let Some(openssl_dir) = self.openssl_dir() {
+            tracing::debug!("Setting OPENSSL_DIR to {openssl_dir:?}");
+            env_vars.push(("OPENSSL_DIR".into(), openssl_dir.display().to_string()));
+        }
+
         Ok(env_vars)
     }
 
@@ -4348,4 +4354,10 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
             .flat_map(|arg| ["--config".to_string(), arg])
             .collect()
     }
+
+    fn openssl_dir(&self) -> Option<PathBuf> {
+        // if cfg!(target_os = "macos") {}
+
+        None
+    }
 }

+ 7 - 2
packages/mobile/Cargo.toml

@@ -19,9 +19,14 @@ libc = "0.2.170"
 [target.'cfg(target_os = "android")'.dependencies]
 jni = "0.21.1"
 
+# The `openssl` dependency generally does not know how to cross-compile for Android. To make the lives
+# of our users easier, we automatically enable the `openssl` feature when building for Android.
+# Feature are additive, so users will need to "subtract" this feature if they do not want it.
+openssl = { version = "0.10", features = ["vendored"], optional = true }
+
 [features]
-default = ["jnibindings", "tokio_runtime", "devtools"]
-jnibindings = []
+default = ["tokio_runtime", "devtools", "android-vendored-ssl"]
+android-vendored-ssl = ["openssl"]
 tokio_runtime = ["dioxus-desktop/tokio_runtime"]
 fullscreen = ["dioxus-desktop/fullscreen"]
 transparent = ["dioxus-desktop/transparent"]