Skip to content

Commit 26baf2c

Browse files
bors[bot]cr1901
andauthored
Merge #507
507: Emit code to bring generic module into scope when using `-g` option. r=adamgreig a=cr1901 The -g option emits a separate file called generic.rs to split the generic code from the peripherals. Right now the -g option requires a user to manually add something like the following lines to `lib.rs`: ```rust use generic::*; pub mod generic; ``` Otherwise compilation will fail with errors like the following: ```sh error[E0433]: failed to resolve: maybe a missing crate `FieldReader`? --> src\port_1_2\p2ifg.rs:111:25 | 111 | P2IFG2_R(crate::FieldReader::new(bits)) | ^^^^^^^^^^^ maybe a missing crate `FieldReader`? ``` This patch automates adding the above code. Co-authored-by: William D. Jones <[email protected]>
2 parents 843475e + cc3eef6 commit 26baf2c

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2626

2727
- Ignore default enumeratedValues.
2828

29+
- Bring `generic` module into scope in `lib.rs` when using `-g` option.
30+
2931
### Changed
3032

3133
- [breaking-change] remove `Variant<U, ENUM_A>`, use `Option<ENUM_A>` instead

src/generate/device.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ pub fn render(
146146
let generic_file = std::str::from_utf8(include_bytes!("generic.rs"))?;
147147
if generic_mod {
148148
writeln!(File::create("generic.rs")?, "{}", generic_file)?;
149+
150+
out.extend(quote! {
151+
#[allow(unused_imports)]
152+
use generic::*;
153+
#[doc="Common register and bit access and modify traits"]
154+
pub mod generic;
155+
});
149156
} else {
150157
let tokens = syn::parse_file(generic_file)?.into_token_stream();
151158

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
//!
2727
//! If the `--target` flag is omitted `svd2rust` assumes the target is the Cortex-M architecture.
2828
//!
29+
//! If using the `--generic_mod` option, the emitted `generic.rs` needs to be moved to `src`, and
30+
//! [`form`](https://github.com/djmcgill/form) commit fcb397a or newer is required for splitting
31+
//! the emitted `lib.rs`.
32+
//!
2933
//! ## target = cortex-m
3034
//!
3135
//! When targeting the Cortex-M architecture, `svd2rust` will generate three files in the current

0 commit comments

Comments
 (0)