From 4e53043395b747b267bee975080896fb781fe19f Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Fri, 18 Jul 2025 15:46:00 +0530 Subject: populate the target_config now before its usage and update the test accordingly --- src/bootstrap/src/core/builder/tests.rs | 2 ++ src/bootstrap/src/core/config/config.rs | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 51a90649692..7f0c6fbd854 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1638,6 +1638,7 @@ mod snapshot { .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 + [build] rustc 0 -> LldWrapper 1 [build] rustdoc 0 [doc] std 1 crates=[core] "); @@ -1653,6 +1654,7 @@ mod snapshot { .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 + [build] rustc 0 -> LldWrapper 1 [build] rustdoc 0 [doc] std 1 crates=[alloc,core] "); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 22a75183404..6e04f115424 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -942,6 +942,7 @@ impl Config { config.rust_profile_use = flags_rust_profile_use; config.rust_profile_generate = flags_rust_profile_generate; + config.apply_target_config(toml.target); config.apply_rust_config(toml.rust, flags_warnings); config.reproducible_artifacts = flags_reproducible_artifact; @@ -967,8 +968,6 @@ impl Config { config.apply_gcc_config(toml.gcc); - config.apply_target_config(toml.target); - match ccache { Some(StringOrBool::String(ref s)) => config.ccache = Some(s.to_string()), Some(StringOrBool::Bool(true)) => { -- cgit 1.4.1-3-g733a5 From a2586f0c801aa52150925b4a66a517b1ffe13ddd Mon Sep 17 00:00:00 2001 From: binarycat Date: Mon, 23 Jun 2025 12:50:18 -0500 Subject: tidy: running of eslint, tsc, and es-check are now an extra check --- src/bootstrap/src/core/config/flags.rs | 2 +- src/etc/completions/x.fish | 6 +- src/etc/completions/x.ps1 | 6 +- src/etc/completions/x.py.fish | 6 +- src/etc/completions/x.py.ps1 | 6 +- src/etc/completions/x.py.zsh | 6 +- src/etc/completions/x.zsh | 6 +- src/tools/tidy/src/ext_tool_checks.rs | 37 +++++- src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs | 141 +++++++++++++++++++++++ src/tools/tidy/src/lib.rs | 1 - src/tools/tidy/src/main.rs | 4 +- src/tools/tidy/src/rustdoc_js.rs | 101 ---------------- 12 files changed, 211 insertions(+), 111 deletions(-) create mode 100644 src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs delete mode 100644 src/tools/tidy/src/rustdoc_js.rs (limited to 'src/bootstrap') diff --git a/src/bootstrap/src/core/config/flags.rs b/src/bootstrap/src/core/config/flags.rs index 1547ca44494..31a427f9ffa 100644 --- a/src/bootstrap/src/core/config/flags.rs +++ b/src/bootstrap/src/core/config/flags.rs @@ -386,7 +386,7 @@ pub enum Subcommand { bless: bool, #[arg(long)] /// comma-separated list of other files types to check (accepts py, py:lint, - /// py:fmt, shell, shell:lint, cpp, cpp:fmt, spellcheck) + /// py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, spellcheck) /// /// Any argument can be prefixed with "auto:" to only run if /// relevant files are modified (eg. "auto:py"). diff --git a/src/etc/completions/x.fish b/src/etc/completions/x.fish index 28a228d5464..f4e7413ca53 100644 --- a/src/etc/completions/x.fish +++ b/src/etc/completions/x.fish @@ -299,7 +299,11 @@ complete -c x -n "__fish_x_using_subcommand doc" -l skip-std-check-if-no-downloa complete -c x -n "__fish_x_using_subcommand doc" -s h -l help -d 'Print help (see more with \'--help\')' complete -c x -n "__fish_x_using_subcommand test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r complete -c x -n "__fish_x_using_subcommand test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r -complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, shell:lint, cpp, cpp:fmt, spellcheck)' -r +<<<<<<< HEAD +complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, spellcheck)' -r +======= +complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck)' -r +>>>>>>> 98204a1f527 (bootstrap: js:es-lint was removed, remove it from the docs) complete -c x -n "__fish_x_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r complete -c x -n "__fish_x_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r complete -c x -n "__fish_x_using_subcommand test" -l run -d 'whether to execute run-* tests' -r diff --git a/src/etc/completions/x.ps1 b/src/etc/completions/x.ps1 index 0c9b3828273..fced6587d32 100644 --- a/src/etc/completions/x.ps1 +++ b/src/etc/completions/x.ps1 @@ -345,7 +345,11 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock { 'x;test' { [CompletionResult]::new('--test-args', '--test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)') [CompletionResult]::new('--compiletest-rustc-args', '--compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests') - [CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, shell:lint, cpp, cpp:fmt, spellcheck)') +<<<<<<< HEAD + [CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, spellcheck)') +======= + [CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck)') +>>>>>>> 98204a1f527 (bootstrap: js:es-lint was removed, remove it from the docs) [CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to') [CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode') [CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests') diff --git a/src/etc/completions/x.py.fish b/src/etc/completions/x.py.fish index 43ae7424e27..c80750111f7 100644 --- a/src/etc/completions/x.py.fish +++ b/src/etc/completions/x.py.fish @@ -299,7 +299,11 @@ complete -c x.py -n "__fish_x.py_using_subcommand doc" -l skip-std-check-if-no-d complete -c x.py -n "__fish_x.py_using_subcommand doc" -s h -l help -d 'Print help (see more with \'--help\')' complete -c x.py -n "__fish_x.py_using_subcommand test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r complete -c x.py -n "__fish_x.py_using_subcommand test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r -complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, shell:lint, cpp, cpp:fmt, spellcheck)' -r +<<<<<<< HEAD +complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, spellcheck)' -r +======= +complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck)' -r +>>>>>>> 98204a1f527 (bootstrap: js:es-lint was removed, remove it from the docs) complete -c x.py -n "__fish_x.py_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r complete -c x.py -n "__fish_x.py_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r complete -c x.py -n "__fish_x.py_using_subcommand test" -l run -d 'whether to execute run-* tests' -r diff --git a/src/etc/completions/x.py.ps1 b/src/etc/completions/x.py.ps1 index 4311e383d64..dfb6482b41c 100644 --- a/src/etc/completions/x.py.ps1 +++ b/src/etc/completions/x.py.ps1 @@ -345,7 +345,11 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock { 'x.py;test' { [CompletionResult]::new('--test-args', '--test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)') [CompletionResult]::new('--compiletest-rustc-args', '--compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests') - [CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, shell:lint, cpp, cpp:fmt, spellcheck)') +<<<<<<< HEAD + [CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, spellcheck)') +======= + [CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck)') +>>>>>>> 98204a1f527 (bootstrap: js:es-lint was removed, remove it from the docs) [CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to') [CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode') [CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests') diff --git a/src/etc/completions/x.py.zsh b/src/etc/completions/x.py.zsh index aff35b31e21..8ccc7a7091c 100644 --- a/src/etc/completions/x.py.zsh +++ b/src/etc/completions/x.py.zsh @@ -345,7 +345,11 @@ _arguments "${_arguments_options[@]}" : \ _arguments "${_arguments_options[@]}" : \ '*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS:_default' \ '*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS:_default' \ -'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, shell\:lint, cpp, cpp\:fmt, spellcheck)]:EXTRA_CHECKS:_default' \ +<<<<<<< HEAD +'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, cpp, cpp\:fmt, js, js\:lint, js\:typecheck, spellcheck)]:EXTRA_CHECKS:_default' \ +======= +'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, cpp, cpp\:fmt, js, js\:lint, js\:typecheck)]:EXTRA_CHECKS:_default' \ +>>>>>>> 98204a1f527 (bootstrap: js:es-lint was removed, remove it from the docs) '--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE:_default' \ '--pass=[force {check,build,run}-pass tests to this mode]:check | build | run:_default' \ '--run=[whether to execute run-* tests]:auto | always | never:_default' \ diff --git a/src/etc/completions/x.zsh b/src/etc/completions/x.zsh index 28ad00f3a0d..8c00abb7b21 100644 --- a/src/etc/completions/x.zsh +++ b/src/etc/completions/x.zsh @@ -345,7 +345,11 @@ _arguments "${_arguments_options[@]}" : \ _arguments "${_arguments_options[@]}" : \ '*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS:_default' \ '*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS:_default' \ -'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, shell\:lint, cpp, cpp\:fmt, spellcheck)]:EXTRA_CHECKS:_default' \ +<<<<<<< HEAD +'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, cpp, cpp\:fmt, js, js\:lint, js\:typecheck, spellcheck)]:EXTRA_CHECKS:_default' \ +======= +'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, cpp, cpp\:fmt, js, js\:lint, js\:typecheck)]:EXTRA_CHECKS:_default' \ +>>>>>>> 98204a1f527 (bootstrap: js:es-lint was removed, remove it from the docs) '--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE:_default' \ '--pass=[force {check,build,run}-pass tests to this mode]:check | build | run:_default' \ '--run=[whether to execute run-* tests]:auto | always | never:_default' \ diff --git a/src/tools/tidy/src/ext_tool_checks.rs b/src/tools/tidy/src/ext_tool_checks.rs index 381ea44fd46..03ed0b00f3e 100644 --- a/src/tools/tidy/src/ext_tool_checks.rs +++ b/src/tools/tidy/src/ext_tool_checks.rs @@ -25,6 +25,8 @@ use std::{fmt, fs, io}; use crate::CiInfo; +mod rustdoc_js; + const MIN_PY_REV: (u32, u32) = (3, 9); const MIN_PY_REV_STR: &str = "≥3.9"; @@ -46,12 +48,25 @@ pub fn check( root_path: &Path, outdir: &Path, ci_info: &CiInfo, + librustdoc_path: &Path, + tools_path: &Path, + src_path: &Path, bless: bool, extra_checks: Option<&str>, pos_args: &[String], bad: &mut bool, ) { - if let Err(e) = check_impl(root_path, outdir, ci_info, bless, extra_checks, pos_args) { + if let Err(e) = check_impl( + root_path, + outdir, + ci_info, + librustdoc_path, + tools_path, + src_path, + bless, + extra_checks, + pos_args, + ) { tidy_error!(bad, "{e}"); } } @@ -60,6 +75,9 @@ fn check_impl( root_path: &Path, outdir: &Path, ci_info: &CiInfo, + librustdoc_path: &Path, + tools_path: &Path, + src_path: &Path, bless: bool, extra_checks: Option<&str>, pos_args: &[String], @@ -108,6 +126,8 @@ fn check_impl( let shell_lint = extra_check!(Shell, Lint); let cpp_fmt = extra_check!(Cpp, Fmt); let spellcheck = extra_check!(Spellcheck, None); + let js_lint = extra_check!(Js, Lint); + let js_typecheck = extra_check!(Js, Typecheck); let mut py_path = None; @@ -275,6 +295,15 @@ fn check_impl( spellcheck_runner(&args)?; } + if js_lint { + rustdoc_js::lint(librustdoc_path, tools_path, src_path)?; + rustdoc_js::es_check(librustdoc_path)?; + } + + if js_typecheck { + rustdoc_js::typecheck(librustdoc_path)?; + } + Ok(()) } @@ -697,6 +726,7 @@ impl ExtraCheckArg { ExtraCheckLang::Py => ".py", ExtraCheckLang::Cpp => ".cpp", ExtraCheckLang::Shell => ".sh", + ExtraCheckLang::Js => ".js", ExtraCheckLang::Spellcheck => { return !crate::files_modified(ci_info, |s| { SPELLCHECK_DIRS.iter().any(|dir| Path::new(s).starts_with(dir)) @@ -717,6 +747,7 @@ impl ExtraCheckArg { ExtraCheckLang::Cpp => &[Fmt], ExtraCheckLang::Shell => &[Lint], ExtraCheckLang::Spellcheck => &[], + ExtraCheckLang::Js => &[Lint, Typecheck], }; supported_kinds.contains(&kind) } @@ -757,6 +788,7 @@ enum ExtraCheckLang { Shell, Cpp, Spellcheck, + Js, } impl FromStr for ExtraCheckLang { @@ -768,6 +800,7 @@ impl FromStr for ExtraCheckLang { "shell" => Self::Shell, "cpp" => Self::Cpp, "spellcheck" => Self::Spellcheck, + "js" => Self::Js, _ => return Err(ExtraCheckParseError::UnknownLang(s.to_string())), }) } @@ -777,6 +810,7 @@ impl FromStr for ExtraCheckLang { enum ExtraCheckKind { Lint, Fmt, + Typecheck, /// Never parsed, but used as a placeholder for /// langs that never have a specific kind. None, @@ -789,6 +823,7 @@ impl FromStr for ExtraCheckKind { Ok(match s { "lint" => Self::Lint, "fmt" => Self::Fmt, + "typecheck" => Self::Typecheck, _ => return Err(ExtraCheckParseError::UnknownKind(s.to_string())), }) } diff --git a/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs b/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs new file mode 100644 index 00000000000..24be26ffbd9 --- /dev/null +++ b/src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs @@ -0,0 +1,141 @@ +//! Tidy check to ensure that rustdoc templates didn't forget a `{# #}` to strip extra whitespace +//! characters. + +use std::ffi::OsStr; +use std::path::{Path, PathBuf}; +use std::process::Command; + +use ignore::DirEntry; + +use crate::walk::walk_no_read; + +fn rustdoc_js_files(librustdoc_path: &Path) -> Vec { + let mut files = Vec::new(); + walk_no_read( + &[&librustdoc_path.join("html/static/js")], + |path, is_dir| is_dir || path.extension().is_none_or(|ext| ext != OsStr::new("js")), + &mut |path: &DirEntry| { + files.push(path.path().into()); + }, + ); + return files; +} + +fn run_eslint(args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> { + let mut child = Command::new("npx") + .arg("eslint") + .arg("-c") + .arg(config_folder.join(".eslintrc.js")) + .args(args) + .spawn()?; + match child.wait() { + Ok(exit_status) => { + if exit_status.success() { + return Ok(()); + } + Err(super::Error::FailedCheck("eslint command failed")) + } + Err(error) => Err(super::Error::Generic(format!("eslint command failed: {error:?}"))), + } +} + +fn get_eslint_version_inner(global: bool) -> Option { + let mut command = Command::new("npm"); + command.arg("list").arg("--parseable").arg("--long").arg("--depth=0"); + if global { + command.arg("--global"); + } + let output = command.output().ok()?; + let lines = String::from_utf8_lossy(&output.stdout); + lines.lines().find_map(|l| l.split(':').nth(1)?.strip_prefix("eslint@")).map(|v| v.to_owned()) +} + +fn get_eslint_version() -> Option { + get_eslint_version_inner(false).or_else(|| get_eslint_version_inner(true)) +} + +pub(super) fn lint( + librustdoc_path: &Path, + tools_path: &Path, + src_path: &Path, +) -> Result<(), super::Error> { + let eslint_version_path = src_path.join("ci/docker/host-x86_64/tidy/eslint.version"); + let eslint_version = match std::fs::read_to_string(&eslint_version_path) { + Ok(version) => version.trim().to_string(), + Err(error) => { + eprintln!("failed to read `{}`: {error:?}", eslint_version_path.display()); + return Err(error.into()); + } + }; + // Having the correct `eslint` version installed via `npm` isn't strictly necessary, since we're invoking it via `npx`, + // but this check allows the vast majority that is not working on the rustdoc frontend to avoid the penalty of running + // `eslint` in tidy. See also: https://github.com/rust-lang/rust/pull/142851 + match get_eslint_version() { + Some(version) => { + if version != eslint_version { + // unfortunatly we can't use `Error::Version` here becuse `str::trim` isn't const and + // Version::required must be a static str + return Err(super::Error::Generic(format!( + "⚠️ Installed version of eslint (`{version}`) is different than the \ + one used in the CI (`{eslint_version}`)\n\ + You can install this version using `npm update eslint` or by using \ + `npm install eslint@{eslint_version}`\n +" + ))); + } + } + None => { + //eprintln!("`eslint` doesn't seem to be installed. Skipping tidy check for JS files."); + //eprintln!("You can install it using `npm install eslint@{eslint_version}`"); + return Err(super::Error::MissingReq( + "eslint", + "js lint checks", + Some(format!("You can install it using `npm install eslint@{eslint_version}`")), + )); + } + } + let files_to_check = rustdoc_js_files(librustdoc_path); + println!("Running eslint on rustdoc JS files"); + run_eslint(&files_to_check, librustdoc_path.join("html/static"))?; + + run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"))?; + run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"))?; + Ok(()) +} + +pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> { + // use npx to ensure correct version + let mut child = Command::new("npx") + .arg("tsc") + .arg("-p") + .arg(librustdoc_path.join("html/static/js/tsconfig.json")) + .spawn()?; + match child.wait() { + Ok(exit_status) => { + if exit_status.success() { + return Ok(()); + } + Err(super::Error::FailedCheck("tsc command failed")) + } + Err(error) => Err(super::Error::Generic(format!("tsc command failed: {error:?}"))), + } +} + +pub(super) fn es_check(librustdoc_path: &Path) -> Result<(), super::Error> { + let files_to_check = rustdoc_js_files(librustdoc_path); + // use npx to ensure correct version + let mut cmd = Command::new("npx"); + cmd.arg("es-check").arg("es2019"); + for f in files_to_check { + cmd.arg(f); + } + match cmd.spawn()?.wait() { + Ok(exit_status) => { + if exit_status.success() { + return Ok(()); + } + Err(super::Error::FailedCheck("es-check command failed")) + } + Err(error) => Err(super::Error::Generic(format!("es-check command failed: {error:?}"))), + } +} diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index ade4055b5bd..4db74cbf61c 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -178,7 +178,6 @@ pub mod mir_opt_tests; pub mod pal; pub mod rustdoc_css_themes; pub mod rustdoc_gui_tests; -pub mod rustdoc_js; pub mod rustdoc_json; pub mod rustdoc_templates; pub mod style; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 0f1116a632e..358a03dd18c 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -112,7 +112,6 @@ fn main() { check!(rustdoc_gui_tests, &tests_path); check!(rustdoc_css_themes, &librustdoc_path); check!(rustdoc_templates, &librustdoc_path); - check!(rustdoc_js, &librustdoc_path, &tools_path, &src_path); check!(rustdoc_json, &src_path, &ci_info); check!(known_bug, &crashes_path); check!(unknown_revision, &tests_path); @@ -181,6 +180,9 @@ fn main() { &root_path, &output_directory, &ci_info, + &librustdoc_path, + &tools_path, + &src_path, bless, extra_checks, pos_args diff --git a/src/tools/tidy/src/rustdoc_js.rs b/src/tools/tidy/src/rustdoc_js.rs deleted file mode 100644 index 5737fcbafc0..00000000000 --- a/src/tools/tidy/src/rustdoc_js.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! Tidy check to ensure that rustdoc templates didn't forget a `{# #}` to strip extra whitespace -//! characters. - -use std::ffi::OsStr; -use std::path::{Path, PathBuf}; -use std::process::Command; - -use ignore::DirEntry; - -use crate::walk::walk_no_read; - -fn run_eslint(args: &[PathBuf], config_folder: PathBuf, bad: &mut bool) { - let mut child = match Command::new("npx") - .arg("eslint") - .arg("-c") - .arg(config_folder.join(".eslintrc.js")) - .args(args) - .spawn() - { - Ok(child) => child, - Err(error) => { - *bad = true; - eprintln!("failed to run eslint: {error:?}"); - return; - } - }; - match child.wait() { - Ok(exit_status) => { - if exit_status.success() { - return; - } - eprintln!("eslint command failed"); - } - Err(error) => eprintln!("eslint command failed: {error:?}"), - } - *bad = true; -} - -fn get_eslint_version_inner(global: bool) -> Option { - let mut command = Command::new("npm"); - command.arg("list").arg("--parseable").arg("--long").arg("--depth=0"); - if global { - command.arg("--global"); - } - let output = command.output().ok()?; - let lines = String::from_utf8_lossy(&output.stdout); - lines.lines().find_map(|l| l.split(':').nth(1)?.strip_prefix("eslint@")).map(|v| v.to_owned()) -} - -fn get_eslint_version() -> Option { - get_eslint_version_inner(false).or_else(|| get_eslint_version_inner(true)) -} - -pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &mut bool) { - let eslint_version_path = src_path.join("ci/docker/host-x86_64/tidy/eslint.version"); - let eslint_version = match std::fs::read_to_string(&eslint_version_path) { - Ok(version) => version.trim().to_string(), - Err(error) => { - *bad = true; - eprintln!("failed to read `{}`: {error:?}", eslint_version_path.display()); - return; - } - }; - // Having the correct `eslint` version installed via `npm` isn't strictly necessary, since we're invoking it via `npx`, - // but this check allows the vast majority that is not working on the rustdoc frontend to avoid the penalty of running - // `eslint` in tidy. See also: https://github.com/rust-lang/rust/pull/142851 - match get_eslint_version() { - Some(version) => { - if version != eslint_version { - *bad = true; - eprintln!( - "⚠️ Installed version of eslint (`{version}`) is different than the \ - one used in the CI (`{eslint_version}`)", - ); - eprintln!( - "You can install this version using `npm update eslint` or by using \ - `npm install eslint@{eslint_version}`", - ); - return; - } - } - None => { - eprintln!("`eslint` doesn't seem to be installed. Skipping tidy check for JS files."); - eprintln!("You can install it using `npm install eslint@{eslint_version}`"); - return; - } - } - let mut files_to_check = Vec::new(); - walk_no_read( - &[&librustdoc_path.join("html/static/js")], - |path, is_dir| is_dir || path.extension().is_none_or(|ext| ext != OsStr::new("js")), - &mut |path: &DirEntry| { - files_to_check.push(path.path().into()); - }, - ); - println!("Running eslint on rustdoc JS files"); - run_eslint(&files_to_check, librustdoc_path.join("html/static"), bad); - - run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"), bad); - run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"), bad); -} -- cgit 1.4.1-3-g733a5 From 4ca5afdc7ac807da8e1beac0813515cc36ef1ac0 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Fri, 18 Jul 2025 17:09:29 +0530 Subject: add default_lld_opt_in_targets method and modified test accordingly add test for lld opt in and also add thread_local defined state to change opt in targets make the config lld test parameter smoother to work, and have no_llvm_config set even when target_config is not present --- src/bootstrap/src/core/builder/tests.rs | 25 +++++++++++++++++++++++-- src/bootstrap/src/core/config/toml/rust.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 7f0c6fbd854..81a526593b4 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -642,6 +642,7 @@ mod snapshot { }; use crate::core::builder::{Builder, Kind, StepDescription, StepMetadata}; use crate::core::config::TargetSelection; + use crate::core::config::toml::rust::with_lld_opt_in_targets; use crate::utils::cache::Cache; use crate::utils::helpers::get_host_target; use crate::utils::tests::{ConfigBuilder, TestCtx}; @@ -1638,12 +1639,33 @@ mod snapshot { .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 - [build] rustc 0 -> LldWrapper 1 [build] rustdoc 0 [doc] std 1 crates=[core] "); } + #[test] + fn test_lld_opt_in() { + let target: &'static str = Box::leak(Box::new(host_target())); + let slice: &'static [&'static str] = Box::leak(Box::new([target])); + + with_lld_opt_in_targets(slice, || { + let ctx = TestCtx::new(); + + insta::assert_snapshot!( + ctx.config("doc") + .path("core") + .override_target_no_std(&host_target()) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 0 -> LldWrapper 1 + [build] rustdoc 0 + [doc] std 1 crates=[core] + "); + }); + } + #[test] fn doc_library_no_std_target() { let ctx = TestCtx::new(); @@ -1654,7 +1676,6 @@ mod snapshot { .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 - [build] rustc 0 -> LldWrapper 1 [build] rustdoc 0 [doc] std 1 crates=[alloc,core] "); diff --git a/src/bootstrap/src/core/config/toml/rust.rs b/src/bootstrap/src/core/config/toml/rust.rs index 307aa52294b..60484ee9e90 100644 --- a/src/bootstrap/src/core/config/toml/rust.rs +++ b/src/bootstrap/src/core/config/toml/rust.rs @@ -410,6 +410,31 @@ pub(crate) fn validate_codegen_backends(backends: Vec, section: &str) -> backends } +#[cfg(not(test))] +fn default_lld_opt_in_targets() -> Vec { + vec!["x86_64-unknown-linux-gnu".to_string()] +} + +#[cfg(test)] +thread_local! { + static TEST_LLD_OPT_IN_TARGETS: std::cell::RefCell>> = std::cell::RefCell::new(None); +} + +#[cfg(test)] +fn default_lld_opt_in_targets() -> Vec { + TEST_LLD_OPT_IN_TARGETS.with(|cell| cell.borrow().clone()).unwrap_or_default() +} + +#[cfg(test)] +pub fn with_lld_opt_in_targets(targets: Vec, f: impl FnOnce() -> R) -> R { + TEST_LLD_OPT_IN_TARGETS.with(|cell| { + let prev = cell.replace(Some(targets)); + let result = f(); + cell.replace(prev); + result + }) +} + impl Config { pub fn apply_rust_config(&mut self, toml_rust: Option, warnings: Warnings) { let mut debug = None; @@ -609,12 +634,13 @@ impl Config { // thus, disabled // - similarly, lld will not be built nor used by default when explicitly asked not to, e.g. // when the config sets `rust.lld = false` - if self.host_target.triple == "x86_64-unknown-linux-gnu" && self.hosts == [self.host_target] + if default_lld_opt_in_targets().contains(&self.host_target.triple.to_string()) + && self.hosts == [self.host_target] { let no_llvm_config = self .target_config .get(&self.host_target) - .is_some_and(|target_config| target_config.llvm_config.is_none()); + .is_none_or(|target_config| target_config.llvm_config.is_none()); let enable_lld = self.llvm_from_ci || no_llvm_config; // Prefer the config setting in case an explicit opt-out is needed. self.lld_enabled = lld_enabled.unwrap_or(enable_lld); -- cgit 1.4.1-3-g733a5 From fb10084b84b23e042c8888490c771ae5a315cfab Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Mon, 21 Jul 2025 20:10:58 +0530 Subject: add test_lld_opt_in test --- src/bootstrap/src/core/builder/tests.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 81a526593b4..4cc57996f3f 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1646,22 +1646,15 @@ mod snapshot { #[test] fn test_lld_opt_in() { - let target: &'static str = Box::leak(Box::new(host_target())); - let slice: &'static [&'static str] = Box::leak(Box::new([target])); - - with_lld_opt_in_targets(slice, || { + with_lld_opt_in_targets(vec![host_target()], || { let ctx = TestCtx::new(); - insta::assert_snapshot!( - ctx.config("doc") - .path("core") - .override_target_no_std(&host_target()) + ctx.config("build") + .path("compiler") .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 0 -> LldWrapper 1 - [build] rustdoc 0 - [doc] std 1 crates=[core] "); }); } -- cgit 1.4.1-3-g733a5