Skip to content

Commit

Permalink
Fix cargo-xwin build
Browse files Browse the repository at this point in the history
Use `CARGO_CFG_TARGET_OS` instead of `cfg` macros
  • Loading branch information
dzervas committed May 30, 2023
1 parent 367c369 commit 6be3238
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
23 changes: 12 additions & 11 deletions frida-gum-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::env;
use std::path::PathBuf;

fn main() {
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
#[cfg(feature = "event-sink")]
{
println!("cargo:rerun-if-changed=event_sink.c");
Expand Down Expand Up @@ -50,8 +51,7 @@ fn main() {
#[cfg(not(feature = "auto-download"))]
println!("cargo:rustc-link-lib=frida-gum");

if env::var("CARGO_CFG_TARGET_OS").unwrap() != "android" {
#[cfg(any(target_os = "linux", target_os = "macos"))]
if target_os != "android" && (target_os == "linux" || target_os == "macos") {
println!("cargo:rustc-link-lib=pthread");
}

Expand Down Expand Up @@ -186,13 +186,14 @@ fn main() {
.compile("stalker_params");
}

#[cfg(target_os = "windows")]
[
"dnsapi", "iphlpapi", "psapi", "winmm", "ws2_32", "advapi32", "crypt32", "gdi32",
"kernel32", "ole32", "secur32", "shell32", "shlwapi", "user32",
]
.iter()
.for_each(|lib| {
println!("cargo:rustc-link-lib=dylib={}", lib);
});
if target_os == "windows" {
[
"dnsapi", "iphlpapi", "psapi", "winmm", "ws2_32", "advapi32", "crypt32", "gdi32",
"kernel32", "ole32", "secur32", "shell32", "shlwapi", "user32",
]
.iter()
.for_each(|lib| {
println!("cargo:rustc-link-lib=dylib={}", lib);
});
}
}
26 changes: 13 additions & 13 deletions frida-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn main() {
"cargo:rustc-link-search={}",
env::var("CARGO_MANIFEST_DIR").unwrap()
);
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();

#[cfg(feature = "auto-download")]
let include_dir = {
Expand All @@ -24,14 +25,12 @@ fn main() {
#[cfg(not(feature = "auto-download"))]
println!("cargo:rustc-link-lib=frida-core");

#[cfg(target_os = "linux")]
{
if target_os == "linux" {
println!("cargo:rustc-link-lib=pthread");
println!("cargo:rustc-link-lib=resolv");
}

#[cfg(target_os = "macos")]
{
if target_os == "macos" {
println!("cargo:rustc-link-lib=bsm");
println!("cargo:rustc-link-lib=pthread");
println!("cargo:rustc-link-lib=framework=AppKit");
Expand Down Expand Up @@ -62,13 +61,14 @@ fn main() {
.write_to_file(out_path.join("bindings.rs"))
.unwrap();

#[cfg(target_os = "windows")]
let _ = &[
"dnsapi", "iphlpapi", "psapi", "winmm", "ws2_32", "advapi32", "crypt32", "gdi32",
"kernel32", "ole32", "secur32", "shell32", "shlwapi", "user32",
]
.iter()
.for_each(|lib| {
println!("cargo:rustc-link-lib=dylib={}", lib);
});
if target_os == "windows" {
let _ = &[
"dnsapi", "iphlpapi", "psapi", "winmm", "ws2_32", "advapi32", "crypt32", "gdi32",
"kernel32", "ole32", "secur32", "shell32", "shlwapi", "user32",
]
.iter()
.for_each(|lib| {
println!("cargo:rustc-link-lib=dylib={}", lib);
});
}
}

0 comments on commit 6be3238

Please sign in to comment.