forked from espressif/esp-idf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental esp-idf native cmake build (espressif#7)
* Implement native esp-idf cmake build Move `build.rs` contents to `build_pio.rs` Add feature `native` Add optional dependency `strum` * Remove main wrapper * Fix patches not getting applied, use correct patches * Clarify some `Chip` methods, fix python virtualenv path Use correct target name for `riscv32`. * Fix pio build, tidy code Fix potentially using `:` to split PATH on windows. * Add documentation to README * Change DEFAULT_SDK_DIR to `.espressif` Set min python version to 3.7. Set default build feature to pio. Make `native` feature usable. * Track `sdkconfig` and `sdkconfig_defaults` files.
- Loading branch information
Showing
7 changed files
with
652 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,16 @@ | ||
use std::convert::TryFrom; | ||
use std::{env, path::PathBuf}; | ||
|
||
use anyhow::*; | ||
|
||
use embuild::bindgen; | ||
use embuild::build; | ||
use embuild::cargo; | ||
use embuild::kconfig; | ||
use embuild::pio; | ||
use embuild::pio::project; | ||
|
||
fn main() -> Result<()> { | ||
let pio_scons_vars = if let Some(pio_scons_vars) = project::SconsVariables::from_piofirst() { | ||
println!("cargo:info=PIO->Cargo build detected: generating bindings only"); | ||
|
||
pio_scons_vars | ||
} else { | ||
let pio = pio::Pio::install_default()?; | ||
|
||
let resolution = pio::Resolver::new(pio.clone()) | ||
.params(pio::ResolutionParams { | ||
platform: Some("espressif32".into()), | ||
frameworks: vec!["espidf".into()], | ||
target: Some(env::var("TARGET")?), | ||
..Default::default() | ||
}) | ||
.resolve(true)?; | ||
|
||
let mut builder = | ||
project::Builder::new(PathBuf::from(env::var("OUT_DIR")?).join("esp-idf")); | ||
|
||
builder | ||
.enable_scons_dump() | ||
.enable_c_entry_points() | ||
.options(build::env_options_iter("ESP_IDF_SYS_PIO_CONF")?) | ||
.files(build::tracked_globs_iter( | ||
PathBuf::from("."), | ||
&["patches/**"], | ||
)?) | ||
.files(build::tracked_env_globs_iter("ESP_IDF_SYS_GLOB")?); | ||
|
||
#[cfg(feature = "espidf_master")] | ||
builder | ||
.platform_package( | ||
"framework-espidf", | ||
"https://github.com/ivmarkov/esp-idf.git#master", | ||
) | ||
.platform_package_patch( | ||
PathBuf::from("patches").join("master_missing_xtensa_atomics_fix.diff"), | ||
PathBuf::from("framework-espidf"), | ||
) | ||
.platform_package_patch( | ||
PathBuf::from("patches").join("ping_setsockopt_fix.diff"), | ||
PathBuf::from("framework-espidf"), | ||
); | ||
|
||
#[cfg(feature = "espidf_master")] | ||
env::set_var("IDF_MAINTAINER", "1"); | ||
|
||
#[cfg(not(feature = "espidf_master"))] | ||
builder | ||
.platform_package_patch( | ||
PathBuf::from("patches").join("pthread_destructor_fix.diff"), | ||
PathBuf::from("framework-espidf"), | ||
) | ||
.platform_package_patch( | ||
PathBuf::from("patches").join("ping_setsockopt_fix.diff"), | ||
PathBuf::from("framework-espidf"), | ||
) | ||
.platform_package_patch( | ||
PathBuf::from("patches").join("missing_xtensa_atomics_fix.diff"), | ||
PathBuf::from("framework-espidf"), | ||
); | ||
|
||
let project_path = builder.generate(&resolution)?; | ||
|
||
pio.build(&project_path, env::var("PROFILE")? == "release")?; | ||
|
||
let pio_scons_vars = project::SconsVariables::from_dump(&project_path)?; | ||
|
||
build::LinkArgsBuilder::try_from(&pio_scons_vars)? | ||
.build() | ||
.propagate(); | ||
|
||
pio_scons_vars | ||
}; | ||
|
||
// In case other SYS crates need to have access to the ESP-IDF C headers | ||
build::CInclArgs::try_from(&pio_scons_vars)?.propagate(); | ||
|
||
let cfg_args = kconfig::CfgArgs::try_from( | ||
pio_scons_vars | ||
.project_dir | ||
.join(if pio_scons_vars.release_build { | ||
"sdkconfig.release" | ||
} else { | ||
"sdkconfig.debug" | ||
}) | ||
.as_path(), | ||
)?; | ||
|
||
cfg_args.propagate("ESP_IDF"); | ||
cfg_args.output("ESP_IDF"); | ||
|
||
let mcu = pio_scons_vars.mcu.as_str(); | ||
|
||
// Output the exact ESP32 MCU, so that we and crates depending directly on us can branch using e.g. #[cfg(esp32xxx)] | ||
println!("cargo:rustc-cfg={}", mcu); | ||
println!("cargo:MCU={}", mcu); | ||
|
||
let header = PathBuf::from("src") | ||
.join("include") | ||
.join(if mcu == "esp8266" { | ||
"esp-8266-rtos-sdk" | ||
} else { | ||
"esp-idf" | ||
}) | ||
.join("bindings.h"); | ||
|
||
cargo::track_file(&header); | ||
|
||
bindgen::run( | ||
bindgen::Factory::from_scons_vars(&pio_scons_vars)? | ||
.builder()? | ||
.ctypes_prefix("c_types") | ||
.header(header.to_string_lossy()) | ||
.blacklist_function("strtold") | ||
.blacklist_function("_strtold_r") | ||
.clang_args(if mcu == "esp32c3" { | ||
vec!["-target", "riscv32"] | ||
} else { | ||
vec![] | ||
}), | ||
) | ||
} | ||
#[cfg(not(any(feature = "pio", feature = "native")))] | ||
compile_error!("One of the features `pio` or `native` must be selected."); | ||
|
||
// Note that the feature `native` must come before `pio`. These features are really | ||
// mutually exclusive but that would require that all dependencies specify the same | ||
// feature so instead we prefer the `native` feature over `pio` so that if one package | ||
// specifies it, this overrides the `pio` feature for all other dependencies too. | ||
// See https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features. | ||
#[cfg(any(feature = "pio", feature = "native"))] | ||
#[cfg_attr(feature = "native", path = "build_native.rs")] | ||
#[cfg_attr(all(feature = "pio", not(feature = "native")), path = "build_pio.rs")] | ||
mod build_impl; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
build_impl::main() | ||
} |
Oops, something went wrong.