2021-03-29 10:59:14 +03:00
#[ cfg(windows) ]
fn build_windows ( ) {
2023-01-06 07:20:26 +03:00
let file = " src/platform/windows.cc " ;
cc ::Build ::new ( ) . file ( file ) . compile ( " windows " ) ;
2021-04-09 04:58:50 +03:00
println! ( " cargo:rustc-link-lib=WtsApi32 " ) ;
2023-01-06 07:20:26 +03:00
println! ( " cargo:rerun-if-changed= {} " , file ) ;
}
#[ cfg(target_os = " macos " ) ]
fn build_mac ( ) {
let file = " src/platform/macos.mm " ;
2023-03-09 12:22:14 +03:00
let mut b = cc ::Build ::new ( ) ;
if let Ok ( os_version ::OsVersion ::MacOS ( v ) ) = os_version ::detect ( ) {
let v = v . version ;
if v . contains ( " 10.14 " ) {
b . flag ( " -DNO_InputMonitoringAuthStatus=1 " ) ;
}
}
b . file ( file ) . compile ( " macos " ) ;
2023-01-06 07:20:26 +03:00
println! ( " cargo:rerun-if-changed= {} " , file ) ;
2021-03-29 10:59:14 +03:00
}
#[ cfg(all(windows, feature = " inline " )) ]
fn build_manifest ( ) {
use std ::io ::Write ;
if std ::env ::var ( " PROFILE " ) . unwrap ( ) = = " release " {
let mut res = winres ::WindowsResource ::new ( ) ;
2023-06-30 17:13:16 +03:00
res . set_icon ( " res/icon.ico " )
2021-03-29 10:59:14 +03:00
. set_language ( winapi ::um ::winnt ::MAKELANGID (
winapi ::um ::winnt ::LANG_ENGLISH ,
winapi ::um ::winnt ::SUBLANG_ENGLISH_US ,
) )
2022-09-18 06:26:10 +03:00
. set_manifest_file ( " res/manifest.xml " ) ;
2021-03-29 10:59:14 +03:00
match res . compile ( ) {
Err ( e ) = > {
write! ( std ::io ::stderr ( ) , " {} " , e ) . unwrap ( ) ;
std ::process ::exit ( 1 ) ;
}
Ok ( _ ) = > { }
}
}
}
2023-11-01 12:37:39 +03:00
fn install_android_deps ( ) {
2021-03-29 10:59:14 +03:00
let target_os = std ::env ::var ( " CARGO_CFG_TARGET_OS " ) . unwrap ( ) ;
if target_os ! = " android " {
return ;
}
let mut target_arch = std ::env ::var ( " CARGO_CFG_TARGET_ARCH " ) . unwrap ( ) ;
if target_arch = = " x86_64 " {
target_arch = " x64 " . to_owned ( ) ;
2023-11-01 12:37:39 +03:00
} else if target_arch = = " x86 " {
target_arch = " x86 " . to_owned ( ) ;
2021-03-29 10:59:14 +03:00
} else if target_arch = = " aarch64 " {
target_arch = " arm64 " . to_owned ( ) ;
} else {
target_arch = " arm " . to_owned ( ) ;
}
2022-05-12 12:55:49 +03:00
let target = format! ( " {} -android " , target_arch ) ;
2021-03-29 10:59:14 +03:00
let vcpkg_root = std ::env ::var ( " VCPKG_ROOT " ) . unwrap ( ) ;
let mut path : std ::path ::PathBuf = vcpkg_root . into ( ) ;
path . push ( " installed " ) ;
path . push ( target ) ;
println! (
" {} " ,
format! (
" cargo:rustc-link-search={} " ,
path . join ( " lib " ) . to_str ( ) . unwrap ( )
)
) ;
2023-11-01 12:37:39 +03:00
println! ( " cargo:rustc-link-lib=ndk_compat " ) ;
2021-03-29 10:59:14 +03:00
println! ( " cargo:rustc-link-lib=oboe " ) ;
2023-11-07 17:13:04 +03:00
println! ( " cargo:rustc-link-lib=oboe_wrapper " ) ;
2021-03-29 10:59:14 +03:00
println! ( " cargo:rustc-link-lib=c++ " ) ;
println! ( " cargo:rustc-link-lib=OpenSLES " ) ;
}
fn main ( ) {
2022-05-12 12:55:49 +03:00
hbb_common ::gen_version ( ) ;
2023-11-01 12:37:39 +03:00
install_android_deps ( ) ;
2021-03-29 10:59:14 +03:00
#[ cfg(all(windows, feature = " inline " )) ]
build_manifest ( ) ;
#[ cfg(windows) ]
build_windows ( ) ;
2023-04-18 08:40:32 +03:00
let target_os = std ::env ::var ( " CARGO_CFG_TARGET_OS " ) . unwrap ( ) ;
if target_os = = " macos " {
#[ cfg(target_os = " macos " ) ]
build_mac ( ) ;
println! ( " cargo:rustc-link-lib=framework=ApplicationServices " ) ;
}
2023-01-06 07:20:26 +03:00
println! ( " cargo:rerun-if-changed=build.rs " ) ;
2022-09-18 06:26:10 +03:00
}