build.rs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if let Ok(vcpkg_root) = std::env::var("VCPKG_INSTALLED_ROOT") {
  62. path = vcpkg_root.into();
  63. } else {
  64. path.push("installed");
  65. }
  66. path.push(target);
  67. println!(
  68. "{}",
  69. format!(
  70. "cargo:rustc-link-search={}",
  71. path.join("lib").to_str().unwrap()
  72. )
  73. );
  74. println!("cargo:rustc-link-lib=ndk_compat");
  75. println!("cargo:rustc-link-lib=oboe");
  76. println!("cargo:rustc-link-lib=c++");
  77. println!("cargo:rustc-link-lib=OpenSLES");
  78. }
  79. fn main() {
  80. hbb_common::gen_version();
  81. install_android_deps();
  82. #[cfg(all(windows, feature = "inline"))]
  83. build_manifest();
  84. #[cfg(windows)]
  85. build_windows();
  86. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
  87. if target_os == "macos" {
  88. #[cfg(target_os = "macos")]
  89. build_mac();
  90. println!("cargo:rustc-link-lib=framework=ApplicationServices");
  91. }
  92. println!("cargo:rerun-if-changed=build.rs");
  93. }