MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / main

Function main

build.rs:8–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6const ASM_PATH: &str = "src/backend/linux_raw/arch";
7
8fn main() {
9 // Don't rerun this on changes other than build.rs, as we only depend on
10 // the rustc version.
11 println!("cargo:rerun-if-changed=build.rs");
12
13 // Gather target information.
14 let arch = var("CARGO_CFG_TARGET_ARCH").unwrap();
15 let env = var("CARGO_CFG_TARGET_ENV").unwrap();
16 let abi = var("CARGO_CFG_TARGET_ABI");
17 let inline_asm_name = format!("{}/{}.rs", ASM_PATH, arch);
18 let inline_asm_name_present = std::fs::metadata(inline_asm_name).is_ok();
19 let os = var("CARGO_CFG_TARGET_OS").unwrap();
20 let pointer_width = var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();
21 let endian = var("CARGO_CFG_TARGET_ENDIAN").unwrap();
22
23 // Check for special target variants.
24 let is_x32 = arch == "x86_64" && pointer_width == "32";
25 let is_arm64_ilp32 = arch == "aarch64" && pointer_width == "32";
26 let is_powerpc64be = arch == "powerpc64" && endian == "big";
27 let is_mipseb = (arch == "mips" || arch == "mips32r6") && endian == "big";
28 let is_mips64eb = arch.contains("mips64") && endian == "big";
29 let is_unsupported_abi = is_x32 || is_arm64_ilp32 || is_powerpc64be || is_mipseb || is_mips64eb;
30
31 // Check for `--features=use-libc`. This allows crate users to enable the
32 // libc backend.
33 let feature_use_libc = var("CARGO_FEATURE_USE_LIBC").is_ok();
34
35 // Check for `RUSTFLAGS=--cfg=rustix_use_libc`. This allows end users to
36 // enable the libc backend even if rustix is depended on transitively.
37 let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok();
38
39 // Check for `RUSTFLAGS=--cfg=rustix_no_linux_raw`. This allows Linux users to
40 // enable the libc backend without the linux raw dependency.
41 let cfg_no_linux_raw = var("CARGO_CFG_RUSTIX_NO_LINUX_RAW").is_ok();
42
43 // Check for `--features=rustc-dep-of-std`.
44 let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
45
46 // Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_features`. This
47 // is a rustc flag rather than a cargo feature flag because it's
48 // experimental and not something we want accidentally enabled via
49 // `--all-features`.
50 let rustix_use_experimental_features =
51 var("CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_FEATURES").is_ok();
52
53 // Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_asm`. This is a
54 // rustc flag rather than a cargo feature flag because it's experimental
55 // and not something we want accidentally enabled via `--all-features`.
56 let rustix_use_experimental_asm = var("CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_ASM").is_ok();
57
58 // Miri doesn't support inline asm, and has builtin support for recognizing
59 // libc FFI calls, so if we're running under miri, use the libc backend.
60 let miri = var("CARGO_CFG_MIRI").is_ok();
61
62 // If experimental features are enabled, auto-detect and use available
63 // features.
64 if rustc_dep_of_std {
65 use_feature("rustc_attrs");

Callers

nothing calls this directly

Calls 7

use_featureFunction · 0.85
use_feature_or_nothingFunction · 0.85
use_static_assertionsFunction · 0.85
can_compileFunction · 0.85
use_thumb_modeFunction · 0.85
containsMethod · 0.80

Tested by

no test coverage detected