2021-03-29 15:59:14 +08:00
|
|
|
#[cfg(windows)]
|
|
|
|
fn build_windows() {
|
2023-01-06 12:20:26 +08:00
|
|
|
let file = "src/platform/windows.cc";
|
|
|
|
cc::Build::new().file(file).compile("windows");
|
2021-04-09 09:58:50 +08:00
|
|
|
println!("cargo:rustc-link-lib=WtsApi32");
|
2023-01-06 12:20:26 +08:00
|
|
|
println!("cargo:rerun-if-changed={}", file);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
fn build_mac() {
|
|
|
|
let file = "src/platform/macos.mm";
|
2023-03-09 17:22:14 +08: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 12:20:26 +08:00
|
|
|
println!("cargo:rerun-if-changed={}", file);
|
2021-03-29 15:59:14 +08: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-05 20:27:48 +08:00
|
|
|
res.set_icon("res/tray-icon.ico")
|
2021-03-29 15:59:14 +08:00
|
|
|
.set_language(winapi::um::winnt::MAKELANGID(
|
|
|
|
winapi::um::winnt::LANG_ENGLISH,
|
|
|
|
winapi::um::winnt::SUBLANG_ENGLISH_US,
|
|
|
|
))
|
2022-09-18 11:26:10 +08:00
|
|
|
.set_manifest_file("res/manifest.xml");
|
2021-03-29 15:59:14 +08:00
|
|
|
match res.compile() {
|
|
|
|
Err(e) => {
|
|
|
|
write!(std::io::stderr(), "{}", e).unwrap();
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
Ok(_) => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install_oboe() {
|
|
|
|
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();
|
|
|
|
} else if target_arch == "aarch64" {
|
|
|
|
target_arch = "arm64".to_owned();
|
|
|
|
} else {
|
|
|
|
target_arch = "arm".to_owned();
|
|
|
|
}
|
2022-05-12 17:55:49 +08:00
|
|
|
let target = format!("{}-android", target_arch);
|
2021-03-29 15:59:14 +08: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()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
println!("cargo:rustc-link-lib=oboe");
|
|
|
|
println!("cargo:rustc-link-lib=c++");
|
|
|
|
println!("cargo:rustc-link-lib=OpenSLES");
|
|
|
|
// I always got some strange link error with oboe, so as workaround, put oboe.cc into oboe src: src/common/AudioStreamBuilder.cpp
|
|
|
|
// also to avoid libc++_shared not found issue, cp ndk's libc++_shared.so to jniLibs, e.g.
|
|
|
|
// ./flutter_hbb/android/app/src/main/jniLibs/arm64-v8a/libc++_shared.so
|
|
|
|
// let include = path.join("include");
|
|
|
|
//cc::Build::new().file("oboe.cc").include(include).compile("oboe_wrapper");
|
|
|
|
}
|
|
|
|
|
2022-09-18 13:13:45 +08:00
|
|
|
#[cfg(feature = "flutter")]
|
2022-05-17 19:59:37 +08:00
|
|
|
fn gen_flutter_rust_bridge() {
|
2023-01-19 21:21:28 +08:00
|
|
|
use lib_flutter_rust_bridge_codegen::{
|
|
|
|
config_parse, frb_codegen, get_symbols_if_no_duplicates, RawOpts,
|
|
|
|
};
|
2022-07-27 22:56:28 +08:00
|
|
|
let llvm_path = match std::env::var("LLVM_HOME") {
|
2022-09-02 20:41:50 +08:00
|
|
|
Ok(path) => Some(vec![path]),
|
2022-09-03 07:54:53 +08:00
|
|
|
Err(_) => None,
|
2022-07-27 22:56:28 +08:00
|
|
|
};
|
2022-05-17 19:59:37 +08:00
|
|
|
// Tell Cargo that if the given file changes, to rerun this build script.
|
2022-05-25 20:50:32 +08:00
|
|
|
println!("cargo:rerun-if-changed=src/flutter_ffi.rs");
|
2023-01-19 21:21:28 +08:00
|
|
|
// Options for frb_codegen
|
|
|
|
let raw_opts = RawOpts {
|
2022-05-17 19:59:37 +08:00
|
|
|
// Path of input Rust code
|
2023-01-19 21:21:28 +08:00
|
|
|
rust_input: vec!["src/flutter_ffi.rs".to_string()],
|
2022-05-17 19:59:37 +08:00
|
|
|
// Path of output generated Dart code
|
2023-01-19 21:21:28 +08:00
|
|
|
dart_output: vec!["flutter/lib/generated_bridge.dart".to_string()],
|
2022-06-02 16:13:34 +08:00
|
|
|
// Path of output generated C header
|
|
|
|
c_output: Some(vec!["flutter/macos/Runner/bridge_generated.h".to_string()]),
|
2023-01-19 21:21:28 +08:00
|
|
|
/// Path to the installed LLVM
|
2022-07-27 22:56:28 +08:00
|
|
|
llvm_path,
|
2023-01-19 21:21:28 +08:00
|
|
|
// for other options use defaults
|
2022-05-17 19:59:37 +08:00
|
|
|
..Default::default()
|
|
|
|
};
|
2023-01-19 21:21:28 +08:00
|
|
|
// get opts from raw opts
|
|
|
|
let configs = config_parse(raw_opts);
|
|
|
|
// generation of rust api for ffi
|
|
|
|
let all_symbols = get_symbols_if_no_duplicates(&configs).unwrap();
|
|
|
|
for config in configs.iter() {
|
|
|
|
frb_codegen(config, &all_symbols).unwrap();
|
|
|
|
}
|
2022-05-17 19:59:37 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 15:59:14 +08:00
|
|
|
fn main() {
|
2022-05-12 17:55:49 +08:00
|
|
|
hbb_common::gen_version();
|
|
|
|
install_oboe();
|
|
|
|
// there is problem with cfg(target_os) in build.rs, so use our workaround
|
2022-05-25 14:30:19 +08:00
|
|
|
// let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
|
|
|
|
// if target_os == "android" || target_os == "ios" {
|
2022-09-08 18:21:17 +08:00
|
|
|
#[cfg(feature = "flutter")]
|
2022-06-02 16:13:34 +08:00
|
|
|
gen_flutter_rust_bridge();
|
2022-05-25 14:30:19 +08:00
|
|
|
// return;
|
|
|
|
// }
|
2021-03-29 15:59:14 +08:00
|
|
|
#[cfg(all(windows, feature = "inline"))]
|
|
|
|
build_manifest();
|
|
|
|
#[cfg(windows)]
|
|
|
|
build_windows();
|
2023-04-18 13:40:32 +08: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 12:20:26 +08:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
2022-09-18 11:26:10 +08:00
|
|
|
}
|