Skip to content
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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Fix various cfg-related crimes #1774

wants to merge 14 commits into from

Conversation

cbiffle
Copy link
Collaborator

@cbiffle cbiffle commented May 6, 2024

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:

  • Boards (as in target_board) now have to be defined somewhere. I've added a boards directory containing (currently empty) config files per board. Any reference to a target_board without a corresponding file will now be treated as a typo.
  • Renamed some boards that only mentioned their processor type and not the board itself.
  • Removed vestiges of the psc-a and sidecar-a boards, which saw firmware support ended a while ago, but were never fully removed from the code.
  • Removed the final bits of STM32H7B3 devel board support, something we haven't used in ~4 years at this point.
  • Removed dead code implementing a traptrace feature in Sidecar, which isn't actually in the Cargo.toml and thus can't be built.
  • Fixed stm32xx-i2c, which was attempting to key off of target_board without actually exposing the cfg in its build script. Forgetting to do this is now a compiler warning.
  • Fixed jefe, which was attempting to key off of armv8m without actually exposing the cfg in its build script. Also now a warning.
  • Fixed 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:

  • Stop using the core::uXX::MAX constants, which are deprecated now.
  • Bump a couple deps because their derive macros produced code the new compiler dislikes.
  • Add a missing syn feature in derive-idol-err, which had apparently been picking it up from some dependency.

These were named after the generic processor model, which isn't right.
@cbiffle cbiffle force-pushed the cbiffle/cfg-check branch 2 times, most recently from 09a9197 to 013ffeb Compare May 6, 2024 21:58
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.
@cbiffle cbiffle force-pushed the cbiffle/cfg-check branch 2 times, most recently from a212a56 to 1d3d2ad Compare May 6, 2024 22:16
@cbiffle cbiffle changed the title Cbiffle/cfg check Fix various cfg-related crimes May 6, 2024
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.
@cbiffle cbiffle marked this pull request as ready for review May 6, 2024 22:36
@cbiffle cbiffle requested review from flihp and labbott as code owners May 6, 2024 22:36
@cbiffle cbiffle requested a review from mkeeter May 6, 2024 22:36

let values = boards.join(",");

println!("cargo:rustc-check-cfg=cfg(target_board, values({values}))");
Copy link
Collaborator

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

#[cfg(feature = "h7b3")]
OctoSpi1 = periph(Group::Ahb3, 14), // B3 only
#[cfg(any(feature = "h743", feature = "h747", feature = "h753"))]
#[cfg(any(feature = "h743", feature = "h753"))]
Copy link
Collaborator

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
Copy link
Collaborator

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)

- `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
Copy link
Collaborator

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.

@@ -71,7 +71,6 @@ cfg_if::cfg_if! {
target_board = "gimlet-d",
target_board = "gimlet-e",
target_board = "gimlet-f",
target_board = "sidecar-a",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

target_board = "psc-b",
target_board = "psc-c"
),
any(target_board = "psc-b", target_board = "psc-c"),
path = "bsp/psc_abc.rs"
Copy link
Collaborator

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?

@mkeeter
Copy link
Collaborator

mkeeter commented May 7, 2024

Thanks for doing all of this cleanup!

With the toolchain bump, do you see any changes to stackmargin for our in-product images?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

Comment on lines +107 to +109
let Ok(dirent) = dirent else {
continue;
};
Copy link
Member

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?

Copy link
Contributor

@aapoalas aapoalas left a 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();
Copy link
Contributor

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?

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
Copy link
Contributor

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?

@cbiffle
Copy link
Collaborator Author

cbiffle commented May 7, 2024

With the toolchain bump, do you see any changes to stackmargin for our in-product images?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants