Skip to content

Emit code to bring generic module into scope when using -g option. #507

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

Merged
merged 2 commits into from
Apr 15, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Ignore default enumeratedValues.

- Bring `generic` module into scope in `lib.rs` when using `-g` option.

### Changed

- [breaking-change] remove `Variant<U, ENUM_A>`, use `Option<ENUM_A>` instead
Expand Down
7 changes: 7 additions & 0 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ pub fn render(
let generic_file = std::str::from_utf8(include_bytes!("generic.rs"))?;
if generic_mod {
writeln!(File::create("generic.rs")?, "{}", generic_file)?;

out.extend(quote! {
#[allow(unused_imports)]
use generic::*;
#[doc="Common register and bit access and modify traits"]
pub mod generic;
});
} else {
let tokens = syn::parse_file(generic_file)?.into_token_stream();

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
//!
//! If the `--target` flag is omitted `svd2rust` assumes the target is the Cortex-M architecture.
//!
//! If using the `--generic_mod` option, the emitted `generic.rs` needs to be moved to `src`, and
//! [`form`](https://github.com/djmcgill/form) commit fcb397a or newer is required for splitting
//! the emitted `lib.rs`.
//!
//! ## target = cortex-m
//!
//! When targeting the Cortex-M architecture, `svd2rust` will generate three files in the current
Expand Down