diff --git a/Cargo.toml b/Cargo.toml index 5003470..b402be5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,14 @@ keywords = ["utf8", "unicode", "string", "validation", "simd"] categories = ["encoding", "algorithms", "no-std", "text-processing"] readme = "README.md" rust-version = "1.78.0" +links = "simdutf" [package.metadata.docs.rs] rustdoc-args = ["--cfg", "docsrs"] [features] -default = ["detect_encoding", "ascii", "latin1", "utf8", "utf16", "utf32", "base64"] +default = ["bundled", "detect_encoding", "ascii", "latin1", "utf8", "utf16", "utf32", "base64"] +bundled = [] detect_encoding = [] ascii = [] latin1 = [] diff --git a/build.rs b/build.rs index 1b17ca4..11357f3 100644 --- a/build.rs +++ b/build.rs @@ -29,5 +29,20 @@ fn main() { feature_define(&mut cc, "UTF32", "SIMDUTF_FEATURE_UTF32"); feature_define(&mut cc, "BASE64", "SIMDUTF_FEATURE_BASE64"); + println!("cargo:rerun-if-env-changed=SIMDUTF_LIB_DIR"); + println!("cargo:rerun-if-env-changed=SIMDUTF_LIB_NAME"); + if cfg!(feature = "bundled") { + cc.define("SIMDUTFRS_BUNDLED", None); + } else { + if let Some(dir) = std::env::var_os("SIMDUTF_LIB_DIR") { + println!("cargo:rustc-link-search=native={}", std::path::Path::new(&dir).display()); + } + if let Ok(name) = std::env::var("SIMDUTF_LIB_NAME") { + if !name.is_empty() { + println!("cargo:rustc-link-lib={name}"); + } + } + } + cc.file("cpp/simdutfrs.cpp").compile("simdutfrs"); } diff --git a/codegen/src/bindings.rs b/codegen/src/bindings.rs index eb8af9c..ae5cef0 100644 --- a/codegen/src/bindings.rs +++ b/codegen/src/bindings.rs @@ -36,7 +36,11 @@ fn decl_cpp_endif2(from: &str, to: &str) { pub fn codegen_cpp() { glines![ "// Auto generated by codegen/src/bindings.rs" + "#ifdef SIMDUTFRS_BUNDLED" "#include \"simdutf.cpp\"" + "#else" + "#include \"simdutf.h\"" + "#endif" "#include \"simdutfrs_extra.cpp\"" "" "extern \"C\" {" diff --git a/cpp/simdutfrs.cpp b/cpp/simdutfrs.cpp index 8ee3af0..ad8b9d9 100644 --- a/cpp/simdutfrs.cpp +++ b/cpp/simdutfrs.cpp @@ -1,5 +1,9 @@ // Auto generated by codegen/src/bindings.rs +#ifdef SIMDUTFRS_BUNDLED #include "simdutf.cpp" +#else +#include "simdutf.h" +#endif #include "simdutfrs_extra.cpp" extern "C" {