-
Notifications
You must be signed in to change notification settings - Fork 174
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
Fix various cfg-related crimes #1774
Conversation
a212a56
to
1d3d2ad
Compare
868fcf3
to
52287f2
Compare
|
||
let values = boards.join(","); | ||
|
||
println!("cargo:rustc-check-cfg=cfg(target_board, values({values}))"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it took me a while to figure out what was going on here, but it's amazing
drv/stm32xx-sys-api/src/h7.rs
Outdated
#[cfg(feature = "h7b3")] | ||
OctoSpi1 = periph(Group::Ahb3, 14), // B3 only | ||
#[cfg(any(feature = "h743", feature = "h747", feature = "h753"))] | ||
#[cfg(any(feature = "h743", feature = "h753"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is any(feature = "h743", feature = "h753")
guaranteed to be true? Now that we've removed h7b3
support, h743
and h753
are the only remaining h7*
features, so I think we can remove this condition (and others below).
@@ -158,12 +151,9 @@ pub enum Peripheral { | |||
Swp = periph(Group::Apb1H, 2), | |||
Crsen = periph(Group::Apb1H, 1), | |||
|
|||
#[cfg(feature = "h7b3")] | |||
Dfsdm1 = periph(Group::Apb2, 30), // B3 differs from 43/47 | |||
|
|||
Hrtim = periph(Group::Apb2, 29), // 43/47 only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by the comments in this file – there are many lines which was 43/47 only
but aren't gated on h743
.
(we could also probably remove the references to the B3
and 47
more generally, since they're both unsupported)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines aren't consistently conditional because I felt the danger of having someone accidentally name a peripheral that isn't implemented on their chip was small. I would like to at least keep the comments; we could comment out the lines that are only on chips we don't support, if you'd prefer.
README.mkdn
Outdated
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g0b1.toml` - stm32g0b1 | ||
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g031.toml` - stm32g031-nucleo | ||
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g070.toml` - stm32g070-nucleo | ||
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g0b1.toml` - stm32g0b1-nucleo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming nit: should nucleo
be at the start or end? We have both stm32g0b1-nucleo
and nucleo-ih743zi2
board names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that the vendor consistently puts nucleo at the front of the name, so, that's an argument for consistently doing that too.
@@ -71,7 +71,6 @@ cfg_if::cfg_if! { | |||
target_board = "gimlet-d", | |||
target_board = "gimlet-e", | |||
target_board = "gimlet-f", | |||
target_board = "sidecar-a", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫡
task/power/src/main.rs
Outdated
target_board = "psc-b", | ||
target_board = "psc-c" | ||
), | ||
any(target_board = "psc-b", target_board = "psc-c"), | ||
path = "bsp/psc_abc.rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: rename to psc_bc.rs
now that rev A is gone?
Thanks for doing all of this cleanup! With the toolchain bump, do you see any changes to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
build/util/src/lib.rs
Outdated
let Ok(dirent) = dirent else { | ||
continue; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we maybe print a warning on weird/bad dir entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments passing by
); | ||
} | ||
boards.sort(); | ||
boards.dedup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Duplicates would probably be a mistake of some sort, maybe worth a warning print as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, is it even possible to get duplicates since we take only toml files' stems and don't do eg. lowercasing? Shouldn't all the file stems be necessarily unique?
Hrtim = periph(Group::Apb2, 29), // 43/47 only | ||
|
||
#[cfg(any(feature = "h743", feature = "h747", feature = "h757"))] | ||
#[cfg(feature = "h743")] | ||
Dfsdm1 = periph(Group::Apb2, 28), // 43/47 differ from B3 | ||
|
||
Sai3 = periph(Group::Apb2, 24), // 43/47 only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: There's a bunch of "B3 only" commented lines below: Are those now entirely unused?
EDIT: Specifically these are Usart10, Uart9, Dfsdm2, Dts, and Dac2.
I have not yet been able to test this. I'd be willing to remove the toolchain bump from this PR, but the changes may regress and I'd like to opt out of refixing them. |
52287f2
to
2e07a83
Compare
Okay, I have resuscitated this PR after getting distracted for several months. I've fixed some of the things people suggested (thanks folks!) and left a few for future work -- basically in cases where this seems like a big improvement over what we had before, and the further improvement would take thought. I'd appreciate a re-review; I've kept changes from code review at the top of the branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went in, looking for a new outlook to life and programming: Found only questions.
Joking aside, I have no right to say this but the changes look good to me.
); | ||
} | ||
boards.sort(); | ||
boards.dedup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, is it even possible to get duplicates since we take only toml files' stems and don't do eg. lowercasing? Shouldn't all the file stems be necessarily unique?
// (3417); on g031, this is 195.88 (196). | ||
// t_i2cclk this yields 1219.7 (1220); on g031, this is 195.88 | ||
// (196). Note that these numbers make assumptions about the | ||
// system's clocking and clock tree configuration; TODO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: What is the TODO here about exactly? Is it about finishing this comment or something code related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO is intended to be about the earlier part of the sentence: when visiting this file I noticed that it contains hardcoded assumptions about the system's clocking and clock tree configuration, which are under the control of the application main file. This should eventually be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, that explains it really well.
The code changes look good to me, but I'd still like to see before / after |
Agreed, will work on that today. I may also bump the compiler to a more recent version, since it's been months since I picked this one. If we're testing stackmargin anyway... |
@@ -0,0 +1,8 @@ | |||
# Board definitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a full list of "adding a new board" steps written down somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe we do. Eventually I'd like "add a file here" to be the whole list, but as you may have noticed, xtask flash and friends still have hardcoded match statements after this change. (I would love to fix that.)
Alright! I have pushed commits addressing most of the code review feedback. I have also bumped the toolchain rev to 2024-09-17, arbitrarily chosen as "the nightly that seemed to work and was closest to the date that I made the change." This corresponds to a post-1.82 version. I've done stackmargin testing on all production boards, though only one rev of each, due to hardware availability (and, frankly, time). Some stacks are up, many are down -- in general the code appears to have gotten a little tighter with the updated toolchain. The only problems I found were
So given that, how are people feeling about the change? |
349de39
to
174e864
Compare
Ugh Clippy has developed some new opinions about things. |
e3ecb11
to
cee048b
Compare
README.mkdn
Outdated
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g0b1.toml` - stm32g0b1 | ||
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g031.toml` - stm32g031-nucleo | ||
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g070.toml` - stm32g070-nucleo | ||
- `cargo xtask dist app/demo-stm32g0-nucleo/app-g0b1.toml` - stm32g0b1-nucleo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: app/demo-stm32g0-nucleo/app-g0b1.toml
was renamed to app/demo-stm32g0-nucleo/app-g0b1.toml.noworky
back in c12d361
These were named after the generic processor model, which isn't right.
This code can't be built, because we have no board support for PSC A anymore.
All of this code was statically unreachable and hasn't been built in... years, at this point. If we want it we can find it in version control.
There's no way to turn this on, so it definitely hasn't been tested in $PERIOD.
The trailing compile_error! will do fine, and this prevents it from matching on something that rustc thinks is a typo'd board name.
Jefe had a check that attempted to avoid building dump support on LPC55, but that check didn't work, because it was checking for the presence of one of our custom cfgs...but not doing the invocation in its build script that actually generates that cfg. rustc will start checking such things soon, which is how I found this.
This crate was generating code that required the _client crate_ to have certain features defined, which is almost certainly a mistake, since this crate has the same set of features. Changed to key off features in the code generator instead.
As of this commit, the following two classes of mistakes will be caught when using a recent rustc: 1. Detecting the armv6m, armv7m, or armv8m features without a build script that actually exposes them. 2. Misspelling a target_board.
We were apparently picking up this feature from a dep, which changed when I attempted a cargo update.
In the interest of not having to run around cleaning up every crate, I've adjusted the workspace lints to the least common denominator. This means one in particular -- clippy::wildcard_imports -- is no longer a warning. To avoid losing my progress on removing wildcard_imports, I've moved that into each fixed crate as a #![forbid].
Clippy gets mad about this now.
This commit contains some code changes that have to be made atomically with the toolchain, to avoid angering our warnings check in the build: - Removed now-stable asm_const feature - Fixed some addr_of instances that are now safe (woo!)
cee048b
to
a744383
Compare
The nightly toolchain started doing checking for cfgs on Sunday, so I bumped our toolchain revision locally to see what it'd find.
In short, it got big mad.
This PR fixes All The Things. The commits provide detailed descriptions, but here's a summary:
target_board
) now have to be defined somewhere. I've added aboards
directory containing (currently empty) config files per board. Any reference to atarget_board
without a corresponding file will now be treated as a typo.psc-a
andsidecar-a
boards, which saw firmware support ended a while ago, but were never fully removed from the code.traptrace
feature in Sidecar, which isn't actually in the Cargo.toml and thus can't be built.stm32xx-i2c
, which was attempting to key off oftarget_board
without actually exposing the cfg in its build script. Forgetting to do this is now a compiler warning.jefe
, which was attempting to key off ofarmv8m
without actually exposing the cfg in its build script. Also now a warning.build/i2c
to use its own features instead of generating code that tried to match on features in its clients, which was working by accident.In order to formally move us to a toolchain that prevents this from regressing, I had to do some small unrelated fixes, namely:
core::uXX::MAX
constants, which are deprecated now.derive
macros produced code the new compiler dislikes.syn
feature inderive-idol-err
, which had apparently been picking it up from some dependency.