Skip to content

feat(cargo): Set rustc-check-cfg for all config options #92

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ball-hayden
Copy link
Contributor

This squashes lint warnings for config options which are not currently enabled.

See https://doc.rust-lang.org/cargo/reference/build-scripts.html\#rustc-check-cfg

@ball-hayden
Copy link
Contributor Author

@d3zd3z thanks for your work so far on this.

May I request a review on this, please?

Copy link
Collaborator

@d3zd3z d3zd3z left a comment

Choose a reason for hiding this comment

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

Unfortunately, this only squashes some warnings from this lint, specifically settings that are possible in the current configuration, but are disabled. But configurations that don't apply will not be seen by this and will still generate warnings.

Aside from generating a list of all possible configs from all Kconfig files (including modules that aren't present), I don't really see a way to make this work, which is why my examples have just been suppressing the lint.

@ball-hayden
Copy link
Contributor Author

This is true.
It does feel like a step in the right direction, though?

@ball-hayden
Copy link
Contributor Author

I wonder if we could do something with kconfiglib similar to how the Doxygen extension works, so we could list all possible options.

I'll try to find some time to have a look into this.

@ball-hayden ball-hayden force-pushed the check-cfg branch 3 times, most recently from 227220c to 8ba2555 Compare April 20, 2025 16:00
@ball-hayden
Copy link
Contributor Author

@d3zd3z how do you feel about this as an approach?

This seems to work for my project - I'd be interested to know how CI fares.

I'm not entirely happy about having an intermediate JSON file, but struggling to think of other options that would produce the complete list we need.

@ball-hayden ball-hayden force-pushed the check-cfg branch 2 times, most recently from b32097a to d1957c9 Compare April 20, 2025 16:08
def main():
args = parse_args()

kconf = Kconfig(args.kconfig_file)
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 not familiar with this code from Zephyr. Will this visit all kconfig files, or just the ones that make sense for the current build. Specifically, I think we should try this with a test case of conditional code that references a config that isn't present in the builds we make, but is in the tree. Ideally, we would make sure this works for modules as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will this visit all kconfig files, or just the ones that make sense for the current build

My understanding is that this will pick up the applications "root" Kconfig file (i.e. the one in <appdir>/Kconfig, where it is defined), and follow any source/rsource commands from there.

So it's not loading everything that smells like a Kconfig file within the directory tree, but it will load all kconfig files that are rsourceed (the same as with Zephyr's normal build).

a test case of conditional code that references a config that isn't present in the builds we make, but is in the tree

I'm not sure I follow.
If it's loaded as part of the Kconfig tree, it is present? If it isn't part of the Kconfig tree, then it's not a valid option (and should be flagged as not available).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This squashes lint warnings for config options which are not
currently enabled.

See https://doc.rust-lang.org/cargo/reference/build-scripts.html\#rustc-check-cfg

Signed-off-by: Hayden Ball <[email protected]>
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.

2 participants