ThiƩbaud Weksteen | d4f2c3c | 2020-11-03 11:08:00 +0100 | [diff] [blame] | 1 | use std::env; |
| 2 | |
| 3 | fn main() { |
| 4 | println!("cargo:rerun-if-changed=build.rs"); |
| 5 | let target = env::var("TARGET").expect("TARGET was not set"); |
| 6 | if target.contains("linux") { |
| 7 | if target.contains("android") { |
| 8 | println!("cargo:rustc-link-lib=dl"); |
| 9 | println!("cargo:rustc-link-lib=log"); |
| 10 | println!("cargo:rustc-link-lib=gcc"); |
| 11 | } else if !target.contains("musl") { |
| 12 | println!("cargo:rustc-link-lib=dl"); |
| 13 | println!("cargo:rustc-link-lib=rt"); |
| 14 | println!("cargo:rustc-link-lib=pthread"); |
| 15 | } |
| 16 | } else if target.contains("freebsd") { |
| 17 | println!("cargo:rustc-link-lib=execinfo"); |
| 18 | println!("cargo:rustc-link-lib=pthread"); |
| 19 | if env::var("RUST_STD_FREEBSD_12_ABI").is_ok() { |
| 20 | println!("cargo:rustc-cfg=freebsd12"); |
| 21 | } |
| 22 | } else if target.contains("netbsd") { |
| 23 | println!("cargo:rustc-link-lib=pthread"); |
| 24 | println!("cargo:rustc-link-lib=rt"); |
| 25 | } else if target.contains("dragonfly") || target.contains("openbsd") { |
| 26 | println!("cargo:rustc-link-lib=pthread"); |
| 27 | } else if target.contains("solaris") { |
| 28 | println!("cargo:rustc-link-lib=socket"); |
| 29 | println!("cargo:rustc-link-lib=posix4"); |
| 30 | println!("cargo:rustc-link-lib=pthread"); |
| 31 | println!("cargo:rustc-link-lib=resolv"); |
| 32 | } else if target.contains("illumos") { |
| 33 | println!("cargo:rustc-link-lib=socket"); |
| 34 | println!("cargo:rustc-link-lib=posix4"); |
| 35 | println!("cargo:rustc-link-lib=pthread"); |
| 36 | println!("cargo:rustc-link-lib=resolv"); |
| 37 | println!("cargo:rustc-link-lib=nsl"); |
| 38 | // Use libumem for the (malloc-compatible) allocator |
| 39 | println!("cargo:rustc-link-lib=umem"); |
| 40 | } else if target.contains("apple-darwin") { |
| 41 | println!("cargo:rustc-link-lib=System"); |
| 42 | |
| 43 | // res_init and friends require -lresolv on macOS/iOS. |
| 44 | // See #41582 and http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html |
| 45 | println!("cargo:rustc-link-lib=resolv"); |
| 46 | } else if target.contains("apple-ios") { |
| 47 | println!("cargo:rustc-link-lib=System"); |
| 48 | println!("cargo:rustc-link-lib=objc"); |
| 49 | println!("cargo:rustc-link-lib=framework=Security"); |
| 50 | println!("cargo:rustc-link-lib=framework=Foundation"); |
| 51 | println!("cargo:rustc-link-lib=resolv"); |
| 52 | } else if target.contains("uwp") { |
| 53 | println!("cargo:rustc-link-lib=ws2_32"); |
| 54 | // For BCryptGenRandom |
| 55 | println!("cargo:rustc-link-lib=bcrypt"); |
| 56 | } else if target.contains("windows") { |
| 57 | println!("cargo:rustc-link-lib=advapi32"); |
| 58 | println!("cargo:rustc-link-lib=ws2_32"); |
| 59 | println!("cargo:rustc-link-lib=userenv"); |
| 60 | } else if target.contains("fuchsia") { |
| 61 | println!("cargo:rustc-link-lib=zircon"); |
| 62 | println!("cargo:rustc-link-lib=fdio"); |
| 63 | } else if target.contains("cloudabi") { |
| 64 | if cfg!(feature = "backtrace") { |
| 65 | println!("cargo:rustc-link-lib=unwind"); |
| 66 | } |
| 67 | println!("cargo:rustc-link-lib=c"); |
| 68 | println!("cargo:rustc-link-lib=compiler_rt"); |
| 69 | } else if (target.contains("sgx") && target.contains("fortanix")) |
| 70 | || target.contains("hermit") |
| 71 | || target.contains("l4re") |
| 72 | || target.contains("redox") |
| 73 | || target.contains("haiku") |
| 74 | || target.contains("vxworks") |
| 75 | || target.contains("wasm32") |
| 76 | || target.contains("asmjs") |
| 77 | { |
| 78 | // These platforms don't have any special requirements. |
| 79 | } else { |
| 80 | // This is for Cargo's build-std support, to mark std as unstable for |
| 81 | // typically no_std platforms. |
| 82 | // This covers: |
| 83 | // - os=none ("bare metal" targets) |
| 84 | // - mipsel-sony-psp |
| 85 | // - nvptx64-nvidia-cuda |
| 86 | // - avr-unknown-unknown |
| 87 | // - tvos (aarch64-apple-tvos, x86_64-apple-tvos) |
| 88 | // - uefi (x86_64-unknown-uefi, i686-unknown-uefi) |
| 89 | // - JSON targets |
| 90 | // - Any new targets that have not been explicitly added above. |
| 91 | println!("cargo:rustc-cfg=feature=\"restricted-std\""); |
| 92 | } |
| 93 | println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()); |
| 94 | println!("cargo:rustc-cfg=backtrace_in_libstd"); |
| 95 | } |