esp-rs / embuild

Build support for embedded Rust: Cargo integration with other embedded build ecosystems & tools, like PlatformIO, CMake and kconfig.
Apache License 2.0
135 stars 38 forks source link

Conditional compilation issue in mixed Rust/C project #71

Closed Narukara closed 1 year ago

Narukara commented 1 year ago

I created a project according to the instructions in https://github.com/esp-rs/esp-idf-template/blob/master/README-cmake.md. It's a mixed Rust/C ESP-IDF project driven by idf.py and CMake.

Then I found that I could not use some mods such as esp_idf_svc::netif. And this is because embuild did not provide some necessary cfg conditions in the build script build.rs.

For example, esp_idf_svc::netif requires the condition esp_idf_comp_esp_netif_enabled:

// from esp-idf-svc/src/lib.rs
#[cfg(all(feature = "alloc", esp_idf_comp_esp_netif_enabled))]
pub mod netif;

And embuild::build::CfgArgs::output_propagated("ESP_IDF") in the build script doesn't provide it. But in a pure Rust project, this condition will be provided.

I wonder if this is intentional. Also, is there any way to enable mods like esp_idf_svc::netif in a mixed project?

ivmarkov commented 1 year ago

I've updated the CMake-build README with this information. If it still does not work for you after applying the changes suggested there, please, reopen this bug, but ideally - in the esp-idf-template project,.