diff --git a/Cargo.lock b/Cargo.lock index 0877d3302..25787d2b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1802,6 +1802,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "ruzstd" version = "0.7.2" @@ -2022,7 +2028,7 @@ dependencies = [ name = "sel4-bitfield-ops" version = "0.1.0" dependencies = [ - "rustc_version", + "rustversion", ] [[package]] @@ -2260,7 +2266,7 @@ name = "sel4-generate-target-specs" version = "0.1.0" dependencies = [ "clap", - "rustc_version", + "rustversion", "serde_json", ] @@ -2485,7 +2491,7 @@ name = "sel4-panicking" version = "0.1.0" dependencies = [ "cfg-if", - "rustc_version", + "rustversion", "sel4-immediate-sync-once-cell", "sel4-panicking-env", "unwinding", diff --git a/crates/sel4-generate-target-specs/Cargo.nix b/crates/sel4-generate-target-specs/Cargo.nix index 10fcd2e53..3bf9ed028 100644 --- a/crates/sel4-generate-target-specs/Cargo.nix +++ b/crates/sel4-generate-target-specs/Cargo.nix @@ -12,7 +12,7 @@ mk { inherit (versions) serde_json clap; }; build-dependencies = { - inherit (versions) rustc_version; + inherit (versions) rustversion; }; package.metadata.rust-analyzer = { rustc_private = true; diff --git a/crates/sel4-generate-target-specs/Cargo.toml b/crates/sel4-generate-target-specs/Cargo.toml index 9c99e52e5..9be77277b 100644 --- a/crates/sel4-generate-target-specs/Cargo.toml +++ b/crates/sel4-generate-target-specs/Cargo.toml @@ -24,4 +24,4 @@ clap = "4.4.6" serde_json = "1.0.87" [build-dependencies] -rustc_version = "0.4.0" +rustversion = "1.0.18" diff --git a/crates/sel4-generate-target-specs/build.rs b/crates/sel4-generate-target-specs/build.rs index 98c870d56..105587134 100644 --- a/crates/sel4-generate-target-specs/build.rs +++ b/crates/sel4-generate-target-specs/build.rs @@ -4,28 +4,18 @@ // SPDX-License-Identifier: BSD-2-Clause // -use core::cmp::Reverse; - -// Determine whether rustc includes https://github.com/rust-lang/rust/pull/122305 - fn main() { - let key = { - let version_meta = rustc_version::version_meta().unwrap(); - let semver = version_meta.semver; - let commit_date = order_date(version_meta.commit_date); - (semver.major, semver.minor, semver.patch, commit_date) - }; - let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned()))); - let target_spec_has_metadata = (1, 78, 0, order_date(Some("2024-03-15".to_owned()))); - if key >= check_cfg_required { - println!("cargo:rustc-check-cfg=cfg(target_spec_has_metadata)"); + let key = "target_spec_has_metadata"; + if rustversion::cfg!(any( + all(not(nightly), since(1.80)), + all(nightly, since(2024 - 05 - 05)) + )) { + println!("cargo:rustc-check-cfg=cfg({key})"); } - if key >= target_spec_has_metadata { - println!("cargo:rustc-cfg=target_spec_has_metadata"); + if rustversion::cfg!(any( + all(not(nightly), since(1.78)), + all(nightly, since(2024 - 03 - 15)) + )) { + println!("cargo:rustc-cfg={key}"); } } - -// no build date means more recent -fn order_date(date: Option) -> Reverse>> { - Reverse(date.map(Reverse)) -} diff --git a/crates/sel4-generate-target-specs/src/main.rs b/crates/sel4-generate-target-specs/src/main.rs index e554bce95..65f1e2359 100644 --- a/crates/sel4-generate-target-specs/src/main.rs +++ b/crates/sel4-generate-target-specs/src/main.rs @@ -257,7 +257,7 @@ impl Context { } fn builtin(triple: &str) -> Target { - #[cfg_attr(not(target_spec_has_metadata), allow(unused_mut))] + #[allow(unused_mut)] let mut target = Target::expect_builtin(&TargetTriple::from_triple(triple)); #[cfg(target_spec_has_metadata)] { diff --git a/crates/sel4-panicking/Cargo.nix b/crates/sel4-panicking/Cargo.nix index 36ea86f7d..cbe040efb 100644 --- a/crates/sel4-panicking/Cargo.nix +++ b/crates/sel4-panicking/Cargo.nix @@ -16,7 +16,7 @@ mk { ; }; build-dependencies = { - inherit (versions) rustc_version; + inherit (versions) rustversion; }; target."cfg(all(panic = \"unwind\", not(target_arch = \"arm\")))".dependencies = { unwinding = unwindingWith [ "personality" ]; diff --git a/crates/sel4-panicking/Cargo.toml b/crates/sel4-panicking/Cargo.toml index 42df92319..2d3f1adf8 100644 --- a/crates/sel4-panicking/Cargo.toml +++ b/crates/sel4-panicking/Cargo.toml @@ -25,7 +25,7 @@ sel4-immediate-sync-once-cell = { path = "../sel4-immediate-sync-once-cell" } sel4-panicking-env = { path = "env" } [build-dependencies] -rustc_version = "0.4.0" +rustversion = "1.0.18" [target."cfg(all(panic = \"unwind\", not(target_arch = \"arm\")))".dependencies.unwinding] version = "0.2.3" diff --git a/crates/sel4-panicking/build.rs b/crates/sel4-panicking/build.rs index 5ff5e56e6..7f4f06b84 100644 --- a/crates/sel4-panicking/build.rs +++ b/crates/sel4-panicking/build.rs @@ -4,36 +4,29 @@ // SPDX-License-Identifier: BSD-2-Clause // -use core::cmp::Reverse; - // Determine whether rustc includes the following changes: // - https://blog.rust-lang.org/2024/05/06/check-cfg.html // - https://github.com/rust-lang/rust/pull/121598 // - https://github.com/rust-lang/rust/pull/126732 fn main() { - let key = { - let version_meta = rustc_version::version_meta().unwrap(); - let semver = version_meta.semver; - let commit_date = order_date(version_meta.commit_date); - (semver.major, semver.minor, semver.patch, commit_date) - }; - let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned()))); - let unwind_intrinsic_renamed = (1, 78, 0, order_date(Some("2024-02-28".to_owned()))); - let panic_info_message_stabilized = (1, 81, 0, order_date(Some("2024-07-01".to_owned()))); - if key >= check_cfg_required { - println!("cargo:rustc-check-cfg=cfg(catch_unwind_intrinsic_still_named_try)"); + if rustversion::cfg!(any( + all(not(nightly), since(1.80)), + all(nightly, since(2024 - 05 - 05)) + )) { + println!("cargo:rustc-check-cfg=cfg(catch_unwind_intrinsic_so_named)"); println!("cargo:rustc-check-cfg=cfg(panic_info_message_stable)"); } - if key < unwind_intrinsic_renamed { - println!("cargo:rustc-cfg=catch_unwind_intrinsic_still_named_try"); + if rustversion::cfg!(any( + all(not(nightly), since(1.78)), + all(nightly, since(2024 - 02 - 28)) + )) { + println!("cargo:rustc-cfg=catch_unwind_intrinsic_so_named"); } - if key >= panic_info_message_stabilized { + if rustversion::cfg!(any( + all(not(nightly), since(1.81)), + all(nightly, since(2024 - 07 - 01)) + )) { println!("cargo:rustc-cfg=panic_info_message_stable"); } } - -// no build date means more recent -fn order_date(date: Option) -> Reverse>> { - Reverse(date.map(Reverse)) -} diff --git a/crates/sel4-panicking/src/lib.rs b/crates/sel4-panicking/src/lib.rs index 41b01af37..43bc96bee 100644 --- a/crates/sel4-panicking/src/lib.rs +++ b/crates/sel4-panicking/src/lib.rs @@ -124,10 +124,10 @@ fn do_panic(info: ExternalPanicInfo) -> ! { } cfg_if! { - if #[cfg(catch_unwind_intrinsic_still_named_try)] { - use core::intrinsics::r#try as catch_unwind_intrinsic; - } else { + if #[cfg(catch_unwind_intrinsic_so_named)] { use core::intrinsics::catch_unwind as catch_unwind_intrinsic; + } else { + use core::intrinsics::r#try as catch_unwind_intrinsic; } } diff --git a/crates/sel4/bitfield-ops/Cargo.nix b/crates/sel4/bitfield-ops/Cargo.nix index 6faedbead..06aeafef3 100644 --- a/crates/sel4/bitfield-ops/Cargo.nix +++ b/crates/sel4/bitfield-ops/Cargo.nix @@ -9,6 +9,6 @@ mk { package.name = "sel4-bitfield-ops"; build-dependencies = { - inherit (versions) rustc_version; + inherit (versions) rustversion; }; } diff --git a/crates/sel4/bitfield-ops/Cargo.toml b/crates/sel4/bitfield-ops/Cargo.toml index 30ff03652..f88aa9f4e 100644 --- a/crates/sel4/bitfield-ops/Cargo.toml +++ b/crates/sel4/bitfield-ops/Cargo.toml @@ -17,4 +17,4 @@ edition = "2021" license = "BSD-2-Clause" [build-dependencies] -rustc_version = "0.4.0" +rustversion = "1.0.18" diff --git a/crates/sel4/bitfield-ops/build.rs b/crates/sel4/bitfield-ops/build.rs index ea87b9449..f16f976de 100644 --- a/crates/sel4/bitfield-ops/build.rs +++ b/crates/sel4/bitfield-ops/build.rs @@ -4,24 +4,11 @@ // SPDX-License-Identifier: BSD-2-Clause // -use core::cmp::Reverse; - -// Determine whether rustc includes https://github.com/rust-lang/rust/pull/121598 - fn main() { - let key = { - let version_meta = rustc_version::version_meta().unwrap(); - let semver = version_meta.semver; - let commit_date = order_date(version_meta.commit_date); - (semver.major, semver.minor, semver.patch, commit_date) - }; - let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned()))); - if key >= check_cfg_required { + if rustversion::cfg!(any( + all(not(nightly), since(1.80)), + all(nightly, since(2024 - 05 - 05)) + )) { println!("cargo:rustc-check-cfg=cfg(kani)"); } } - -// no build date means more recent -fn order_date(date: Option) -> Reverse>> { - Reverse(date.map(Reverse)) -} diff --git a/hacking/cargo-manifest-management/direct-dependency-allow-list.toml b/hacking/cargo-manifest-management/direct-dependency-allow-list.toml index 9d03d2d35..d8c116cbf 100644 --- a/hacking/cargo-manifest-management/direct-dependency-allow-list.toml +++ b/hacking/cargo-manifest-management/direct-dependency-allow-list.toml @@ -54,6 +54,7 @@ riscv = "0.12.1" rsa = "0.9.6" rtcc = "0.3.2" rustc_version = "0.4.0" +rustversion = "1.0.18" rustls = "0.23.5" rustls-pemfile = "2.0.0" sbi = "0.2.0"