Skip to content
Myr

build.rs

This file

Path

build.rs

194 lines · 6.8 KiB · Rust

Last changed by

Merge pull request #440 from dtolnay/backtraceDavid Tolnaybefore adoption9b67e5d

History of this file

Take it

The walk stopped after 200 commits: lines older than 553ed38 point at it.

Merge pull request #436 from dtolnay/upDavid Tolnaybefore adoption67df012

lines 1–2why, one step back
1#![allow(clippy::uninlined_format_args)]
2

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 3why, one step back
3use std::env;

Merge pull request #335 from dtolnay/cargoenvvarDavid Tolnaybefore adoptioneb66ff5

line 4why, one step back
4use std::ffi::OsString;

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

lines 5–6why, one step back
5use std::fs;
6use std::io::ErrorKind;

Merge pull request #358 from dtolnay/workspacewrapperDavid Tolnaybefore adoption7a4cac5

line 7why, one step back
7use std::iter;

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 8why, one step back
8use std::path::Path;

Move ExitStatus::success check into compile_probe()David Tolnaybefore adoptiond10baed

line 9why, one step back
9use std::process::{self, Command, Stdio};

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 10–13why, one step back
10use std::str;
1112fn main() {13 if cfg!(feature = "std") {

Merge pull request #414 from dtolnay/nightlyDavid Tolnaybefore adoption213a9c2

line 14why, one step back
14 println!("cargo:rerun-if-changed=src/nightly.rs");

Merge pull request #330 from dtolnay/bootstrapDavid Tolnaybefore adoption5121cd2

line 15why, one step back
15

Merge pull request #440 from dtolnay/backtraceDavid Tolnaybefore adoption9b67e5d

line 16why, one step back
16 let error_generic_member_access;

Merge pull request #337 from dtolnay/bootstrapDavid Tolnaybefore adoptionded2295

lines 17–52why, one step back
17 let consider_rustc_bootstrap;
18 if compile_probe(false) {19 // This is a nightly or dev compiler, so it supports unstable20 // features regardless of RUSTC_BOOTSTRAP. No need to rerun build21 // script if RUSTC_BOOTSTRAP is changed.22 error_generic_member_access = true;23 consider_rustc_bootstrap = false;24 } else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") {25 if compile_probe(true) {26 // This is a stable or beta compiler for which the user has set27 // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build28 // script if they change it.29 error_generic_member_access = true;30 consider_rustc_bootstrap = true;31 } else if rustc_bootstrap == "1" {32 // This compiler does not support the generic member access API33 // in the form that anyhow expects. No need to pay attention to34 // RUSTC_BOOTSTRAP.35 error_generic_member_access = false;36 consider_rustc_bootstrap = false;37 } else {38 // This is a stable or beta compiler for which RUSTC_BOOTSTRAP39 // is set to restrict the use of unstable features by this40 // crate.41 error_generic_member_access = false;42 consider_rustc_bootstrap = true;43 }44 } else {45 // Without RUSTC_BOOTSTRAP, this compiler does not support the46 // generic member access API in the form that anyhow expects, but47 // try again if the user turns on unstable features.48 error_generic_member_access = false;49 consider_rustc_bootstrap = true;50 }5152 if error_generic_member_access {

Move ExitStatus::success check into compile_probe()David Tolnaybefore adoptiond10baed

line 53why, one step back
53 println!("cargo:rustc-cfg=error_generic_member_access");

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 54why, one step back
54 }

Merge pull request #337 from dtolnay/bootstrapDavid Tolnaybefore adoptionded2295

lines 55–58why, one step back
55
56 if consider_rustc_bootstrap {57 println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");58 }

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 59–60why, one step back
59 }
60

Merge pull request #436 from dtolnay/upDavid Tolnaybefore adoption67df012

lines 61–62why, one step back
61 let Some(rustc) = rustc_minor_version() else {
62 return;

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 63–64why, one step back
63 };
64

Merge pull request #363 from dtolnay/checkcfgDavid Tolnaybefore adoption17bbd1e

line 65why, one step back
65 if rustc >= 80 {

Merge pull request #414 from dtolnay/nightlyDavid Tolnaybefore adoption213a9c2

line 66why, one step back
66 println!("cargo:rustc-check-cfg=cfg(anyhow_build_probe)");

Merge pull request #363 from dtolnay/checkcfgDavid Tolnaybefore adoption17bbd1e

line 67why, one step back
67 println!("cargo:rustc-check-cfg=cfg(anyhow_nightly_testing)");

Merge pull request #426 from dtolnay/clippyfmtDavid Tolnaybefore adoptionf271988

line 68why, one step back
68 println!("cargo:rustc-check-cfg=cfg(anyhow_no_clippy_format_args)");

Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf

line 69why, one step back
69 println!("cargo:rustc-check-cfg=cfg(anyhow_no_core_error)");

Merge pull request #363 from dtolnay/checkcfgDavid Tolnaybefore adoption17bbd1e

line 70why, one step back
70 println!("cargo:rustc-check-cfg=cfg(error_generic_member_access)");

Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf

lines 71–76why, one step back
71 }
7273 if rustc < 81 {74 // core::error::Error75 // https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror76 println!("cargo:rustc-cfg=anyhow_no_core_error");

Merge pull request #426 from dtolnay/clippyfmtDavid Tolnaybefore adoptionf271988

lines 77–82why, one step back
77 }
7879 if rustc < 85 {80 // #[clippy::format_args]81 // https://doc.rust-lang.org/1.85.1/clippy/attribs.html#clippyformat_args82 println!("cargo:rustc-cfg=anyhow_no_clippy_format_args");

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 83–85why, one step back
83 }
84}85

Merge pull request #337 from dtolnay/bootstrapDavid Tolnaybefore adoptionded2295

line 86why, one step back
86fn compile_probe(rustc_bootstrap: bool) -> bool {

Merge pull request #320 from RalfJung/bootstrapDavid Tolnaybefore adoption61d8676

line 87why, one step back
87 if env::var_os("RUSTC_STAGE").is_some() {

Reword bootstrap commentDavid Tolnaybefore adoption0798a9a

lines 88–94why, one step back
88 // We are running inside rustc bootstrap. This is a highly non-standard
89 // environment with issues such as:90 //91 // https://github.com/rust-lang/cargo/issues/1113892 // https://github.com/rust-lang/rust/issues/11483993 //94 // Let's just not use nightly features here.

Move ExitStatus::success check into compile_probe()David Tolnaybefore adoptiond10baed

line 95why, one step back
95 return false;

Merge pull request #320 from RalfJung/bootstrapDavid Tolnaybefore adoption61d8676

lines 96–97why, one step back
96 }
97

Merge pull request #335 from dtolnay/cargoenvvarDavid Tolnaybefore adoptioneb66ff5

lines 98–99why, one step back
98 let rustc = cargo_env_var("RUSTC");
99 let out_dir = cargo_env_var("OUT_DIR");

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

line 100why, one step back
100 let out_subdir = Path::new(&out_dir).join("probe");

Merge pull request #414 from dtolnay/nightlyDavid Tolnaybefore adoption213a9c2

line 101why, one step back
101 let probefile = Path::new("src").join("nightly.rs");

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 102why, one step back
102

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

lines 103–109why, one step back
103 if let Err(err) = fs::create_dir(&out_subdir) {
104 if err.kind() != ErrorKind::AlreadyExists {105 eprintln!("Failed to create {}: {}", out_subdir.display(), err);106 process::exit(1);107 }108 }109

Merge pull request #358 from dtolnay/workspacewrapperDavid Tolnaybefore adoption7a4cac5

lines 110–118why, one step back
110 let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty());
111 let rustc_workspace_wrapper =112 env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty());113 let mut rustc = rustc_wrapper114 .into_iter()115 .chain(rustc_workspace_wrapper)116 .chain(iter::once(rustc));117 let mut cmd = Command::new(rustc.next().unwrap());118 cmd.args(rustc);

