build.rs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #[cfg(windows)]
  2. fn build_windows() {
  3. let file = "src/platform/windows.cc";
  4. let file2 = "src/platform/windows_delete_test_cert.cc";
  5. cc::Build::new().file(file).file(file2).compile("windows");
  6. println!("cargo:rustc-link-lib=WtsApi32");
  7. println!("cargo:rerun-if-changed={}", file);
  8. println!("cargo:rerun-if-changed={}", file2);
  9. }
  10. #[cfg(target_os = "macos")]
  11. fn build_mac() {
  12. let file = "src/platform/macos.mm";
  13. let mut b = cc::Build::new();
  14. if let Ok(os_version::OsVersion::MacOS(v)) = os_version::detect() {
  15. let v = v.version;
  16. if v.contains("10.14") {
  17. b.flag("-DNO_InputMonitoringAuthStatus=1");
  18. }
  19. }
  20. b.file(file).compile("macos");
  21. println!("cargo:rerun-if-changed={}", file);
  22. }
  23. #[cfg(all(windows, feature = "inline"))]
  24. fn build_manifest() {
  25. use std::io::Write;
  26. if std::env::var("PROFILE").unwrap() == "release" {
  27. let mut res = winres::WindowsResource::new();
  28. res.set_icon("res/icon.ico")
  29. .set_language(winapi::um::winnt::MAKELANGID(
  30. winapi::um::winnt::LANG_ENGLISH,
  31. winapi::um::winnt::SUBLANG_ENGLISH_US,
  32. ))
  33. .set_manifest_file("res/manifest.xml");
  34. match res.compile() {
  35. Err(e) => {
  36. write!(std::io::stderr(), "{}", e).unwrap();
  37. std::process::exit(1);
  38. }
  39. Ok(_) => {}
  40. }
  41. }
  42. }
  43. fn install_android_deps() {
  44. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
  45. if target_os != "android" {
  46. return;
  47. }
  48. let mut target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
  49. if target_arch == "x86_64" {
  50. target_arch = "x64".to_owned();
  51. } else if target_arch == "x86" {
  52. target_arch = "x86".to_owned();
  53. } else if target_arch == "aarch64" {
  54. target_arch = "arm64".to_owned();
  55. } else {
  56. target_arch = "arm".to_owned();
  57. }
  58. let target = format!("{}-android", target_arch);
  59. let vcpkg_root = std::env::var("VCPKG_ROOT").unwrap();
  60. let mut path: std::path::PathBuf = vcpkg_root.into();
  61. path.push("installed");
  62. path.push(target);
  63. println!(
  64. "{}",
  65. format!(
  66. "cargo:rustc-link-search={}",
  67. path.join("lib").to_str().unwrap()
  68. )
  69. );
  70. println!("cargo:rustc-link-lib=ndk_compat");
  71. println!("cargo:rustc-link-lib=oboe");
  72. println!("cargo:rustc-link-lib=oboe_wrapper");
  73. println!("cargo:rustc-link-lib=c++");
  74. println!("cargo:rustc-link-lib=OpenSLES");
  75. }
  76. fn main() {
  77. hbb_common::gen_version();
  78. install_android_deps();
  79. #[cfg(all(windows, feature = "inline"))]
  80. build_manifest();
  81. #[cfg(windows)]
  82. build_windows();
  83. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
  84. if target_os == "macos" {
  85. #[cfg(target_os = "macos")]
  86. build_mac();
  87. println!("cargo:rustc-link-lib=framework=ApplicationServices");
  88. }
  89. println!("cargo:rerun-if-changed=build.rs");
  90. }