build.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #[cfg(windows)]
  2. fn build_windows() {
  3. cc::Build::new().file("src/windows.cc").compile("windows");
  4. println!("cargo:rustc-link-lib=WtsApi32");
  5. println!("cargo:rerun-if-changed=build.rs");
  6. println!("cargo:rerun-if-changed=windows.cc");
  7. }
  8. #[cfg(all(windows, feature = "inline"))]
  9. fn build_manifest() {
  10. use std::io::Write;
  11. if std::env::var("PROFILE").unwrap() == "release" {
  12. let mut res = winres::WindowsResource::new();
  13. res.set_icon("icon.ico")
  14. .set_language(winapi::um::winnt::MAKELANGID(
  15. winapi::um::winnt::LANG_ENGLISH,
  16. winapi::um::winnt::SUBLANG_ENGLISH_US,
  17. ))
  18. .set_manifest_file("manifest.xml");
  19. match res.compile() {
  20. Err(e) => {
  21. write!(std::io::stderr(), "{}", e).unwrap();
  22. std::process::exit(1);
  23. }
  24. Ok(_) => {}
  25. }
  26. }
  27. }
  28. fn install_oboe() {
  29. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
  30. if target_os != "android" {
  31. return;
  32. }
  33. let mut target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
  34. if target_arch == "x86_64" {
  35. target_arch = "x64".to_owned();
  36. } else if target_arch == "aarch64" {
  37. target_arch = "arm64".to_owned();
  38. } else {
  39. target_arch = "arm".to_owned();
  40. }
  41. let target = format!("{}-android-static", target_arch);
  42. let vcpkg_root = std::env::var("VCPKG_ROOT").unwrap();
  43. let mut path: std::path::PathBuf = vcpkg_root.into();
  44. path.push("installed");
  45. path.push(target);
  46. println!(
  47. "{}",
  48. format!(
  49. "cargo:rustc-link-search={}",
  50. path.join("lib").to_str().unwrap()
  51. )
  52. );
  53. println!("cargo:rustc-link-lib=oboe");
  54. println!("cargo:rustc-link-lib=c++");
  55. println!("cargo:rustc-link-lib=OpenSLES");
  56. // I always got some strange link error with oboe, so as workaround, put oboe.cc into oboe src: src/common/AudioStreamBuilder.cpp
  57. // also to avoid libc++_shared not found issue, cp ndk's libc++_shared.so to jniLibs, e.g.
  58. // ./flutter_hbb/android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so
  59. // let include = path.join("include");
  60. //cc::Build::new().file("oboe.cc").include(include).compile("oboe_wrapper");
  61. }
  62. fn main() {
  63. #[cfg(all(windows, feature = "inline"))]
  64. build_manifest();
  65. #[cfg(windows)]
  66. build_windows();
  67. #[cfg(target_os = "macos")]
  68. println!("cargo:rustc-link-lib=framework=ApplicationServices");
  69. hbb_common::gen_version();
  70. install_oboe();
  71. }