From 607497d57caf28c3d06adfdd5bca826e9c81205b Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 28 Apr 2024 14:44:30 +0200 Subject: [PATCH 1/5] Port print-cfg run-make to Rust-based rmake.rs --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/print-cfg/Makefile | 37 ------- tests/run-make/print-cfg/rmake.rs | 100 ++++++++++++++++++ tests/run-make/print-to-output/rmake.rs | 67 ++++++++++++ 4 files changed, 167 insertions(+), 38 deletions(-) delete mode 100644 tests/run-make/print-cfg/Makefile create mode 100644 tests/run-make/print-cfg/rmake.rs create mode 100644 tests/run-make/print-to-output/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1b560ee352c..a2179b895b3 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -219,7 +219,6 @@ run-make/prefer-rlib/Makefile run-make/pretty-print-to-file/Makefile run-make/pretty-print-with-dep-file/Makefile run-make/print-calling-conventions/Makefile -run-make/print-cfg/Makefile run-make/print-target-list/Makefile run-make/profile/Makefile run-make/prune-link-args/Makefile diff --git a/tests/run-make/print-cfg/Makefile b/tests/run-make/print-cfg/Makefile deleted file mode 100644 index 6b153e5b54e..00000000000 --- a/tests/run-make/print-cfg/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# needs-llvm-components: x86 arm - -include ../tools.mk - -all: default output_to_file - $(RUSTC) --target x86_64-pc-windows-gnu --print cfg | $(CGREP) windows - $(RUSTC) --target x86_64-pc-windows-gnu --print cfg | $(CGREP) x86_64 - $(RUSTC) --target i686-pc-windows-msvc --print cfg | $(CGREP) msvc - $(RUSTC) --target i686-apple-darwin --print cfg | $(CGREP) macos - $(RUSTC) --target i686-unknown-linux-gnu --print cfg | $(CGREP) gnu - $(RUSTC) --target arm-unknown-linux-gnueabihf --print cfg | $(CGREP) target_abi= - $(RUSTC) --target arm-unknown-linux-gnueabihf --print cfg | $(CGREP) eabihf - -output_to_file: - # Backend-independent, printed by rustc_driver_impl/src/lib.rs - $(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt - $(CGREP) windows < $(TMPDIR)/cfg.txt - - # Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs - $(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt - $(CGREP) dynamic-no-pic < $(TMPDIR)/relocation-models.txt - - # Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs - $(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt - $(CGREP) reference-types < $(TMPDIR)/target-features.txt - - # Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp - $(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt - $(CGREP) generic < $(TMPDIR)/target-cpus.txt - -ifdef IS_WINDOWS -default: - $(RUSTC) --print cfg | $(CGREP) windows -else -default: - $(RUSTC) --print cfg | $(CGREP) unix -endif diff --git a/tests/run-make/print-cfg/rmake.rs b/tests/run-make/print-cfg/rmake.rs new file mode 100644 index 00000000000..0f829c9a95f --- /dev/null +++ b/tests/run-make/print-cfg/rmake.rs @@ -0,0 +1,100 @@ +//! This checks the output of `--print=cfg` +//! +//! Specifically it checks that output is correctly formatted +//! (ie. no duplicated cfgs, values are between "", names are not). +//! +//! It also checks that some targets have the correct set cfgs. + +extern crate run_make_support; + +use std::collections::HashSet; +use std::ffi::OsString; +use std::io::BufRead; +use std::iter::FromIterator; + +use run_make_support::{rustc, tmp_dir}; + +fn main() { + check( + /*target*/ "x86_64-pc-windows-gnu", + /*includes*/ &["windows", "target_arch=\"x86_64\""], + /*disallow*/ &["unix"], + ); + check( + /*target*/ "i686-pc-windows-msvc", + /*includes*/ &["windows", "target_env=\"msvc\""], + /*disallow*/ &["unix"], + ); + check( + /*target*/ "i686-apple-darwin", + /*includes*/ &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""], + /*disallow*/ &["windows"], + ); + check( + /*target*/ "i686-unknown-linux-gnu", + /*includes*/ &["unix", "target_env=\"gnu\""], + /*disallow*/ &["windows"], + ); + check( + /*target*/ "arm-unknown-linux-gnueabihf", + /*includes*/ &["unix", "target_abi=\"eabihf\""], + /*disallow*/ &["windows"], + ); +} + +fn check(target: &str, includes: &[&str], disallow: &[&str]) { + fn _inner(output: &str, includes: &[&str], disallow: &[&str]) { + let mut found = HashSet::::new(); + let mut recorded = HashSet::::new(); + + for l in output.lines() { + assert!(l == l.trim()); + if let Some((left, right)) = l.split_once('=') { + assert!(right.starts_with("\"")); + assert!(right.ends_with("\"")); + assert!(!left.contains("\"")); + } else { + assert!(!l.contains("\"")); + } + + assert!(recorded.insert(l.to_string()), "duplicated: {}", &l); + assert!(!disallow.contains(&l), "found disallowed: {}", &l); + if includes.contains(&l) { + assert!(found.insert(l.to_string()), "duplicated (includes): {}", &l); + } + } + + let should_found = HashSet::::from_iter(includes.iter().map(|s| s.to_string())); + let diff: Vec<_> = should_found.difference(&found).collect(); + + assert!( + diff.is_empty(), + "expected: {:?}, found: {:?} (~ {:?})", + &should_found, + &found, + &diff + ); + } + + // --print=cfg + { + let output = rustc().target(target).print("cfg").run(); + + let stdout = String::from_utf8(output.stdout).unwrap(); + + _inner(&stdout, includes, disallow); + } + + // --print=cfg=PATH + { + let tmp_path = tmp_dir().join(format!("{target}.cfg")); + let mut print_arg = OsString::from("--print=cfg="); + print_arg.push(tmp_path.as_os_str()); + + let output = rustc().target(target).arg(print_arg).run(); + + let output = std::fs::read_to_string(&tmp_path).unwrap(); + + _inner(&output, includes, disallow); + } +} diff --git a/tests/run-make/print-to-output/rmake.rs b/tests/run-make/print-to-output/rmake.rs new file mode 100644 index 00000000000..91724b492f8 --- /dev/null +++ b/tests/run-make/print-to-output/rmake.rs @@ -0,0 +1,67 @@ +//! This checks the output of some `--print` options when +//! output to a file (instead of stdout) + +extern crate run_make_support; + +use std::ffi::OsString; + +use run_make_support::{rustc, target, tmp_dir}; + +fn main() { + // Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs + check( + /*target*/ &target(), + /*option*/ "relocation-models", + /*includes*/ &["dynamic-no-pic"], + ); + + // Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs + check( + /*target*/ "wasm32-unknown-unknown", + /*option*/ "target-features", + /*includes*/ &["reference-types"], + ); + + // Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp + check( + /*target*/ "wasm32-unknown-unknown", + /*option*/ "target-cpus", + /*includes*/ &["generic"], + ); +} + +fn check(target: &str, option: &str, includes: &[&str]) { + fn _inner(output: &str, includes: &[&str]) { + for i in includes { + assert!(output.contains(i), "output doesn't contains: {}", i); + } + } + + // --print={option} + let stdout = { + let output = rustc().target(target).print(option).run(); + + let stdout = String::from_utf8(output.stdout).unwrap(); + + _inner(&stdout, includes); + + stdout + }; + + // --print={option}=PATH + let output = { + let tmp_path = tmp_dir().join(format!("{option}.txt")); + let mut print_arg = OsString::from(format!("--print={option}=")); + print_arg.push(tmp_path.as_os_str()); + + let _output = rustc().target(target).arg(print_arg).run(); + + let output = std::fs::read_to_string(&tmp_path).unwrap(); + + _inner(&output, includes); + + output + }; + + assert_eq!(&stdout, &output); +} From 006c94cfa1a4658318f237d87afb2a4434d42b39 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 28 Apr 2024 17:17:18 +0200 Subject: [PATCH 2/5] Use named struct arguments instead of comment named args --- tests/run-make/print-cfg/rmake.rs | 66 ++++++++++++---------- tests/run-make/print-to-output/rmake.rs | 75 +++++++++++++------------ 2 files changed, 74 insertions(+), 67 deletions(-) diff --git a/tests/run-make/print-cfg/rmake.rs b/tests/run-make/print-cfg/rmake.rs index 0f829c9a95f..71db7b8a693 100644 --- a/tests/run-make/print-cfg/rmake.rs +++ b/tests/run-make/print-cfg/rmake.rs @@ -14,36 +14,42 @@ use run_make_support::{rustc, tmp_dir}; -fn main() { - check( - /*target*/ "x86_64-pc-windows-gnu", - /*includes*/ &["windows", "target_arch=\"x86_64\""], - /*disallow*/ &["unix"], - ); - check( - /*target*/ "i686-pc-windows-msvc", - /*includes*/ &["windows", "target_env=\"msvc\""], - /*disallow*/ &["unix"], - ); - check( - /*target*/ "i686-apple-darwin", - /*includes*/ &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""], - /*disallow*/ &["windows"], - ); - check( - /*target*/ "i686-unknown-linux-gnu", - /*includes*/ &["unix", "target_env=\"gnu\""], - /*disallow*/ &["windows"], - ); - check( - /*target*/ "arm-unknown-linux-gnueabihf", - /*includes*/ &["unix", "target_abi=\"eabihf\""], - /*disallow*/ &["windows"], - ); +struct PrintCfg { + target: &'static str, + includes: &'static [&'static str], + disallow: &'static [&'static str], } -fn check(target: &str, includes: &[&str], disallow: &[&str]) { - fn _inner(output: &str, includes: &[&str], disallow: &[&str]) { +fn main() { + check(PrintCfg { + target: "x86_64-pc-windows-gnu", + includes: &["windows", "target_arch=\"x86_64\""], + disallow: &["unix"], + }); + check(PrintCfg { + target: "i686-pc-windows-msvc", + includes: &["windows", "target_env=\"msvc\""], + disallow: &["unix"], + }); + check(PrintCfg { + target: "i686-apple-darwin", + includes: &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""], + disallow: &["windows"], + }); + check(PrintCfg { + target: "i686-unknown-linux-gnu", + includes: &["unix", "target_env=\"gnu\""], + disallow: &["windows"], + }); + check(PrintCfg { + target: "arm-unknown-linux-gnueabihf", + includes: &["unix", "target_abi=\"eabihf\""], + disallow: &["windows"], + }); +} + +fn check(PrintCfg { target, includes, disallow }: PrintCfg) { + fn check_(output: &str, includes: &[&str], disallow: &[&str]) { let mut found = HashSet::::new(); let mut recorded = HashSet::::new(); @@ -82,7 +88,7 @@ fn _inner(output: &str, includes: &[&str], disallow: &[&str]) { let stdout = String::from_utf8(output.stdout).unwrap(); - _inner(&stdout, includes, disallow); + check_(&stdout, includes, disallow); } // --print=cfg=PATH @@ -95,6 +101,6 @@ fn _inner(output: &str, includes: &[&str], disallow: &[&str]) { let output = std::fs::read_to_string(&tmp_path).unwrap(); - _inner(&output, includes, disallow); + check_(&output, includes, disallow); } } diff --git a/tests/run-make/print-to-output/rmake.rs b/tests/run-make/print-to-output/rmake.rs index 91724b492f8..8595a0c490b 100644 --- a/tests/run-make/print-to-output/rmake.rs +++ b/tests/run-make/print-to-output/rmake.rs @@ -7,31 +7,37 @@ use run_make_support::{rustc, target, tmp_dir}; -fn main() { - // Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs - check( - /*target*/ &target(), - /*option*/ "relocation-models", - /*includes*/ &["dynamic-no-pic"], - ); - - // Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs - check( - /*target*/ "wasm32-unknown-unknown", - /*option*/ "target-features", - /*includes*/ &["reference-types"], - ); - - // Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp - check( - /*target*/ "wasm32-unknown-unknown", - /*option*/ "target-cpus", - /*includes*/ &["generic"], - ); +struct Option<'a> { + target: &'a str, + option: &'static str, + includes: &'static [&'static str], } -fn check(target: &str, option: &str, includes: &[&str]) { - fn _inner(output: &str, includes: &[&str]) { +fn main() { + // Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs + check(Option { + target: &target(), + option: "relocation-models", + includes: &["dynamic-no-pic"], + }); + + // Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs + check(Option { + target: "wasm32-unknown-unknown", + option: "target-features", + includes: &["reference-types"], + }); + + // Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp + check(Option { + target: "wasm32-unknown-unknown", + option: "target-cpus", + includes: &["generic"], + }); +} + +fn check(args: Option) { + fn check_(output: &str, includes: &[&str]) { for i in includes { assert!(output.contains(i), "output doesn't contains: {}", i); } @@ -39,29 +45,24 @@ fn _inner(output: &str, includes: &[&str]) { // --print={option} let stdout = { - let output = rustc().target(target).print(option).run(); + let output = rustc().target(args.target).print(args.option).run(); - let stdout = String::from_utf8(output.stdout).unwrap(); - - _inner(&stdout, includes); - - stdout + String::from_utf8(output.stdout).unwrap() }; // --print={option}=PATH let output = { - let tmp_path = tmp_dir().join(format!("{option}.txt")); - let mut print_arg = OsString::from(format!("--print={option}=")); + let tmp_path = tmp_dir().join(format!("{}.txt", args.option)); + let mut print_arg = OsString::from(format!("--print={}=", args.option)); print_arg.push(tmp_path.as_os_str()); - let _output = rustc().target(target).arg(print_arg).run(); + let _output = rustc().target(args.target).arg(print_arg).run(); - let output = std::fs::read_to_string(&tmp_path).unwrap(); - - _inner(&output, includes); - - output + std::fs::read_to_string(&tmp_path).unwrap() }; + check_(&stdout, args.includes); + check_(&output, args.includes); + assert_eq!(&stdout, &output); } From f5b3b400f7c5f85d3e0a821d83f41b2b71985f9b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 10 Apr 2024 20:14:18 +0200 Subject: [PATCH 3/5] Inline `clipboard.svg` into CSS --- src/librustdoc/html/static/css/rustdoc.css | 12 +++++++++++- src/librustdoc/html/static/images/clipboard.svg | 1 - src/librustdoc/html/static_files.rs | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) delete mode 100644 src/librustdoc/html/static/images/clipboard.svg diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 74c9130fd77..6b0a9c91e6c 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1636,7 +1636,17 @@ a.tooltip:hover::after { } #copy-path::before { filter: var(--copy-path-img-filter); - content: url('clipboard-24048e6d87f63d07.svg'); + /* clipboard */ + content: url('data:image/svg+xml,\ +\ +\ +'); + width: 19px; + height: 18px; } #copy-path:hover::before { filter: var(--copy-path-img-hover-filter); diff --git a/src/librustdoc/html/static/images/clipboard.svg b/src/librustdoc/html/static/images/clipboard.svg deleted file mode 100644 index e437c83fb6b..00000000000 --- a/src/librustdoc/html/static/images/clipboard.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index d8874c2fda0..d78cf0a028a 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -100,7 +100,6 @@ pub(crate) fn for_each(f: impl Fn(&StaticFile) -> Result<(), E>) -> Result<() storage_js => "static/js/storage.js", scrape_examples_js => "static/js/scrape-examples.js", wheel_svg => "static/images/wheel.svg", - clipboard_svg => "static/images/clipboard.svg", copyright => "static/COPYRIGHT.txt", license_apache => "static/LICENSE-APACHE.txt", license_mit => "static/LICENSE-MIT.txt", From f780913c722a78ab87e3fea10af4b75c0e4c1b66 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 10 Apr 2024 20:29:15 +0200 Subject: [PATCH 4/5] Inline `wheel.svg` into CSS --- src/librustdoc/html/static/css/rustdoc.css | 15 ++++++++++++++- src/librustdoc/html/static/images/wheel.svg | 1 - src/librustdoc/html/static_files.rs | 1 - 3 files changed, 14 insertions(+), 3 deletions(-) delete mode 100644 src/librustdoc/html/static/images/wheel.svg diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 6b0a9c91e6c..887a5c39444 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1608,7 +1608,20 @@ a.tooltip:hover::after { font-size: 0; } #settings-menu > a:before { - content: url('wheel-63255fc4502dca9a.svg'); + /* Wheel */ + content: url('data:image/svg+xml,\ + '); width: 22px; height: 22px; } diff --git a/src/librustdoc/html/static/images/wheel.svg b/src/librustdoc/html/static/images/wheel.svg deleted file mode 100644 index ba30f13dd58..00000000000 --- a/src/librustdoc/html/static/images/wheel.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index d78cf0a028a..035376bace9 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -99,7 +99,6 @@ pub(crate) fn for_each(f: impl Fn(&StaticFile) -> Result<(), E>) -> Result<() src_script_js => "static/js/src-script.js", storage_js => "static/js/storage.js", scrape_examples_js => "static/js/scrape-examples.js", - wheel_svg => "static/images/wheel.svg", copyright => "static/COPYRIGHT.txt", license_apache => "static/LICENSE-APACHE.txt", license_mit => "static/LICENSE-MIT.txt", From 5a3509c2f47758cc714381bc2f2fa68583bd5a5a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 10 Apr 2024 20:36:02 +0200 Subject: [PATCH 5/5] Add some missing comments to describe what the inlined SVG is --- src/librustdoc/html/static/css/rustdoc.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 887a5c39444..80a4ea0424a 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1133,6 +1133,7 @@ so that we can apply CSS-filters to change the arrow color in themes */ .setting-check input:checked { background-color: var(--settings-input-color); border-width: 1px; + /* cross-mark image in the settings checkboxes */ content: url('data:image/svg+xml,\ \ '); @@ -1627,6 +1628,7 @@ a.tooltip:hover::after { } #sidebar-button > a:before { + /* sidebar resizer image */ content: url('data:image/svg+xml,\ \ @@ -1860,6 +1862,7 @@ However, it's not needed with smaller screen width because the doc/code block is /* sidebar button opens modal use hamburger button */ .src #sidebar-button > a:before, .sidebar-menu-toggle:before { + /* hamburger button image */ content: url('data:image/svg+xml,\ '); @@ -1873,6 +1876,7 @@ However, it's not needed with smaller screen width because the doc/code block is /* src sidebar button opens a folder view */ .src #sidebar-button > a:before { + /* folder image */ content: url('data:image/svg+xml,\ \