Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build-rs): Add the 'error' directive #14910

Merged
merged 8 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions crates/build-rs/src/allow_use.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/build-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ MSRV: Respected as of "#,
};
}

mod allow_use;
mod ident;

pub mod input;
Expand Down
33 changes: 13 additions & 20 deletions crates/build-rs/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
//!
//! Reference: <https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script>

use crate::{
allow_use,
ident::{is_ascii_ident, is_ident},
};
use crate::ident::{is_ascii_ident, is_ident};
use std::{ffi::OsStr, fmt::Display, fmt::Write, path::Path, str};

fn emit(directive: &str, value: impl Display) {
Expand Down Expand Up @@ -309,13 +306,11 @@ pub fn rustc_check_cfgs(keys: &[&str]) {
}
}

if allow_use::check_cfg() {
let mut directive = keys[0].to_string();
for key in &keys[1..] {
write!(directive, ", {key}").expect("writing to string should be infallible");
}
emit("rustc-check-cfg", format_args!("cfg({directive})"));
let mut directive = keys[0].to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much unrelated to the error directive and may have other impacts (which is extremely rare I also believe). While I am fine with each change in this PR, should they be broken down to multiple PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSRV for this crate is 1.81. check-cfg was added in 1.80. This would only be a concern if/when we drop the MSRV further.

for key in &keys[1..] {
write!(directive, ", {key}").expect("writing to string should be infallible");
}
emit("rustc-check-cfg", format_args!("cfg({directive})"));
}

/// Add to the list of expected config names that is used when checking the
Expand All @@ -339,17 +334,15 @@ pub fn rustc_check_cfg_values(key: &str, values: &[&str]) {
return;
}

if allow_use::check_cfg() {
let mut directive = format!("\"{}\"", values[0].escape_default());
for value in &values[1..] {
write!(directive, ", \"{}\"", value.escape_default())
.expect("writing to string should be infallible");
}
emit(
"rustc-check-cfg",
format_args!("cfg({key}, values({directive}))"),
);
let mut directive = format!("\"{}\"", values[0].escape_default());
for value in &values[1..] {
write!(directive, ", \"{}\"", value.escape_default())
.expect("writing to string should be infallible");
}
emit(
"rustc-check-cfg",
format_args!("cfg({key}, values({directive}))"),
);
}

/// The `rustc-env` instruction tells Cargo to set the given environment variable
Expand Down