Skip to content

Commit abaf2e8

Browse files
committed
Auto merge of rust-lang#119027 - GuillaumeGomez:rollup-bcxuwn7, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - rust-lang#118644 (Add test for Apple's `-weak_framework` linker argument) - rust-lang#118828 (Remove dead codes in rustc_codegen_gcc) - rust-lang#118830 (Add support for `--env` on `tracked_env::var`) - rust-lang#119001 (rustdoc-search: remove parallel searchWords array) - rust-lang#119020 (remove `hex` dependency in bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4451777 + 6c50b61 commit abaf2e8

File tree

31 files changed

+263
-124
lines changed

31 files changed

+263
-124
lines changed

compiler/rustc_codegen_gcc/src/common.rs

-11
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ pub trait TypeReflection<'gcc, 'tcx> {
377377
fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
378378
fn is_u128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
379379

380-
fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
381-
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
382-
383380
fn is_vector(&self) -> bool;
384381
}
385382

@@ -464,14 +461,6 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
464461
self.unqualified() == cx.u128_type.unqualified()
465462
}
466463

467-
fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
468-
self.unqualified() == cx.context.new_type::<f32>()
469-
}
470-
471-
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
472-
self.unqualified() == cx.context.new_type::<f64>()
473-
}
474-
475464
fn is_vector(&self) -> bool {
476465
let mut typ = self.clone();
477466
loop {

compiler/rustc_codegen_gcc/src/context.rs

-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
2222
use crate::callee::get_fn;
2323
use crate::common::SignType;
2424

25-
#[derive(Clone)]
26-
pub struct FuncSig<'gcc> {
27-
pub params: Vec<Type<'gcc>>,
28-
pub return_type: Type<'gcc>,
29-
}
30-
3125
pub struct CodegenCx<'gcc, 'tcx> {
3226
pub check_overflow: bool,
3327
pub codegen_unit: &'tcx CodegenUnit<'tcx>,

compiler/rustc_expand/src/proc_macro_server.rs

+4
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ impl server::Types for Rustc<'_, '_> {
426426
}
427427

428428
impl server::FreeFunctions for Rustc<'_, '_> {
429+
fn injected_env_var(&mut self, var: &str) -> Option<String> {
430+
self.ecx.sess.opts.logical_env.get(var).cloned()
431+
}
432+
429433
fn track_env_var(&mut self, var: &str, value: Option<&str>) {
430434
self.sess()
431435
.env_depinfo

library/proc_macro/src/bridge/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ macro_rules! with_api {
5555
$m! {
5656
FreeFunctions {
5757
fn drop($self: $S::FreeFunctions);
58+
fn injected_env_var(var: &str) -> Option<String>;
5859
fn track_env_var(var: &str, value: Option<&str>);
5960
fn track_path(path: &str);
6061
fn literal_from_str(s: &str) -> Result<Literal<$S::Span, $S::Symbol>, ()>;

library/proc_macro/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,8 @@ pub mod tracked_env {
15031503
#[unstable(feature = "proc_macro_tracked_env", issue = "99515")]
15041504
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
15051505
let key: &str = key.as_ref();
1506-
let value = env::var(key);
1506+
let value = crate::bridge::client::FreeFunctions::injected_env_var(key)
1507+
.map_or_else(|| env::var(key), Ok);
15071508
crate::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok());
15081509
value
15091510
}

src/bootstrap/Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ dependencies = [
5555
"cmake",
5656
"fd-lock",
5757
"filetime",
58-
"hex",
5958
"home",
6059
"ignore",
6160
"junction",
@@ -313,12 +312,6 @@ version = "0.4.1"
313312
source = "registry+https://github.com/rust-lang/crates.io-index"
314313
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
315314

316-
[[package]]
317-
name = "hex"
318-
version = "0.4.3"
319-
source = "registry+https://github.com/rust-lang/crates.io-index"
320-
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
321-
322315
[[package]]
323316
name = "home"
324317
version = "0.5.4"

src/bootstrap/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ clap = { version = "4.4.7", default-features = false, features = ["std", "usage"
3939
clap_complete = "4.4.3"
4040
cmake = "0.1.38"
4141
filetime = "0.2"
42-
hex = "0.4"
4342
home = "0.5.4"
4443
ignore = "0.4.10"
4544
libc = "0.2.150"

src/bootstrap/src/core/build_steps/setup.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
22
use crate::t;
33
use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY;
4+
use crate::utils::helpers::hex_encode;
45
use crate::Config;
56
use sha2::Digest;
67
use std::env::consts::EXE_SUFFIX;
@@ -566,7 +567,7 @@ fn create_vscode_settings_maybe(config: &Config) -> io::Result<bool> {
566567
if let Ok(current) = fs::read_to_string(&vscode_settings) {
567568
let mut hasher = sha2::Sha256::new();
568569
hasher.update(&current);
569-
let hash = hex::encode(hasher.finalize().as_slice());
570+
let hash = hex_encode(hasher.finalize().as_slice());
570571
if hash == *current_hash {
571572
return Ok(true);
572573
} else if historical_hashes.contains(&hash.as_str()) {

src/bootstrap/src/core/download.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use std::{
1111
use build_helper::ci::CiEnv;
1212
use xz2::bufread::XzDecoder;
1313

14-
use crate::core::build_steps::llvm::detect_llvm_sha;
1514
use crate::core::config::RustfmtMetadata;
1615
use crate::utils::helpers::{check_run, exe, program_out_of_date};
16+
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
1717
use crate::{t, Config};
1818

1919
static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
@@ -345,7 +345,7 @@ impl Config {
345345
reader.consume(l);
346346
}
347347

348-
let checksum = hex::encode(hasher.finalize().as_slice());
348+
let checksum = hex_encode(hasher.finalize().as_slice());
349349
let verified = checksum == expected;
350350

351351
if !verified {

src/bootstrap/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use filetime::FileTime;
3434
use sha2::digest::Digest;
3535
use termcolor::{ColorChoice, StandardStream, WriteColor};
3636
use utils::channel::GitInfo;
37+
use utils::helpers::hex_encode;
3738

3839
use crate::core::builder;
3940
use crate::core::builder::Kind;
@@ -1871,7 +1872,7 @@ pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
18711872
hasher.update(status);
18721873
hasher.update(additional_input);
18731874

1874-
hex::encode(hasher.finalize().as_slice())
1875+
hex_encode(hasher.finalize().as_slice())
18751876
}
18761877

18771878
/// Ensures that the behavior dump directory is properly initialized.

src/bootstrap/src/tests/builder.rs

-16
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,6 @@ fn alias_and_path_for_library() {
156156
assert_eq!(first(cache.all::<doc::Std>()), &[doc_std!(A => A, stage = 0)]);
157157
}
158158

159-
#[test]
160-
fn test_beta_rev_parsing() {
161-
use crate::utils::helpers::extract_beta_rev;
162-
163-
// single digit revision
164-
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
165-
// multiple digits
166-
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
167-
// nightly channel (no beta revision)
168-
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
169-
// stable channel (no beta revision)
170-
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
171-
// invalid string
172-
assert_eq!(extract_beta_rev("invalid"), None);
173-
}
174-
175159
mod defaults {
176160
use super::{configure, first, run_build};
177161
use crate::core::builder::*;

src/bootstrap/src/tests/helpers.rs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use crate::utils::helpers::{extract_beta_rev, hex_encode, make};
2+
use std::{env, path::PathBuf};
3+
4+
#[test]
5+
fn test_make() {
6+
for (host, make_path) in vec![
7+
("dragonfly", PathBuf::from("gmake")),
8+
("netbsd", PathBuf::from("gmake")),
9+
("freebsd", PathBuf::from("gmake")),
10+
("openbsd", PathBuf::from("gmake")),
11+
("linux", PathBuf::from("make")),
12+
// for checking the default
13+
("_", PathBuf::from("make")),
14+
] {
15+
assert_eq!(make(host), make_path);
16+
}
17+
}
18+
19+
#[cfg(unix)]
20+
#[test]
21+
fn test_absolute_unix() {
22+
use crate::utils::helpers::absolute_unix;
23+
24+
// Test an absolute path
25+
let path = PathBuf::from("/home/user/file.txt");
26+
assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("/home/user/file.txt"));
27+
28+
// Test an absolute path with double leading slashes
29+
let path = PathBuf::from("//root//file.txt");
30+
assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("//root/file.txt"));
31+
32+
// Test a relative path
33+
let path = PathBuf::from("relative/path");
34+
assert_eq!(absolute_unix(&path).unwrap(), env::current_dir().unwrap().join("relative/path"));
35+
}
36+
37+
#[test]
38+
fn test_beta_rev_parsing() {
39+
// single digit revision
40+
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
41+
// multiple digits
42+
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
43+
// nightly channel (no beta revision)
44+
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
45+
// stable channel (no beta revision)
46+
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
47+
// invalid string
48+
assert_eq!(extract_beta_rev("invalid"), None);
49+
}
50+
51+
#[test]
52+
fn test_string_to_hex_encode() {
53+
let input_string = "Hello, World!";
54+
let hex_string = hex_encode(input_string);
55+
assert_eq!(hex_string, "48656c6c6f2c20576f726c6421");
56+
}

src/bootstrap/src/tests/setup.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use super::{RUST_ANALYZER_SETTINGS, SETTINGS_HASHES};
2+
use crate::utils::helpers::hex_encode;
23
use sha2::Digest;
34

45
#[test]
56
fn check_matching_settings_hash() {
67
let mut hasher = sha2::Sha256::new();
78
hasher.update(&RUST_ANALYZER_SETTINGS);
8-
let hash = hex::encode(hasher.finalize().as_slice());
9+
let hash = hex_encode(hasher.finalize().as_slice());
910
assert_eq!(
1011
&hash,
1112
SETTINGS_HASHES.last().unwrap(),

src/bootstrap/src/utils/helpers.rs

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use crate::LldMode;
2020

2121
pub use crate::utils::dylib::{dylib_path, dylib_path_var};
2222

23+
#[cfg(test)]
24+
#[path = "../tests/helpers.rs"]
25+
mod tests;
26+
2327
/// A helper macro to `unwrap` a result except also print out details like:
2428
///
2529
/// * The file/line of the panic
@@ -540,3 +544,11 @@ pub fn add_rustdoc_cargo_linker_args(
540544
cmd.env("RUSTDOCFLAGS", flags);
541545
}
542546
}
547+
548+
/// Converts `T` into a hexadecimal `String`.
549+
pub fn hex_encode<T>(input: T) -> String
550+
where
551+
T: AsRef<[u8]>,
552+
{
553+
input.as_ref().iter().map(|x| format!("{:02x}", x)).collect()
554+
}

0 commit comments

Comments
 (0)