Merge pull request #337 from dtolnay/bootstrapDavid Tolnaybefore adoptionded2295

lines 119–122why, one step back
119
120 if !rustc_bootstrap {121 cmd.env_remove("RUSTC_BOOTSTRAP");122 }

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 123–124why, one step back
123
124 cmd.stderr(Stdio::null())

Merge pull request #414 from dtolnay/nightlyDavid Tolnaybefore adoption213a9c2

line 125why, one step back
125 .arg("--cfg=anyhow_build_probe")

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 126why, one step back
126 .arg("--edition=2018")

Update crate name used for build script probeDavid Tolnaybefore adoption2d32366

line 127why, one step back
127 .arg("--crate-name=anyhow")

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 128why, one step back
128 .arg("--crate-type=lib")

Merge pull request #354 from dtolnay/deadcodeDavid Tolnaybefore adoption8be9091

line 129why, one step back
129 .arg("--cap-lints=allow")

Order cap-lints flag in the same order as thiserror build scriptDavid Tolnaybefore adoption4249254

line 130why, one step back
130 .arg("--emit=dep-info,metadata")

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 131why, one step back
131 .arg("--out-dir")

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

line 132why, one step back
132 .arg(&out_subdir)

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 133–147why, one step back
133 .arg(probefile);
134135 if let Some(target) = env::var_os("TARGET") {136 cmd.arg("--target").arg(target);137 }138139 // If Cargo wants to set RUSTFLAGS, use that.140 if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {141 if !rustflags.is_empty() {142 for arg in rustflags.split('\x1f') {143 cmd.arg(arg);144 }145 }146 }147

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

