run_make_support/external_deps/c_cxx_compiler/
extras.rs

1use crate::{is_arm64ec, is_win7, is_windows, is_windows_msvc, target, uname};
2
3fn get_windows_msvc_libs() -> Vec<&'static str> {
4    let mut libs =
5        vec!["ws2_32.lib", "userenv.lib", "bcrypt.lib", "ntdll.lib", "synchronization.lib"];
6    if is_win7() {
7        libs.push("advapi32.lib");
8    }
9    libs
10}
11
12/// `EXTRACFLAGS`
13pub fn extra_c_flags() -> Vec<&'static str> {
14    if is_windows() {
15        if is_windows_msvc() {
16            let mut args = get_windows_msvc_libs();
17            if is_arm64ec() {
18                args.push("/arm64EC");
19            }
20            args
21        } else {
22            vec!["-lws2_32", "-luserenv", "-lbcrypt", "-lntdll", "-lsynchronization"]
23        }
24    } else {
25        // For cross-compilation targets, we need to check the target, not the host
26        let target_triple = target();
27        if target_triple.contains("hexagon") {
28            // Hexagon targets need unwind support but don't have some Linux libraries
29            vec!["-lunwind", "-lclang_rt.builtins-hexagon"]
30        } else {
31            // For host-based detection, fall back to uname() for non-cross compilation
32            match uname() {
33                n if n.contains("Darwin") => vec!["-lresolv"],
34                n if n.contains("FreeBSD") => vec!["-lm", "-lpthread", "-lgcc_s"],
35                n if n.contains("SunOS") => {
36                    vec!["-lm", "-lpthread", "-lposix4", "-lsocket", "-lresolv"]
37                }
38                n if n.contains("OpenBSD") => vec!["-lm", "-lpthread", "-lc++abi"],
39                _ => vec!["-lm", "-lrt", "-ldl", "-lpthread"],
40            }
41        }
42    }
43}
44
45pub fn extra_linker_flags() -> Vec<&'static str> {
46    if is_windows_msvc() {
47        let mut args = get_windows_msvc_libs();
48        if is_arm64ec() {
49            args.push("/MACHINE:ARM64EC");
50        }
51        args
52    } else {
53        vec![]
54    }
55}
56
57/// `EXTRACXXFLAGS`
58pub fn extra_cxx_flags() -> Vec<&'static str> {
59    if is_windows() {
60        if is_windows_msvc() { vec![] } else { vec!["-lstdc++"] }
61    } else {
62        match &uname()[..] {
63            "Darwin" => vec!["-lc++"],
64            "FreeBSD" | "SunOS" | "OpenBSD" => vec![],
65            _ => vec!["-lstdc++"],
66        }
67    }
68}