From db9824713b9496c1767b9b7d52beeb74c04e449d Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Wed, 29 Nov 2023 16:59:10 +0200 Subject: [PATCH 1/2] Add `include-compatible` config flag When developing FPGA, code needs to be generated dynamically. Idiomatic way of doing it is using `include!` macro: https://doc.rust-lang.org/cargo/reference/build-script-examples.html#code-generation But top-level attributes can't be used with it: https://github.com/rust-lang/rfcs/issues/752 So I added a config flag that disables generation of all top-level attributes. --- CHANGELOG.md | 1 + src/config.rs | 1 + src/generate/device.rs | 35 +++++++++++++++++++---------------- src/main.rs | 7 +++++++ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 650f537f..c5b27894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [v0.31.2] - 2023-11-29 +- Add `include-compatible` config flag - Add iterators for register/cluster/field arrays - Use parentheses instead of square brackets in docs for field arrays diff --git a/src/config.rs b/src/config.rs index 29a95475..e64e47f2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,7 @@ pub struct Config { pub atomics_feature: Option, pub generic_mod: bool, pub make_mod: bool, + pub include_compatible: bool, pub ignore_groups: bool, pub keep_list: bool, pub strict: bool, diff --git a/src/generate/device.rs b/src/generate/device.rs index 36413f63..d3f47e42 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -29,28 +29,31 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Result<()> { .action(ArgAction::SetTrue) .help("Create mod.rs instead of lib.rs, without inner attributes"), ) + .arg( + Arg::new("include_compatible") + .long("include-compatible") + .alias("include_compatible") + .action(ArgAction::SetTrue) + .help("Do not generate top-level attributes to make it compatible with include! macro"), + ) .arg( Arg::new("strict") .long("strict") From cf16e8d4fc009eb5599d3211266398c6f8dc2056 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Wed, 29 Nov 2023 21:13:31 +0200 Subject: [PATCH 2/2] Rename to skip-crate-attributes --- CHANGELOG.md | 2 +- src/config.rs | 2 +- src/generate/device.rs | 4 ++-- src/main.rs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b27894..cfdffd28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [v0.31.2] - 2023-11-29 -- Add `include-compatible` config flag +- Add `skip-crate-attributes` config flag - Add iterators for register/cluster/field arrays - Use parentheses instead of square brackets in docs for field arrays diff --git a/src/config.rs b/src/config.rs index e64e47f2..c80dc561 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,7 +10,7 @@ pub struct Config { pub atomics_feature: Option, pub generic_mod: bool, pub make_mod: bool, - pub include_compatible: bool, + pub skip_crate_attributes: bool, pub ignore_groups: bool, pub keep_list: bool, pub strict: bool, diff --git a/src/generate/device.rs b/src/generate/device.rs index d3f47e42..b799b648 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -35,7 +35,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Result Result<()> { .help("Create mod.rs instead of lib.rs, without inner attributes"), ) .arg( - Arg::new("include_compatible") - .long("include-compatible") - .alias("include_compatible") + Arg::new("skip_crate_attributes") + .long("skip-crate-attributes") + .alias("skip_crate_attributes") .action(ArgAction::SetTrue) - .help("Do not generate top-level attributes to make it compatible with include! macro"), + .help("Do not generate crate attributes"), ) .arg( Arg::new("strict")