Skip to content

Commit

Permalink
Update builtins (#69)
Browse files Browse the repository at this point in the history
* Update builtins

* Update CHANGELOG
  • Loading branch information
Jake-Shadle authored Apr 10, 2024
1 parent 811699a commit 4e0a840
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 46 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [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.
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<!-- markdownlint-disable no-inline-html first-line-heading -->

<div align="center">

# `⚙️ 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)
</div>
Expand All @@ -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};
Expand Down Expand Up @@ -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)
7 changes: 2 additions & 5 deletions src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
56 changes: 55 additions & 1 deletion src/targets/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down
122 changes: 85 additions & 37 deletions update/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<String, String> {
// Get the list of possible targets
let output = Command::new(&rustc)
.args(&["--print", "target-list"])
Expand Down Expand Up @@ -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(
"
Expand Down Expand Up @@ -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<String>) {
Expand Down Expand Up @@ -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<String, String> {
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);
}
}

0 comments on commit 4e0a840

Please sign in to comment.