Skip to content

Commit f88b0de

Browse files
bors[bot]burrbull
andauthored
Merge #516
516: Config r=Emilgardis a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents d0e9e5f + 3a2ed1f commit f88b0de

File tree

10 files changed

+242
-179
lines changed

10 files changed

+242
-179
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525

2626
FEATURES: [""]
2727

28+
OPTIONS: [""]
29+
2830
include:
2931
# Test MSRV
3032
- rust: 1.40.0
@@ -37,7 +39,8 @@ jobs:
3739
VENDOR: RISC-V
3840
TARGET: x86_64-unknown-linux-gnu
3941
TRAVIS_OS_NAME: linux
40-
FEATURES: "strict,const-generic"
42+
FEATURES: "strict"
43+
OPTIONS: "--const_generic"
4144

4245
# Use nightly for architectures which don't support stable
4346
- rust: nightly
@@ -73,4 +76,4 @@ jobs:
7376
override: true
7477
components: rustfmt
7578
- name: Run CI script for ${{ matrix.VENDOR }} under ${{ matrix.rust }}
76-
run: TARGET=${{ matrix.TARGET }} VENDOR=${{ matrix.VENDOR }} TRAVIS_OS_NAME=${{ matrix.TRAVIS_OS_NAME }} FEATURES=${{ matrix.FEATURES }} bash ci/script.sh
79+
run: TARGET=${{ matrix.TARGET }} VENDOR=${{ matrix.VENDOR }} TRAVIS_OS_NAME=${{ matrix.TRAVIS_OS_NAME }} FEATURES=${{ matrix.FEATURES }} OPTIONS=${{ matrix.OPTIONS }} bash ci/script.sh

CHANGELOG.md

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

1010
### Changed
1111

12+
- options can be set now with `svd2rust.toml` config
13+
- option `ignore_groups` for optional disabling #506
14+
- [breaking-change] move `const_generic` from features to options
15+
- use `Config` to pass options over all render levels
1216
- Use register iterator from `svd-parser`
1317
- rm unneeded `core::convert::` prefix on `From`
1418

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ path = "src/main.rs"
3434
[dependencies]
3535
cast = "0.2"
3636
clap = "2.33"
37+
clap_conf = "0.1.5"
3738
env_logger = "~0.7"
3839
inflections = "1.1"
3940
log = { version = "~0.4", features = ["std"] }
@@ -52,4 +53,3 @@ features = ["full","extra-traits"]
5253

5354
[features]
5455
strict = ["svd-parser/strict"]
55-
const-generic = []

ci/script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_svd() {
1010
# NOTE we care about errors in svd2rust, but not about errors / warnings in rustfmt
1111
local cwd=$(pwd)
1212
pushd $td
13-
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust -i ${1}.svd
13+
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust -i $OPTIONS ${1}.svd
1414

1515
mv lib.rs src/lib.rs
1616

src/generate/device.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@ use quote::{quote, ToTokens};
44
use std::fs::File;
55
use std::io::Write;
66

7-
use crate::util::{self, ToSanitizedUpperCase};
7+
use crate::util::{self, Config, ToSanitizedUpperCase};
88
use crate::Target;
99
use anyhow::Result;
1010

1111
use crate::generate::{interrupt, peripheral};
1212

1313
/// Whole device generation
14-
pub fn render(
15-
d: &Device,
16-
target: Target,
17-
nightly: bool,
18-
generic_mod: bool,
19-
make_mod: bool,
20-
device_x: &mut String,
21-
) -> Result<TokenStream> {
14+
pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<TokenStream> {
2215
let mut out = TokenStream::new();
2316

2417
let commit_info = {
@@ -46,14 +39,14 @@ pub fn render(
4639
commit_info
4740
);
4841

49-
if target == Target::Msp430 {
42+
if config.target == Target::Msp430 {
5043
out.extend(quote! {
5144
#![feature(abi_msp430_interrupt)]
5245
});
5346
}
5447

5548
out.extend(quote! { #![doc = #doc] });
56-
if !make_mod {
49+
if !config.make_mod {
5750
out.extend(quote! {
5851
// Deny a subset of warnings
5952
#![deny(const_err)]
@@ -109,7 +102,7 @@ pub fn render(
109102

110103
let mut fields = TokenStream::new();
111104
let mut exprs = TokenStream::new();
112-
if target == Target::CortexM {
105+
if config.target == Target::CortexM {
113106
out.extend(quote! {
114107
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
115108
#[cfg(feature = "rt")]
@@ -133,7 +126,7 @@ pub fn render(
133126
}
134127
}
135128

136-
if target == Target::Msp430 {
129+
if config.target == Target::Msp430 {
137130
out.extend(quote! {
138131
// XXX: Are there any core peripherals, really? Requires bump of msp430 crate.
139132
// pub use msp430::peripheral::Peripherals as CorePeripherals;
@@ -145,10 +138,10 @@ pub fn render(
145138
}
146139

147140
let generic_file = std::str::from_utf8(include_bytes!("generic.rs"))?;
148-
if generic_mod {
141+
if config.generic_mod {
149142
writeln!(File::create("generic.rs")?, "{}", generic_file)?;
150143

151-
if !make_mod {
144+
if !config.make_mod {
152145
out.extend(quote! {
153146
#[allow(unused_imports)]
154147
use generic::*;
@@ -169,10 +162,10 @@ pub fn render(
169162
});
170163
}
171164

172-
out.extend(interrupt::render(target, &d.peripherals, device_x)?);
165+
out.extend(interrupt::render(config.target, &d.peripherals, device_x)?);
173166

174167
for p in &d.peripherals {
175-
if target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
168+
if config.target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
176169
// Core peripherals are handled above
177170
continue;
178171
}
@@ -181,7 +174,7 @@ pub fn render(
181174
p,
182175
&d.peripherals,
183176
&d.default_register_properties,
184-
nightly,
177+
config,
185178
)?);
186179

187180
if p.registers
@@ -206,7 +199,7 @@ pub fn render(
206199
}
207200

208201
let span = Span::call_site();
209-
let take = match target {
202+
let take = match config.target {
210203
Target::CortexM => Some(Ident::new("cortex_m", span)),
211204
Target::Msp430 => Some(Ident::new("msp430", span)),
212205
Target::RISCV => Some(Ident::new("riscv", span)),

0 commit comments

Comments
 (0)