mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-08-30 10:06:35 +00:00
Turning on hbb_common's "webrtc" feature pulls webrtc-util into the android link, and its ifaces() -- reached from vnet::Net::new() on every ICE gather -- calls getifaddrs(). bionic exports getifaddrs/freeifaddrs only from API 24, while flutter/ndk_*.sh builds against --platform 21, so every abi failed to link on the undefined symbols. Raising the platform to 24 would have to drag minSdkVersion 22 with it and turn the link error into a load-time one on Android 5.1/6.0, so define the two symbols instead, using the RTM_GETLINK + RTM_GETADDR netlink dump bionic itself uses. The definition also shadows bionic's on API >= 24 rather than delegating to it, so the path that ships is the path every test device runs. Checked against synthesised netlink dumps on the host -- link/address parsing, prefix masks, point-to-point, ipv6 scope ids, malformed and truncated messages -- under UBSan and byte-exact guard malloc, with a deliberately unsigned remainder as the negative control. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
106 lines
3.4 KiB
Rust
106 lines
3.4 KiB
Rust
#[cfg(windows)]
|
|
fn build_windows() {
|
|
let file = "src/platform/windows.cc";
|
|
let file2 = "src/platform/windows_delete_test_cert.cc";
|
|
cc::Build::new().file(file).file(file2).compile("windows");
|
|
println!("cargo:rustc-link-lib=WtsApi32");
|
|
println!("cargo:rerun-if-changed={}", file);
|
|
println!("cargo:rerun-if-changed={}", file2);
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
fn build_mac() {
|
|
let file = "src/platform/macos.mm";
|
|
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.flag("-std=c++17").file(file).compile("macos");
|
|
println!("cargo:rerun-if-changed={}", file);
|
|
}
|
|
|
|
#[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();
|
|
res.set_icon("res/icon.ico")
|
|
.set_language(winapi::um::winnt::MAKELANGID(
|
|
winapi::um::winnt::LANG_ENGLISH,
|
|
winapi::um::winnt::SUBLANG_ENGLISH_US,
|
|
))
|
|
.set_manifest_file("res/manifest.xml");
|
|
match res.compile() {
|
|
Err(e) => {
|
|
write!(std::io::stderr(), "{}", e).unwrap();
|
|
std::process::exit(1);
|
|
}
|
|
Ok(_) => {}
|
|
}
|
|
}
|
|
}
|
|
|
|
// bionic only exports getifaddrs()/freeifaddrs() from API 24, while the jniLibs
|
|
// are built against the API 21 sysroot (flutter/ndk_*.sh). webrtc-util calls
|
|
// them, so without this the android link fails on undefined symbols.
|
|
fn build_android_ifaddrs() {
|
|
let file = "src/platform/android_ifaddrs.c";
|
|
cc::Build::new().file(file).compile("android_ifaddrs");
|
|
println!("cargo:rerun-if-changed={}", file);
|
|
}
|
|
|
|
fn install_android_deps() {
|
|
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 == "x86" {
|
|
target_arch = "x86".to_owned();
|
|
} else if target_arch == "aarch64" {
|
|
target_arch = "arm64".to_owned();
|
|
} else {
|
|
target_arch = "arm".to_owned();
|
|
}
|
|
let target = format!("{}-android", target_arch);
|
|
let vcpkg_root = std::env::var("VCPKG_ROOT").unwrap();
|
|
let mut path: std::path::PathBuf = vcpkg_root.into();
|
|
if let Ok(vcpkg_root) = std::env::var("VCPKG_INSTALLED_ROOT") {
|
|
path = vcpkg_root.into();
|
|
} else {
|
|
path.push("installed");
|
|
}
|
|
path.push(target);
|
|
println!(
|
|
"cargo:rustc-link-search={}",
|
|
path.join("lib").to_str().unwrap()
|
|
);
|
|
println!("cargo:rustc-link-lib=ndk_compat");
|
|
println!("cargo:rustc-link-lib=c++");
|
|
println!("cargo:rustc-link-lib=OpenSLES");
|
|
}
|
|
|
|
fn main() {
|
|
hbb_common::gen_version();
|
|
install_android_deps();
|
|
#[cfg(all(windows, feature = "inline"))]
|
|
build_manifest();
|
|
#[cfg(windows)]
|
|
build_windows();
|
|
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");
|
|
}
|
|
if target_os == "android" {
|
|
build_android_ifaddrs();
|
|
}
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
}
|