-
Notifications
You must be signed in to change notification settings - Fork 126
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
Co-existence of old and legacy driver wrappers in downstream crates #313
Comments
Thanks for summarizing all the points! While not the root cause, i still would like to the gating at the bindgeh.h level. One example to do it with features would be to create different versions of bindgen.h and use them depending on what driver features are set on a esp-idf-sys level. Because if we do not create bindgen for old and new driver, its impossible to misuse them in a downstream wrapper since you ever get the new or the old one. I know that this would not solve the issue with external esp_idf_components that might relight on legacy drivers etc. I only think that could be an extra measure around the things you are proposing. |
Yes - as long as you shift the This would bind us forever with the "features" approach though. If we take the lighter-weight approach of "if you use the sys bindings, you are on your own what you do, be careful" (which anyways applies, right), we can remove the features at some point in time. |
Yeah that's why i thought we may could create some "user defined" kconfigs that would translate to rust cfg attributes. That way we don't need "rust features" and we would not need to split the bindgen.h into multiple files. And for example in a potential IDFv6 that has no legacy drivers we could drop them since not defined kconfigs are just ignored. E.g a IDV v6 driver could be included with cfg(any( all(adc_oneshoot, not (legacy_adc)), esp_idf_major >= 6)). |
First to elaborate about the features and what I mean that we should be probably minimalistic there: Assume we just want to release the new crates ASAP, and not wait on the ESP IDF issue to get resolved.
In one release iteration from now, we might get the
Please elaborate it the way I elaborated the other two solutions, with pros and cons, and ideally - comparing to the other two solutions in terms of development complexity, ergonomics for the end user and so on. Then we have a meaningful basis to discuss on. Because for the moment, I'm a bit in the dark how this solution would improve on the other two.
I'm not sure from where the need to split
=> Example with components and the ADC oneshot drivers:
=> Example with features and the ADC oneshot drivers:
... where |
In light of this issue - and if it does not get resolved soon - the scheme below is the only one I could come up with so as to workaround the issue with a minimal effort and a minimal cognitive load to the end user:
Necessary changes to the
esp-idf-sys
build systemesp-idf-sys
Cargo native build as follows:esp_idf_components
env var and cargo-metadata parameter, introduce a new value which is a "pseudo-component":default
esp_idf_components
env var is not specified, it is assumed to have a value of "default" (see below for the meaning of this value)esp_idf_components
env var IS specified, it is assumed (as it is right now) to contain a list of ESP IDF components, plus (and this is the new thing) optionally thedefault
valuedefault
value is contained inesp_idf_components
, it is first expanded to ALL ESP IDF components except the ones which designate "new" (non-legacy) driversdefault
"special" value to a list of components. Re-using the PIO-build hack of "traversing" all directories listed directly under the ESP IDF'scomponents
repo dir might work...default
special value is expanded and then its expansion is de-duplicated with whatever additional components the user has entered in theesp_idf_components
env var, build proceeds as usual (as it is today)Necessary changes to
esp-idf-hal
To comply with the "whole object file" style of linking described in the ESP IDF issue we have to keep the following invariant:
esp-idf-hal
has a wrapper for both a legacy XYZ driver, and a new XYZ driver, for any build configuration exactly one of these (or none of these) should be built. Where by "built" what we mean is that the other wrapper (or both) should be#ifndef
-ed out. I.e. under no circumstances we should generate the code for BOTH Rust driver wrappers. Either one, or the other, or none of them, but not both.esp-idf-hal
means that we need to keep the existing#[cfg(esp_idf_comp_XYZ)]
conditional for the new driver#[cfg(all(esp_idf_comp_driver, **not(esp_idf_comp_XYZ)**))]
(**
emphasis mine)Code in third party crates outside of
esp-idf-sys
should follow the same invariant so as to deal with the issue.How would the above ^^^ solve the problem
esp-idf-hal
does not build any new driver, ergo, no conflicts possibleesp_idf_components = default, esp_adc
), we would build BOTH the legacy and the new ESP IDF ADC oneshot drivers' C code, but will build only the new ADC oneshot Rust driver wrapper. This way, the legacy ADC C driver - even if present on the linker command line, will be pruned early, including its__attribute__((constructor))
constructor, which is causing us the headachesAlternative: doing it all with features
Rather than changing the
esp-idf-sys
build system from above, we can alternatively introduce a new cargo feature - inesp-idf-hal
- for each new driver that pops-up in ESP IDF and keep this list of new features growing ad-infinitum (or until the legacy driver is retired in - say - ESP IDF 6 or later). To elaborate:The above features would not be enabled by default.
new-adc-driver
feature enabled,esp-idf-hal
compiles the legacy ADC oneshot Rust wrapper (i.e. it needs#[cfg(all(not(feature = "new-adc-oneshot-driver"), esp_idf_comp_driver)]
- but only if thedriver
component is enabled of course)new-adc-driver
feature enabled,esp-idf-hal
compiles the new ADC oneshot Rust wrapper, and compiles-out the legacy one. The new oneshot Rust wrapper would only be compiled however if bothfeature ="new-adc-oneshot-driver"
andesp_idf_comp_esp_adc
is enabled.Pros:
esp-idf-sys
build are necessary. Might be a good short-term solution for the upcoming release of theesp-idf-*
cratesCons:
esp-idf-sys
)esp-idf-sys
directly should introduce their own similar feature-based scheme and should be carefully applying it, by understanding all the details elaborated here. In contrast, changing the build system ofesp-idf-sys
by extending with thedefault
pseudo-feature might result in a setup which is a tad easier to explain, and does not result in any new features.Cons of both approaches
For backwards compatibility, both approaches will keep the legacy drivers "enabled", and the new drivers disabled. Which in the long term is not ideal, as we expect folks to start using the new drivers.
But the current reality is, we have just one new driver - ADC oneshot, with possible another in the works (I2C). Everything else is legacy drivers.
The text was updated successfully, but these errors were encountered: