From 6a084267d08bb5022ac49f4d79a1d2b9a4fa41f9 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Wed, 25 Oct 2023 18:33:37 +0800 Subject: [PATCH] ubuntu 22 cryptonight use O2 --- Cargo.lock | 11 +++++++++++ Cargo.toml | 4 ++-- consensus/cryptonight-rs/Cargo.toml | 1 + consensus/cryptonight-rs/build.rs | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f10ab6b59..740089623f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1726,6 +1726,7 @@ dependencies = [ "bencher", "cc", "libc", + "os_info", "rustc-serialize", ] @@ -6507,6 +6508,16 @@ dependencies = [ "num-integer", ] +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log 0.4.17", + "winapi 0.3.9", +] + [[package]] name = "os_str_bytes" version = "6.4.1" diff --git a/Cargo.toml b/Cargo.toml index b8ae533527..f1b127da60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -551,5 +551,5 @@ starcoin-vm-runtime.debug = 1 [profile.release.package."*"] debug = false -[profile.release.package.cryptonight-rs] -opt-level = 2 +#[profile.release.package.cryptonight-rs] +#opt-level = 2 diff --git a/consensus/cryptonight-rs/Cargo.toml b/consensus/cryptonight-rs/Cargo.toml index b289793007..81314b6c34 100644 --- a/consensus/cryptonight-rs/Cargo.toml +++ b/consensus/cryptonight-rs/Cargo.toml @@ -4,6 +4,7 @@ name = "bench" [build-dependencies] cc = "1.0" +os_info = { version = "3", default-features = false } [dependencies] libc = { workspace = true } diff --git a/consensus/cryptonight-rs/build.rs b/consensus/cryptonight-rs/build.rs index 977c078237..85ee62a1eb 100644 --- a/consensus/cryptonight-rs/build.rs +++ b/consensus/cryptonight-rs/build.rs @@ -26,7 +26,22 @@ fn main() { config.flag("-maes").flag("-msse2"); } if target_os.contains("linux") || target_os.contains("macos") { - config.flag("-fexceptions").flag("-std=gnu99"); + let info = os_info::get(); + let opt_level = env::var("OPT_LEVEL").expect("fetching OPT_LEVEL"); + if info.os_type() == os_info::Type::Ubuntu + && info.version() == &os_info::Version::Custom("22.04".into()) + { + if opt_level == "3" { + config.flag("-O2").flag("-fexceptions").flag("-std=gnu99"); + } else { + config.flag("-fexceptions").flag("-std=gnu99"); + } + } else { + config + .flag("-Ofast") + .flag("-fexceptions") + .flag("-std=gnu99"); + } } config.compile("cryptonight"); }