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

Compile only needed esp-idf components #83

Closed
N3xed opened this issue Apr 12, 2022 · 5 comments · Fixed by #115
Closed

Compile only needed esp-idf components #83

N3xed opened this issue Apr 12, 2022 · 5 comments · Fixed by #115

Comments

@N3xed
Copy link
Collaborator

N3xed commented Apr 12, 2022

Currently, when compiling the esp-idf all components are compiled by cmake, but only for select components the bindings are generated (everything that is included in src/include/esp-idf/bindings.h). That is currently around 1k C-files, which @igrr estimated could be brought down to around 600.
This behavior is not that detrimental as recompiling the esp-idf is normally rare (e.g. on first build, after clean). (There is also currently a bug where changing the sdkconfig/sdkconfig.defaults does not cause an esp-idf recompilation.)
However, when frequently changing the sdkconfigs or switing MCU, etc. and especially for CI such an improvement would be nice indeed.

To fix this we need to pass a list of components to cmake so that it knows specifically which components to build. As a first approach, we can disable building all components for which no bindings are generated (I don't how many that is, though).

In the long term though, we should make this configurable (maybe with an approach like I suggested in #72) as the demand for more and more esp-idf components grows.

@ivmarkov
Copy link
Collaborator

In the long term though, we should make this configurable (maybe with an approach like I suggested in #72) as the demand for more and more esp-idf components grows.

The approach suggested in #72 might be a bit of an overkill, as it is addressing the problem of how do we compile and generate *-sys bindings for external (out-of-tree) components.

For "in-tree" components, that might be an overkill, especially given that we have like 70% of the solution already:

  • Look at EspIdfComponents and how it is used here, which is the CMake-first build.
  • All that we need is a similar env-var for native build, which is (a) first passed down to CMake and (b) after that is parsed with a very similar code to the above, so that the bindings are generated only for the components which had actually been build. It env var is empty, the code should compile and generate bindings for everything, of course.

From then on, everything is solved already - esp-idf-sys, but also esp-idf-hal and esp-idf-svc are sprinkled with "#ifdefs" using these component strings (they are passed as cfg flags to Rust), so that not just the unsafe wrappers in esp-idf-sys, but also the safe wrappers in esp-idf-svc and esp-idf-hal are conditionally compiled, depending on where the component was enabled or not.

@ivmarkov
Copy link
Collaborator

Just to note that this task became even easier recently, as we no longer have a hard-coded list of esp idf components. I'm instead enumerating the components by doing directory scans instead. This should also make the task for plugging custom components easier.

@N3xed
Copy link
Collaborator Author

N3xed commented May 11, 2022

Yup, I noticed it, just haven't gotten around to implementing it.
Thanks for the notice though.

@maximeborges
Copy link
Contributor

Regarding

(There is also currently a bug where changing the sdkconfig/sdkconfig.defaults does not cause an esp-idf recompilation.)

is there any solution?

@N3xed
Copy link
Collaborator Author

N3xed commented May 31, 2022

Regarding

(There is also currently a bug where changing the sdkconfig/sdkconfig.defaults does not cause an esp-idf recompilation.)

is there any solution?

This is fixed in master (see commit 468b792) but not in a release yet.

N3xed added a commit that referenced this issue Aug 2, 2022
Add `$ESP_IDF_COMPONENTS` and `esp_idf_components` configuration option that allow
to specify a list of esp-idf components to build. This list can be used to trim down the esp-idf
build and reduce compile time.
Only implemented for the native build driver.
Fixes #83
@N3xed N3xed closed this as completed in #115 Aug 2, 2022
N3xed added a commit that referenced this issue Aug 2, 2022
Add `$ESP_IDF_COMPONENTS` and `esp_idf_components` configuration option that allow
to specify a list of esp-idf components to build. This list can be used to trim down the esp-idf
build and reduce compile time.
Only implemented for the native build driver.
Fixes #83
JakobLachermeier pushed a commit to JakobLachermeier/esp-idf-sys that referenced this issue Aug 26, 2022
Add `$ESP_IDF_COMPONENTS` and `esp_idf_components` configuration option that allow
to specify a list of esp-idf components to build. This list can be used to trim down the esp-idf
build and reduce compile time.
Only implemented for the native build driver.
Fixes esp-rs#83
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 a pull request may close this issue.

3 participants