diff --git a/CHANGELOG.md b/CHANGELOG.md index d7a2f0f..7d58e7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Changed +- [PR#69](https://github.com/EmbarkStudios/cfg-expr/pull/67) updated the builtin target list to 1.77.2. + ## [0.15.7] - 2024-02-09 ### Changed - [PR#67](https://github.com/EmbarkStudios/cfg-expr/pull/67) updated the builtin target list to 1.76.0. diff --git a/README.md b/README.md index 35e1243..cb39588 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ + +
# `⚙️ cfg-expr` -**A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [Rust 1.75.0](https://forge.rust-lang.org/release/platform-support.html) are supported.** +**A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [1.77.2] are supported.** [![Build Status](https://github.com/EmbarkStudios/cfg-expr/workflows/CI/badge.svg)](https://github.com/EmbarkStudios/cfg-expr/actions?workflow=CI) [![Crates.io](https://img.shields.io/crates/v/cfg-expr.svg)](https://crates.io/crates/cfg-expr) [![Docs](https://docs.rs/cfg-expr/badge.svg)](https://docs.rs/cfg-expr) [![Minimum Stable Rust Version](https://img.shields.io/badge/Rust%20MSRV-1.70.0-blue?color=fc8d62&logo=rust)](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html) -[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.75.0-blue.svg)](https://forge.rust-lang.org/release/platform-support.html) +[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.77.2-blue.svg)](https://forge.rust-lang.org/release/platform-support.html) [![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md) [![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](https://embark.dev)
@@ -22,7 +24,7 @@ `cfg-expr` is a crate that can be used to parse and evaluate Rust `cfg()` expressions, both as declarable in Rust code itself, as well in cargo manifests' `[target.'cfg()'.dependencies]` sections. -It contains a list of all builtin targets known to rustc as of `1.75.0` that can be used to determine if a particular cfg expression is satisfiable. +It contains a list of all builtin targets known to rustc as of [1.77.2] that can be used to determine if a particular cfg expression is satisfiable. ```rust use cfg_expr::{targets::get_builtin_target_by_triple, Expression, Predicate}; @@ -107,3 +109,5 @@ at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. + +[1.77.2]: (https://forge.rust-lang.org/release/platform-support.html) diff --git a/src/targets.rs b/src/targets.rs index 1b8d5e2..cac98b1 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -368,12 +368,9 @@ pub fn get_builtin_target_by_triple(triple: &str) -> Option<&'static TargetInfo> } /// Retrieves the version of rustc for which the built-in targets were -/// retrieved from. Targets may be added and removed between different rustc -/// versions. +/// retrieved from. /// -/// ``` -/// assert_eq!("1.76.0", cfg_expr::targets::rustc_version()); -/// ``` +/// Targets may be added and removed between different rustc versions. pub fn rustc_version() -> &'static str { builtins::RUSTC_VERSION } diff --git a/src/targets/builtins.rs b/src/targets/builtins.rs index 273f36e..082a004 100644 --- a/src/targets/builtins.rs +++ b/src/targets/builtins.rs @@ -10,7 +10,7 @@ use super::*; -pub(crate) const RUSTC_VERSION: &str = "1.76.0"; +pub(crate) const RUSTC_VERSION: &str = "1.77.2"; pub const ALL_BUILTINS: &[TargetInfo] = &[ TargetInfo { @@ -234,6 +234,19 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_128_ptr, panic: Panic::abort, }, + TargetInfo { + triple: Triple::new_const("aarch64-unknown-illumos"), + os: Some(Os::illumos), + abi: None, + arch: Arch::aarch64, + env: None, + vendor: Some(Vendor::unknown), + families: Families::unix, + pointer_width: 64, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_128_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("aarch64-unknown-linux-gnu"), os: Some(Os::linux), @@ -1053,6 +1066,19 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("hexagon-unknown-none-elf"), + os: None, + abi: None, + arch: Arch::hexagon, + env: None, + vendor: Some(Vendor::unknown), + families: Families::new_const(&[]), + pointer_width: 32, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_ptr, + panic: Panic::abort, + }, TargetInfo { triple: Triple::new_const("i386-apple-ios"), os: Some(Os::ios), @@ -1937,6 +1963,19 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::new_const(&[]), panic: Panic::abort, }, + TargetInfo { + triple: Triple::new_const("riscv32im-risc0-zkvm-elf"), + os: Some(Os::zkvm), + abi: None, + arch: Arch::riscv32, + env: None, + vendor: Some(Vendor::risc0), + families: Families::new_const(&[]), + pointer_width: 32, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_ptr, + panic: Panic::abort, + }, TargetInfo { triple: Triple::new_const("riscv32im-unknown-none-elf"), os: None, @@ -1989,6 +2028,19 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("riscv32imafc-esp-espidf"), + os: Some(Os::espidf), + abi: None, + arch: Arch::riscv32, + env: Some(Env::newlib), + vendor: Some(Vendor::espressif), + families: Families::unix, + pointer_width: 32, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_ptr, + panic: Panic::abort, + }, TargetInfo { triple: Triple::new_const("riscv32imafc-unknown-none-elf"), os: None, @@ -3005,6 +3057,7 @@ impl super::Vendor { pub const nintendo: Vendor = Vendor::new_const("nintendo"); pub const nvidia: Vendor = Vendor::new_const("nvidia"); pub const pc: Vendor = Vendor::new_const("pc"); + pub const risc0: Vendor = Vendor::new_const("risc0"); pub const sony: Vendor = Vendor::new_const("sony"); pub const sun: Vendor = Vendor::new_const("sun"); pub const unikraft: Vendor = Vendor::new_const("unikraft"); @@ -3049,6 +3102,7 @@ impl super::Os { pub const watchos: Os = Os::new_const("watchos"); pub const windows: Os = Os::new_const("windows"); pub const xous: Os = Os::new_const("xous"); + pub const zkvm: Os = Os::new_const("zkvm"); } impl super::Family { diff --git a/update/src/main.rs b/update/src/main.rs index eb79139..6f392c6 100644 --- a/update/src/main.rs +++ b/update/src/main.rs @@ -1,22 +1,9 @@ use std::{fmt::Write, process::Command}; -fn real_main() -> Result<(), String> { - let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_owned()); - - // Get the rustc version - let output = Command::new(&rustc) - .arg("--version") - .output() - .map_err(|e| format!("failed to run rustc --version: {e}"))?; - - if !output.status.success() { - return Err(format!("rustc --version {}", output.status)); - } - - let version = String::from_utf8(output.stdout).unwrap(); - - let version = version.splitn(3, ' ').nth(1).unwrap(); +const BUILTINS: &str = "src/targets/builtins.rs"; +const README: &str = "README.md"; +fn assemble(version: &str, rustc: String) -> Result { // Get the list of possible targets let output = Command::new(&rustc) .args(&["--print", "target-list"]) @@ -53,12 +40,7 @@ fn real_main() -> Result<(), String> { ", ); - write!( - out, - "pub(crate) const RUSTC_VERSION: &str = \"{}\";", - version - ) - .unwrap(); + write!(out, "pub(crate) const RUSTC_VERSION: &str = \"{version}\";").unwrap(); out.push_str( " @@ -321,19 +303,7 @@ fn real_main() -> Result<(), String> { write_impls(&mut out, "Panic", panics); //write_impls(&mut out, "RelocationModel", relocation_models); - std::fs::write("src/targets/builtins.rs", out) - .map_err(|e| format!("failed to write target_list.rs: {e}"))?; - - let status = Command::new("rustfmt") - .args(&["--edition", "2018", "src/targets/builtins.rs"]) - .status() - .map_err(|e| format!("failed to run rustfmt: {e}"))?; - - if !status.success() { - return Err(format!("failed to successfully format: {status}")); - } - - Ok(()) + Ok(out) } fn write_impls(out: &mut String, typ: &'static str, builtins: Vec) { @@ -451,9 +421,87 @@ fn write_group_str<'a, T: 'a + GroupElement>( } } +fn read_rustc_version() -> Result<(String, String), String> { + let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_owned()); + + // Get the rustc version + let output = Command::new(&rustc) + .arg("--version") + .output() + .map_err(|e| format!("failed to run rustc --version: {e}"))?; + + if !output.status.success() { + return Err(format!("rustc --version {}", output.status)); + } + + let version = String::from_utf8(output.stdout).unwrap(); + + Ok((version.splitn(3, ' ').nth(1).unwrap().into(), rustc)) +} + +fn assemble_readme(rustc_version: &str) -> Result { + let rm = + std::fs::read_to_string(README).map_err(|e| format!("failed to read {README}: {e}"))?; + + let end = rm + .rfind("]:") + .ok_or_else(|| "failed to find rust version end".to_owned())?; + let start = rm[..end] + .rfind('[') + .ok_or_else(|| "failed to find rust version begin".to_owned())?; + + let old_version = &rm[start + 1..end]; + let replaced = rm.replace(old_version, rustc_version); + + Ok(replaced) +} + +fn finalize(builtins: String, readme: String) -> Result<(), String> { + std::fs::write(BUILTINS, builtins).map_err(|e| format!("failed to write {BUILTINS}: {e}"))?; + + let status = Command::new("rustfmt") + .args(&["--edition", "2018", "src/targets/builtins.rs"]) + .status() + .map_err(|e| format!("failed to run rustfmt: {e}"))?; + + if !status.success() { + return Err(format!("failed to successfully format: {status}")); + } + + std::fs::write(README, readme).map_err(|e| format!("failed to write {README}: {e}"))?; + Ok(()) +} + fn main() { - if let Err(ref e) = real_main() { - eprintln!("error: {}", e); + let (rustc_version, rustc) = match read_rustc_version() { + Ok(rv) => rv, + Err(err) => { + eprintln!("failed to read rustc version: {err}"); + std::process::exit(1); + } + }; + + let mut assembled = String::new(); + let mut readme = String::new(); + std::thread::scope(|s| { + s.spawn(|| match assemble(&rustc_version, rustc) { + Ok(ab) => assembled = ab, + Err(err) => { + eprintln!("error assembling {BUILTINS}: {err}"); + std::process::exit(1); + } + }); + s.spawn(|| match assemble_readme(&rustc_version) { + Ok(rm) => readme = rm, + Err(err) => { + eprintln!("error assembling {README}: {err}"); + std::process::exit(1); + } + }); + }); + + if let Err(err) = finalize(assembled, readme) { + eprintln!("{err}"); std::process::exit(1); } }