{"id":29210634,"url":"https://github.com/embarkstudios/cfg-expr","last_synced_at":"2025-07-02T21:07:21.807Z","repository":{"id":36946096,"uuid":"230005031","full_name":"EmbarkStudios/cfg-expr","owner":"EmbarkStudios","description":"A parser and evaluator for Rust cfg() expressions. Targets as of Rust 1.58.0 are supported.","archived":false,"fork":false,"pushed_at":"2025-05-16T06:44:47.000Z","size":352,"stargazers_count":41,"open_issues_count":2,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-26T20:40:59.917Z","etag":null,"topics":["rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EmbarkStudios.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-24T21:25:39.000Z","updated_at":"2025-05-16T06:44:51.000Z","dependencies_parsed_at":"2024-10-19T07:38:12.221Z","dependency_job_id":"d7217ddf-b857-4203-9d7d-e46b11d49625","html_url":"https://github.com/EmbarkStudios/cfg-expr","commit_stats":{"total_commits":158,"total_committers":12,"mean_commits":"13.166666666666666","dds":0.1708860759493671,"last_synced_commit":"4584e415143143c4f80501a68cbb0d2f76ececee"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":"EmbarkStudios/opensource-template","purl":"pkg:github/EmbarkStudios/cfg-expr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Fcfg-expr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Fcfg-expr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Fcfg-expr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Fcfg-expr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EmbarkStudios","download_url":"https://codeload.github.com/EmbarkStudios/cfg-expr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Fcfg-expr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263215299,"owners_count":23431895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust"],"created_at":"2025-07-02T21:07:21.064Z","updated_at":"2025-07-02T21:07:21.790Z","avatar_url":"https://github.com/EmbarkStudios.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable no-inline-html first-line-heading --\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n# `⚙️ cfg-expr`\n\n**A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [1.87.0] are supported.**\n\n[![Build Status](https://github.com/EmbarkStudios/cfg-expr/workflows/CI/badge.svg)](https://github.com/EmbarkStudios/cfg-expr/actions?workflow=CI)\n[![Crates.io](https://img.shields.io/crates/v/cfg-expr.svg)](https://crates.io/crates/cfg-expr)\n[![Docs](https://docs.rs/cfg-expr/badge.svg)](https://docs.rs/cfg-expr)\n[![Minimum Stable Rust Version](https://img.shields.io/badge/Rust%20MSRV-1.70.0-blue?color=fc8d62\u0026logo=rust)](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html)\n[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.87.0-blue.svg)](https://forge.rust-lang.org/release/platform-support.html)\n[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)\n[![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](https://embark.dev)\n\u003c/div\u003e\n\n## Alternatives\n\n- [cargo-platform](https://crates.io/crates/cargo-platform)\n- [parse_cfg](https://crates.io/crates/parse_cfg)\n\n## Usage\n\n`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.\n\nIt contains a list of all builtin targets known to rustc as of [1.87.0] that can be used to determine if a particular cfg expression is satisfiable.\n\n```rust\nuse cfg_expr::{targets::get_builtin_target_by_triple, Expression, Predicate};\n\nlet specific = Expression::parse(\n    r#\"all(\n        target_os = \"windows\",\n        target_arch = \"x86\",\n        windows,\n        target_env = \"msvc\",\n        target_feature = \"fxsr\",\n        target_feature = \"sse\",\n        target_feature = \"sse2\",\n        target_pointer_width = \"32\",\n        target_endian = \"little\",\n        not(target_vendor = \"uwp\"),\n        feature = \"cool_thing\",\n    )\"#,\n).unwrap();\n\n// cfg_expr includes a list of every builtin target in rustc\nlet x86_win = get_builtin_target_by_triple(\"i686-pc-windows-msvc\").unwrap();\nlet uwp_win = get_builtin_target_by_triple(\"i686-uwp-windows-msvc\").unwrap();\nlet mac = get_builtin_target_by_triple(\"x86_64-apple-darwin\").unwrap();\n\nlet avail_target_feats = [\"fxsr\", \"sse\", \"sse2\"];\n\n// This will satisfy all requirements\nassert!(specific.eval(|pred| {\n    match pred {\n        Predicate::Target(tp) =\u003e tp.matches(x86_win),\n        Predicate::TargetFeature(feat) =\u003e avail_target_feats.contains(feat),\n        Predicate::Feature(feat) =\u003e *feat == \"cool_thing\",\n        _ =\u003e false,\n    }\n}));\n\n// This will *not* satisfy the vendor predicate\nassert!(!specific.eval(|pred| {\n    match pred {\n        Predicate::Target(tp) =\u003e tp.matches(uwp_win),\n        Predicate::TargetFeature(feat) =\u003e avail_target_feats.contains(feat),\n        _ =\u003e false,\n    }\n}));\n\n// This will *not* satisfy the vendor, os, or env predicates\nassert!(!specific.eval(|pred| {\n    match pred {\n        Predicate::Target(tp) =\u003e tp.matches(mac),\n        Predicate::TargetFeature(feat) =\u003e avail_target_feats.contains(feat),\n        _ =\u003e false,\n    }\n}));\n```\n\n## Contributing\n\nWe welcome community contributions to this project.\n\nPlease read our [Contributor Guide](CONTRIBUTING.md) for more information on how to get started.\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n### Contribution\n\nUnless 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.\n\n[1.87.0]: (https://forge.rust-lang.org/release/platform-support.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembarkstudios%2Fcfg-expr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fembarkstudios%2Fcfg-expr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembarkstudios%2Fcfg-expr/lists"}