diff --git a/Cargo.lock b/Cargo.lock index f9d595f..48b474f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,8 +140,9 @@ checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" [[package]] name = "ceresdb-client-py" -version = "0.1.0" +version = "0.1.1" dependencies = [ + "cc", "ceresdb-client-rs", "pyo3", "pyo3-asyncio", @@ -213,8 +214,7 @@ dependencies = [ [[package]] name = "cmake" version = "0.1.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +source = "git+https://github.com/messense/cmake-rs.git?branch=cross-compile#15ab68baca7c44bcf23c5d91a4201f10d40552a1" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index f653d48..e43d410 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,9 @@ rev = "d71ac1f024f6204d86d445cd1bcddf170116b9bf" [lib] crate-type = ["cdylib"] name = "ceresdb_client" + +[patch.crates-io] +cmake = { git = "https://github.com/messense/cmake-rs.git", branch = "cross-compile" } + +[build-dependencies] +cc = "1.0.73" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..e1ca9f1 --- /dev/null +++ b/build.rs @@ -0,0 +1,44 @@ +// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. +use std::env; + +fn main() { + let target = env::var("TARGET").unwrap(); + if target.contains("apple") { + // On (older) OSX we need to link against the clang runtime, + // which is hidden in some non-default path. + // + // More details at https://github.com/alexcrichton/curl-rust/issues/279. + if let Some(path) = macos_link_search_path() { + println!("cargo:rustc-link-lib=clang_rt.osx"); + println!("cargo:rustc-link-search={}", path); + } + } +} + +fn macos_link_search_path() -> Option { + let output = cc::Build::new() + .get_compiler() + .to_command() + .arg("--print-search-dirs") + .output() + .ok()?; + if !output.status.success() { + println!( + "failed to run 'clang --print-search-dirs', continuing without a link search path" + ); + return None; + } + + let stdout = String::from_utf8_lossy(&output.stdout); + for line in stdout.lines() { + if line.contains("libraries: =") { + let path = line.split('=').nth(1)?; + if !path.is_empty() { + return Some(format!("{}/lib/darwin", path)); + } + } + } + + println!("failed to determine link search path, continuing without it"); + None +}