line 148why, one step back
148 let success = match cmd.status() {

Move ExitStatus::success check into compile_probe()David Tolnaybefore adoptiond10baed

lines 149–150why, one step back
149 Ok(status) => status.success(),
150 Err(_) => false,

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

lines 151–156why, one step back
151 };
152153 // Clean up to avoid leaving nondeterministic absolute paths in the dep-info154 // file in OUT_DIR, which causes nonreproducible builds in build systems155 // that treat the entire OUT_DIR as an artifact.156 if let Err(err) = fs::remove_dir_all(&out_subdir) {

Merge pull request #420 from dtolnay/enotemptyDavid Tolnaybefore adoption2c64c15

lines 157–166why, one step back
157 // libc::ENOTEMPTY
158 // Some filesystems (NFSv3) have timing issues under load where '.nfs*'159 // dummy files can continue to get created for a short period after the160 // probe command completes, breaking remove_dir_all.161 // To be replaced with ErrorKind::DirectoryNotEmpty (Rust 1.83+).162 const ENOTEMPTY: i32 = 39;163164 if !(err.kind() == ErrorKind::NotFound165 || (cfg!(target_os = "linux") && err.raw_os_error() == Some(ENOTEMPTY)))166 {

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

lines 167–169why, one step back
167 eprintln!("Failed to clean up {}: {}", out_subdir.display(), err);
168 process::exit(1);169 }

Move ExitStatus::success check into compile_probe()David Tolnaybefore adoptiond10baed

line 170why, one step back
170 }

Merge pull request #388 from dtolnay/outdirDavid Tolnaybefore adoption4986853

lines 171–172why, one step back
171
172 success

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 173–175why, one step back
173}
174175fn rustc_minor_version() -> Option<u32> {

RUSTC must be set by Cargo for build scriptDavid Tolnaybefore adoptionee41470

line 176why, one step back
176 let rustc = cargo_env_var("RUSTC");

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 177–183why, one step back
177 let output = Command::new(rustc).arg("--version").output().ok()?;
178 let version = str::from_utf8(&output.stdout).ok()?;179 let mut pieces = version.split('.');180 if pieces.next() != Some("rustc 1") {181 return None;182 }183 pieces.next()?.parse().ok()

Merge pull request #335 from dtolnay/cargoenvvarDavid Tolnaybefore adoptioneb66ff5

lines 184–193why, one step back
184}
185186fn cargo_env_var(key: &str) -> OsString {187 env::var_os(key).unwrap_or_else(|| {188 eprintln!(189 "Environment variable ${} is not set during execution of build script",190 key,191 );192 process::exit(1);193 })

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 194why, one step back
194}