From 17dc8aada3f68f632bd7463e60c4955a3b1dc42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 24 Jan 2025 21:20:24 +0100 Subject: [PATCH] WIP --- .github/workflows/check.yml | 4 +-- Cargo.lock | 64 +++++++++++++--------------------- Cargo.toml | 9 ++--- src/build.rs | 1 + src/pgo/optimize.rs | 5 ++- tests/integration/pgo.rs | 12 +++++-- tests/integration/utils/mod.rs | 9 +++++ 7 files changed, 50 insertions(+), 54 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 6fa1ef5..138b434 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust-version: [ 1.78.0, stable, beta, nightly ] + rust-version: [ 1.80.0, stable, beta, nightly ] steps: - name: Checkout sources uses: actions/checkout@v2 @@ -45,7 +45,7 @@ jobs: - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.78.0 + toolchain: 1.80.0 components: clippy, rustfmt, llvm-tools-preview - name: Build diff --git a/Cargo.lock b/Cargo.lock index c1e0c30..c46dc17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,17 +78,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "bitflags" version = "2.6.0" @@ -236,13 +225,11 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" dependencies = [ - "atty", - "lazy_static", - "winapi", + "windows-sys", ] [[package]] @@ -288,11 +275,17 @@ dependencies = [ "regex", ] +[[package]] +name = "env_home" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" + [[package]] name = "env_logger" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" dependencies = [ "anstream", "anstyle", @@ -334,29 +327,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "home" -version = "0.5.11" +name = "humansize" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" dependencies = [ - "windows-sys", + "libm", ] -[[package]] -name = "humansize" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" - [[package]] name = "humantime" version = "2.1.0" @@ -387,6 +365,12 @@ version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -641,12 +625,12 @@ dependencies = [ [[package]] name = "which" -version = "7.0.0" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9cad3279ade7346b96e38731a641d7343dd6a53d55083dd54eadfa5a1b38c6b" +checksum = "fb4a9e33648339dc1642b0e36e21b3385e6148e289226f657c809dee59df5028" dependencies = [ "either", - "home", + "env_home", "rustix", "winsafe", ] diff --git a/Cargo.toml b/Cargo.toml index 1360479..d10fc43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "cargo-pgo" version = "0.2.8" edition = "2021" -rust-version = "1.78.0" +rust-version = "1.80.0" description = "Cargo subcommand for optimizing Rust binaries with PGO and BOLT." repository = "https://github.com/kobzol/cargo-pgo" @@ -30,9 +30,9 @@ which = "7" clap = { version = "4.5", features = ["derive"] } log = "0.4" env_logger = "0.11" -colored = "2" +colored = "3" cargo_metadata = "0.19" -humansize = "1" +humansize = "2" semver = "1" tempfile = "3.14" regex = "1.11" @@ -42,6 +42,3 @@ walkdir = "2.5" shellwords = "1.1" blake3 = "1.4" version_check = "0.9" - -[dev-dependencies] -version_check = "0.9" diff --git a/src/build.rs b/src/build.rs index 7eeb9f3..fe95056 100644 --- a/src/build.rs +++ b/src/build.rs @@ -86,6 +86,7 @@ pub fn cargo_command_with_rustflags( env.insert("RUSTFLAGS".to_string(), existing_rustflags); } (false, _) => { + panic!("FOO"); // If there's no RUSTFLAGS, and Cargo doesn't support `--config` yet, just use // RUSTFLAGS. env.insert("RUSTFLAGS".to_string(), serialized_rustflags); diff --git a/src/pgo/optimize.rs b/src/pgo/optimize.rs index 2e772f6..d775109 100644 --- a/src/pgo/optimize.rs +++ b/src/pgo/optimize.rs @@ -5,8 +5,7 @@ use anyhow::anyhow; use cargo_metadata::diagnostic::DiagnosticLevel; use cargo_metadata::{CompilerMessage, Message}; use colored::Colorize; -use humansize::file_size_opts::BINARY; -use humansize::FileSize; +use humansize::{format_size, BINARY}; use once_cell::sync::OnceCell; use regex::Regex; use rustc_demangle::{demangle, Demangle}; @@ -153,7 +152,7 @@ fn print_pgo_profile_stats(stats: &ProfileStats, pgo_dir: &Path) -> anyhow::Resu } else { "file" }, - stats.total_size.file_size(BINARY).unwrap().yellow(), + format_size(stats.total_size, BINARY).yellow(), cli_format_path(pgo_dir.display()) ); Ok(()) diff --git a/tests/integration/pgo.rs b/tests/integration/pgo.rs index a60e198..456cd57 100644 --- a/tests/integration/pgo.rs +++ b/tests/integration/pgo.rs @@ -325,10 +325,16 @@ rustflags = ["-Ctarget-cpu=native"] ), ); + eprintln!("{}", &format!( + r#" +[target.{}] +rustflags = ["-Ctarget-cpu=native"] +"#, + target + )); let output = project.cmd(&["build", "--", "-v"]).run()?; - println!("{}", output.stderr()); - assert!(output.stderr().contains("-Ctarget-cpu=native")); - assert!(output.stderr().contains("-Cprofile-generate")); + output.assert_stderr_contains("-Ctarget-cpu=native"); + output.assert_stderr_contains("-Cprofile-generate"); output.assert_ok(); Ok(()) diff --git a/tests/integration/utils/mod.rs b/tests/integration/utils/mod.rs index 7a2ed1f..ed1423b 100644 --- a/tests/integration/utils/mod.rs +++ b/tests/integration/utils/mod.rs @@ -167,6 +167,8 @@ pub trait OutputExt { fn assert_ok(self) -> Self; fn assert_error(self) -> Self; + fn assert_stderr_contains(&self, needle: &str); + fn stdout(&self) -> String; fn stderr(&self) -> String; } @@ -190,6 +192,13 @@ impl OutputExt for Output { self } + fn assert_stderr_contains(&self, needle: &str) { + let stderr = self.stderr(); + if !stderr.contains(needle) { + panic!("STDERR\n{stderr}\nDOES NOT CONTAIN\n{needle}"); + } + } + fn stdout(&self) -> String { String::from_utf8_lossy(&self.stdout).to_string() }