Skip to content

Config #516

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 6 commits into from
May 8, 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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:

FEATURES: [""]

OPTIONS: [""]

include:
# Test MSRV
- rust: 1.40.0
Expand All @@ -37,7 +39,8 @@ jobs:
VENDOR: RISC-V
TARGET: x86_64-unknown-linux-gnu
TRAVIS_OS_NAME: linux
FEATURES: "strict,const-generic"
FEATURES: "strict"
OPTIONS: "--const_generic"

# Use nightly for architectures which don't support stable
- rust: nightly
Expand Down Expand Up @@ -73,4 +76,4 @@ jobs:
override: true
components: rustfmt
- name: Run CI script for ${{ matrix.VENDOR }} under ${{ matrix.rust }}
run: TARGET=${{ matrix.TARGET }} VENDOR=${{ matrix.VENDOR }} TRAVIS_OS_NAME=${{ matrix.TRAVIS_OS_NAME }} FEATURES=${{ matrix.FEATURES }} bash ci/script.sh
run: TARGET=${{ matrix.TARGET }} VENDOR=${{ matrix.VENDOR }} TRAVIS_OS_NAME=${{ matrix.TRAVIS_OS_NAME }} FEATURES=${{ matrix.FEATURES }} OPTIONS=${{ matrix.OPTIONS }} bash ci/script.sh
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ path = "src/main.rs"
[dependencies]
cast = "0.2"
clap = "2.33"
clap_conf = "0.1.5"
env_logger = "~0.7"
inflections = "1.1"
log = { version = "~0.4", features = ["std"] }
Expand All @@ -52,4 +53,3 @@ features = ["full","extra-traits"]

[features]
strict = ["svd-parser/strict"]
const-generic = []
2 changes: 1 addition & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_svd() {
# NOTE we care about errors in svd2rust, but not about errors / warnings in rustfmt
local cwd=$(pwd)
pushd $td
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust -i ${1}.svd
RUST_BACKTRACE=1 $cwd/target/$TARGET/release/svd2rust -i $OPTIONS ${1}.svd

mv lib.rs src/lib.rs

Expand Down
31 changes: 12 additions & 19 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ use quote::{quote, ToTokens};
use std::fs::File;
use std::io::Write;

use crate::util::{self, ToSanitizedUpperCase};
use crate::util::{self, Config, ToSanitizedUpperCase};
use crate::Target;
use anyhow::Result;

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

/// Whole device generation
pub fn render(
d: &Device,
target: Target,
nightly: bool,
generic_mod: bool,
make_mod: bool,
device_x: &mut String,
) -> Result<TokenStream> {
pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<TokenStream> {
let mut out = TokenStream::new();

let commit_info = {
Expand Down Expand Up @@ -46,14 +39,14 @@ pub fn render(
commit_info
);

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

out.extend(quote! { #![doc = #doc] });
if !make_mod {
if !config.make_mod {
out.extend(quote! {
// Deny a subset of warnings
#![deny(const_err)]
Expand Down Expand Up @@ -109,7 +102,7 @@ pub fn render(

let mut fields = TokenStream::new();
let mut exprs = TokenStream::new();
if target == Target::CortexM {
if config.target == Target::CortexM {
out.extend(quote! {
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
#[cfg(feature = "rt")]
Expand All @@ -133,7 +126,7 @@ pub fn render(
}
}

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

let generic_file = std::str::from_utf8(include_bytes!("generic.rs"))?;
if generic_mod {
if config.generic_mod {
writeln!(File::create("generic.rs")?, "{}", generic_file)?;

if !make_mod {
if !config.make_mod {
out.extend(quote! {
#[allow(unused_imports)]
use generic::*;
Expand All @@ -169,10 +162,10 @@ pub fn render(
});
}

out.extend(interrupt::render(target, &d.peripherals, device_x)?);
out.extend(interrupt::render(config.target, &d.peripherals, device_x)?);

for p in &d.peripherals {
if target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
if config.target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
// Core peripherals are handled above
continue;
}
Expand All @@ -181,7 +174,7 @@ pub fn render(
p,
&d.peripherals,
&d.default_register_properties,
nightly,
config,
)?);

if p.registers
Expand All @@ -206,7 +199,7 @@ pub fn render(
}

let span = Span::call_site();
let take = match target {
let take = match config.target {
Target::CortexM => Some(Ident::new("cortex_m", span)),
Target::Msp430 => Some(Ident::new("msp430", span)),
Target::RISCV => Some(Ident::new("riscv", span)),
Expand Down
Loading