Skip to content

Commit

Permalink
feat: ios support
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvictor committed Aug 29, 2024
1 parent db1ff12 commit f26fe95
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyrsolace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ crossbeam-channel = "0.5.13"
# once_cell = "1.19.0"
pyo3 = { version = "0.19.1", features = ["extension-module", "chrono", "abi3-py37"] }
# rayon = "1.10.0"
rsolace = { version = "0.1.8", path = "../rsolace" }
rsolace = { version = "0.2.0", path = "../rsolace" }
tracing = "0.1"
tracing-subscriber = "0.3"
2 changes: 1 addition & 1 deletion rsolace-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rsolace-sys"
version = "0.1.8"
version = "0.2.0"
edition = "2021"
description = "Solace binding generated by bindgen"
keywords = ["solace"]
Expand Down
84 changes: 75 additions & 9 deletions rsolace-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate bindgen;
// use std::env;
use std::process::Command;
use std::{io::Write, path::PathBuf};
// use bindgen::CargoCallbacks;

Expand All @@ -9,6 +10,9 @@ const SOLCLIENT_GZ_PATH: &str = "solclient_Win_vs2015_7.25.0.10.tar.gz";
#[cfg(target_os = "macos")]
const SOLCLIENT_GZ_PATH: &str = "solclient_Darwin-universal2_opt_7.25.0.10.tar.gz";

#[cfg(target_os = "ios")]
const SOLCLIENT_GZ_PATH: &str = "solclient_ios_opt_7.25.0.10.tar.gz";

#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
const SOLCLIENT_GZ_PATH: &str = "solclient_Linux26-x86_64_opt_7.25.0.10.tar.gz";

Expand All @@ -18,13 +22,58 @@ const SOLCLIENT_GZ_PATH: &str = "solclient_Linux-aarch64_opt_7.25.0.10_withssl.t
#[cfg(all(target_os = "linux", target_arch = "x86_64", target_env = "musl"))]
const SOLCLIENT_GZ_PATH: &str = "solclient_Linux_musl-x86_64_opt_7.25.0.10.tar.gz";

fn lipo_arch_lib(solclient_folder_name: &str, arch: &str, lib_name: &str) {
let lib_path = format!("{}/lib/lib{}.a", solclient_folder_name, lib_name);
let lib_path_exist = std::path::Path::new(&lib_path).exists();
let source_lib_path = if lib_path_exist {
lib_path
} else {
format!(
"rsolace-sys/{}/lib/lib{}.a",
solclient_folder_name, lib_name
)
};
let arch_lib_path = if lib_path_exist {
format!("{}/lib/lib{}-{}.a", solclient_folder_name, lib_name, arch)
} else {
format!(
"rsolace-sys/{}/lib/lib{}-{}.a",
solclient_folder_name, lib_name, arch
)
};

Command::new("lipo")
.arg(source_lib_path)
.arg("-thin")
.arg(arch)
.arg("-output")
.arg(arch_lib_path)
.spawn()
.expect(&format!("lipo {} error", lib_name));
}

fn main() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
println!("target_os: {} | target_arch: {}", target_os, target_arch);
let solclient_gz_path = if target_os == "ios" {
"solclient_ios_opt_7.25.0.10.tar.gz"
} else {
SOLCLIENT_GZ_PATH
};
let solclient_folder_name = "../solclient-7.25.0.10";
let solclient_folder_path = std::path::Path::new(solclient_folder_name);
let solclient_gz_url =
format!("https://github.com/Yvictor/rsolace/releases/download/0.0.0/{SOLCLIENT_GZ_PATH}");
let resp = reqwest::blocking::get(solclient_gz_url).unwrap();
format!("https://github.com/Yvictor/rsolace/releases/download/0.0.0/{solclient_gz_path}");
println!("{}", solclient_gz_url);
let client = reqwest::blocking::Client::builder()
.timeout(std::time::Duration::from_secs(60 * 5))
.build()
.unwrap();
let resp = client.get(solclient_gz_url).send().unwrap();
// let resp = reqwest::blocking::get(solclient_gz_url).unwrap();
let content = resp.bytes().unwrap();
println!("content size: {}", content.len());
let file_gz_name = format!("{solclient_folder_name}.tar.gz");
let file_gz_path = std::path::Path::new(&file_gz_name);
if !file_gz_path.exists() {
Expand Down Expand Up @@ -58,11 +107,11 @@ fn main() {
// );
// // println!("cargo:rustc-link-search=native=rsolace-sys/solclient-7.25.0.10/lib");
// // println!("cargo:rustc-link-search=solclient-7.25.0.10/include/solclient");
let os = std::env::consts::OS;
if os == "macos" {
// let os = std::env::consts::OS;
if target_os == "macos" {
println!("cargo:rustc-link-lib=dylib=gssapi_krb5");
}
if os == "windows" {
if target_os == "windows" {
let arch_folder = if std::env::var("Platform").unwrap_or("x64".into()) == "x64" {
"Win64"
} else {
Expand All @@ -83,10 +132,27 @@ fn main() {
println!("cargo:rustc-link-lib=static=libsolclient_s");
// println!("cargo:rustc-link-lib=static=libsolclient");
} else {
println!("cargo:rustc-link-lib=static=ssl");
println!("cargo:rustc-link-lib=static=crypto");
println!("cargo:rustc-link-lib=static=solclient");
println!("cargo:rustc-link-lib=static=solclientssl");
if target_os == "ios" {
let arch = if target_arch == "aarch64" {
"arm64"
} else if target_arch == "x86_64" {
"x86_64"
} else {
"armv7s"
};
// let arch = "arm64";
lipo_arch_lib(solclient_folder_name, arch, "ssl-universal");
lipo_arch_lib(solclient_folder_name, arch, "crypto-universal");
lipo_arch_lib(solclient_folder_name, arch, "solclient");
println!("cargo:rustc-link-lib=static=ssl-universal-{arch}");
println!("cargo:rustc-link-lib=static=crypto-universal-{arch}");
println!("cargo:rustc-link-lib=static=solclient-{arch}");
} else {
println!("cargo:rustc-link-lib=static=ssl");
println!("cargo:rustc-link-lib=static=crypto");
println!("cargo:rustc-link-lib=static=solclient");
println!("cargo:rustc-link-lib=static=solclientssl");
}
}
let include_path = solclient_folder_path.join("include");
let include_arg = format!("-I{}", include_path.to_str().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions rsolace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rsolace"
version = "0.1.9"
version = "0.2.0"
edition = "2021"
description = "Solace bindings for the Rust"
keywords = ["solace"]
Expand All @@ -16,7 +16,7 @@ crossbeam-channel = { version = "0.5.8", optional = true}
dashmap = "5.4.0"
enum_primitive = "0.1.1"
failure = "0.1.8"
rsolace-sys = { version = "0.1.8", path = "../rsolace-sys" }
rsolace-sys = { version = "0.2.0", path = "../rsolace-sys" }
snafu = { version = "0.7.4", features = ["rust_1_46"]}
tokio = { version = "1.28.2", optional = true}
tracing = "0.1"
Expand Down

0 comments on commit f26fe95

Please sign in to comment.