1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
mod build;
pub use build::build;

pub fn out_dir() -> &'static str {
    std::env!("OUT_DIR")
}

pub fn print_cargo_link() {
    print_cargo_link_from(out_dir())
}

/**
 * @param dst Pass OUT_DIR environment variable value.
 */
pub fn print_cargo_link_from(dst: &str) {
    #[cfg(all(windows, debug_assertions))]
    // Prevents "undefined symbol _CrtDbgReport" linker error
    println!("cargo:rustc-link-lib=dylib=msvcrtd");

    println!("cargo:rustc-link-search=native={}/lib", dst);
    println!("cargo:rustc-link-search=native={}/build/third_party", dst);
    println!(
        "cargo:rustc-link-search=native={}/build/third_party/brotli",
        dst
    );
    println!(
        "cargo:rustc-link-search=native={}/build/third_party/highway",
        dst
    );

    if cfg!(windows) {
        println!("cargo:rustc-link-lib=static=jxl-static");
        println!("cargo:rustc-link-lib=static=jxl_threads-static");
    } else {
        println!("cargo:rustc-link-lib=static=jxl");
        println!("cargo:rustc-link-lib=static=jxl_threads");
    }
    println!("cargo:rustc-link-lib=static=brotlicommon-static");
    println!("cargo:rustc-link-lib=static=brotlidec-static");
    println!("cargo:rustc-link-lib=static=brotlienc-static");
    println!("cargo:rustc-link-lib=static=hwy");
    println!("cargo:rustc-link-lib=static=skcms");

    #[cfg(not(windows))]
    // The order matters; this should be after other libs or the linker fails
    println!("cargo:rustc-link-lib=dylib=stdc++");
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_print() {
        super::print_cargo_link();
    }
}