Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include-compatible config flag #779

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [v0.31.2] - 2023-11-29

- Add `skip-crate-attributes` config flag
- Add iterators for register/cluster/field arrays
- Use parentheses instead of square brackets in docs for field arrays

Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Config {
pub atomics_feature: Option<String>,
pub generic_mod: bool,
pub make_mod: bool,
pub skip_crate_attributes: bool,
pub ignore_groups: bool,
pub keep_list: bool,
pub strict: bool,
Expand Down
35 changes: 19 additions & 16 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,31 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
}
};

let doc = format!(
"Peripheral access API for {0} microcontrollers \
(generated using svd2rust v{1}{commit_info})\n\n\
You can find an overview of the generated API [here].\n\n\
API features to be included in the [next] svd2rust \
release can be generated by cloning the svd2rust [repository], \
checking out the above commit, and running `cargo doc --open`.\n\n\
[here]: https://docs.rs/svd2rust/{1}/svd2rust/#peripheral-api\n\
[next]: https://github.com/rust-embedded/svd2rust/blob/master/CHANGELOG.md#unreleased\n\
[repository]: https://github.com/rust-embedded/svd2rust",
d.name.to_uppercase(),
env!("CARGO_PKG_VERSION"),
);

if config.target == Target::Msp430 {
out.extend(quote! {
#![feature(abi_msp430_interrupt)]
});
}

out.extend(quote! { #![doc = #doc] });
if !config.make_mod {
if !config.skip_crate_attributes {
let doc = format!(
"Peripheral access API for {0} microcontrollers \
(generated using svd2rust v{1}{commit_info})\n\n\
You can find an overview of the generated API [here].\n\n\
API features to be included in the [next] svd2rust \
release can be generated by cloning the svd2rust [repository], \
checking out the above commit, and running `cargo doc --open`.\n\n\
[here]: https://docs.rs/svd2rust/{1}/svd2rust/#peripheral-api\n\
[next]: https://github.com/rust-embedded/svd2rust/blob/master/CHANGELOG.md#unreleased\n\
[repository]: https://github.com/rust-embedded/svd2rust",
d.name.to_uppercase(),
env!("CARGO_PKG_VERSION"),
);

out.extend(quote! { #![doc = #doc] });
}

if !config.make_mod && !config.skip_crate_attributes {
out.extend(quote! {
// Explicitly allow a few warnings that may be verbose
#![allow(non_camel_case_types)]
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ fn run() -> Result<()> {
.action(ArgAction::SetTrue)
.help("Create mod.rs instead of lib.rs, without inner attributes"),
)
.arg(
Arg::new("skip_crate_attributes")
.long("skip-crate-attributes")
.alias("skip_crate_attributes")
.action(ArgAction::SetTrue)
.help("Do not generate crate attributes"),
)
.arg(
Arg::new("strict")
.long("strict")
Expand Down
Loading