build.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. use std::env;
  2. fn main() -> miette::Result<()> {
  3. if cfg!(feature = "bundled") {
  4. // Builds the project in the directory located in `core`, installing it into $OUT_DIR
  5. let mut dst = cmake::Config::new("core")
  6. .define("BUILD_SHARED_LIBS", "OFF")
  7. .define("ZXING_READERS", "ON")
  8. .define("ZXING_WRITERS", "NEW")
  9. .define("ZXING_EXPERIMENTAL_API", "ON")
  10. .define("ZXING_C_API", "ON")
  11. .define("ZXING_USE_BUNDLED_ZINT", "ON")
  12. .define("CMAKE_CXX_STANDARD", "20")
  13. .build();
  14. dst.push("lib");
  15. println!("cargo:rustc-link-search=native={}", dst.display());
  16. println!("cargo:rustc-link-lib=static=ZXing");
  17. if let Ok(target) = env::var("TARGET") {
  18. if target.contains("apple") {
  19. println!("cargo:rustc-link-lib=dylib=c++");
  20. } else if target.contains("linux") {
  21. println!("cargo:rustc-link-lib=dylib=stdc++");
  22. }
  23. }
  24. } else if let Ok(lib_dir) = env::var("ZXING_CPP_LIB_DIR") {
  25. println!("cargo:rustc-link-search=native={}", lib_dir);
  26. println!("cargo:rustc-link-lib=dylib=ZXing");
  27. } else {
  28. // panic!("ZXing library not found. Use feature 'bundled' or set environment variabale ZXING_CPP_LIB_DIR.")
  29. }
  30. // manual bindings.rs generation:
  31. // bindgen core/src/ZXingC.h -o src/bindings.rs --no-prepend-enum-name --merge-extern-blocks --use-core --no-doc-comments --no-layout-tests --with-derive-partialeq --allowlist-item "ZXing.*" -- -DZXING_EXPERIMENTAL_API
  32. Ok(())
  33. }