Skip to content

Commit

Permalink
Use rustversion instead of rustc_version crate
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Nov 11, 2024
1 parent f2f1394 commit dd23fa8
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 72 deletions.
12 changes: 9 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sel4-generate-target-specs/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-generate-target-specs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ clap = "4.4.6"
serde_json = "1.0.87"

[build-dependencies]
rustc_version = "0.4.0"
rustversion = "1.0.18"
32 changes: 11 additions & 21 deletions crates/sel4-generate-target-specs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}
2 changes: 1 addition & 1 deletion crates/sel4-generate-target-specs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
{
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-panicking/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-panicking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 14 additions & 21 deletions crates/sel4-panicking/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}
6 changes: 3 additions & 3 deletions crates/sel4-panicking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sel4/bitfield-ops/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
mk {
package.name = "sel4-bitfield-ops";
build-dependencies = {
inherit (versions) rustc_version;
inherit (versions) rustversion;
};
}
2 changes: 1 addition & 1 deletion crates/sel4/bitfield-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ edition = "2021"
license = "BSD-2-Clause"

[build-dependencies]
rustc_version = "0.4.0"
rustversion = "1.0.18"
21 changes: 4 additions & 17 deletions crates/sel4/bitfield-ops/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dd23fa8

Please sign in to comment.