-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
imarkov
committed
Oct 6, 2021
1 parent
ac6522b
commit 002262a
Showing
6 changed files
with
280 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "esp-idf-sys" | ||
version = "0.20.2" | ||
version = "0.20.3" | ||
authors = ["Alexey Arbuzov <[email protected]>", "sapir <[email protected]>", "Ivan Markov <[email protected]>"] | ||
edition = "2018" | ||
categories = ["embedded", "hardware-support"] | ||
|
@@ -10,6 +10,7 @@ repository = "https://github.com/ivmarkov/esp-idf-sys" | |
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
links = "esp_idf" | ||
build = "build/build.rs" | ||
|
||
# No xtensa in regular compiler yet | ||
[package.metadata.docs.rs] | ||
|
@@ -31,7 +32,7 @@ embedded-svc = "0.8.3" | |
paste = "1" | ||
|
||
[build-dependencies] | ||
embuild = "0.24" | ||
embuild = "0.24.5" | ||
anyhow = "1" | ||
strum = { version = "0.21", optional = true, features = ["derive"] } | ||
regex = "1.5" |
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
use anyhow::*; | ||
use regex::{self}; | ||
use std::{collections::HashSet, error, fs, iter::once, path::Path, str::FromStr}; | ||
|
||
use embuild::{bindgen, build, kconfig}; | ||
|
||
pub const STABLE_PATCHES: &[&str] = &[ | ||
"patches/missing_xtensa_atomics_fix.diff", | ||
"patches/pthread_destructor_fix.diff", | ||
"patches/ping_setsockopt_fix.diff", | ||
]; | ||
|
||
#[allow(unused)] | ||
pub const MASTER_PATCHES: &[&str] = &["patches/master_missing_xtensa_atomics_fix.diff"]; | ||
|
||
const ALL_COMPONENTS: &[&str] = &[ | ||
// TODO: Put all IDF components here | ||
"comp_pthread_enabled", | ||
"comp_nvs_flash_enabled", | ||
"comp_esp_http_client_enabled", | ||
"comp_esp_http_server_enabled", | ||
"comp_espcoredump_enabled", | ||
"comp_app_update_enabled", | ||
"comp_esp_serial_slave_link_enabled", | ||
"comp_spi_flash_enabled", | ||
"comp_esp_adc_cal_enabled", | ||
]; | ||
|
||
pub struct EspIdfBuildOutput { | ||
pub cincl_args: build::CInclArgs, | ||
pub link_args: Option<build::LinkArgs>, | ||
pub kconfig_args: Box<dyn Iterator<Item = (String, kconfig::Value)>>, | ||
pub components: EspIdfComponents, | ||
pub bindgen: bindgen::Factory, | ||
} | ||
|
||
pub struct EspIdfComponents(Vec<&'static str>); | ||
|
||
impl EspIdfComponents { | ||
pub fn new() -> Self { | ||
Self(ALL_COMPONENTS.iter().map(|s| *s).collect::<Vec<_>>()) | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn from<I, S>(enabled: I) -> Self | ||
where | ||
I: Iterator<Item = S>, | ||
S: Into<String>, | ||
{ | ||
let enabled = enabled.map(Into::into).collect::<HashSet<_>>(); | ||
|
||
Self( | ||
ALL_COMPONENTS | ||
.iter() | ||
.map(|s| *s) | ||
.filter(|s| enabled.contains(*s)) | ||
.collect::<Vec<_>>(), | ||
) | ||
} | ||
|
||
pub fn clang_args<'a>(&'a self) -> impl Iterator<Item = String> + 'a { | ||
self.0 | ||
.iter() | ||
.map(|s| format!("-DESP_IDF_{}", s.to_uppercase())) | ||
} | ||
|
||
pub fn cfg_args<'a>(&'a self) -> impl Iterator<Item = String> + 'a { | ||
self.0.iter().map(|c| format!("esp_idf_{}", c)) | ||
} | ||
} | ||
|
||
pub struct EspIdfVersion { | ||
pub major: u32, | ||
pub minor: u32, | ||
pub patch: u32, | ||
} | ||
|
||
impl EspIdfVersion { | ||
pub fn parse(bindings_file: impl AsRef<Path>) -> Result<Self> { | ||
let bindings_content = fs::read_to_string(bindings_file.as_ref())?; | ||
|
||
Ok(Self { | ||
major: Self::grab_const(&bindings_content, "ESP_IDF_VERSION_MAJOR", "u32")?, | ||
minor: Self::grab_const(&bindings_content, "ESP_IDF_VERSION_MINOR", "u32")?, | ||
patch: Self::grab_const(bindings_content, "ESP_IDF_VERSION_PATCH", "u32")?, | ||
}) | ||
} | ||
|
||
pub fn cfg_args(&self) -> impl Iterator<Item = String> { | ||
once(format!( | ||
"esp_idf_full_version=\"{}.{}.{}\"", | ||
self.major, self.minor, self.patch | ||
)) | ||
.chain(once(format!( | ||
"esp_idf_version=\"{}.{}\"", | ||
self.major, self.minor | ||
))) | ||
.chain(once(format!("esp_idf_major_version=\"{}\"", self.major))) | ||
.chain(once(format!("esp_idf_minor_version=\"{}\"", self.minor))) | ||
.chain(once(format!("esp_idf_patch_version=\"{}\"", self.patch))) | ||
} | ||
|
||
fn grab_const<T>( | ||
text: impl AsRef<str>, | ||
const_name: impl AsRef<str>, | ||
const_type: impl AsRef<str>, | ||
) -> Result<T> | ||
where | ||
T: FromStr, | ||
T::Err: error::Error + Send + Sync + 'static, | ||
{ | ||
// Future: Consider using bindgen::callbacks::ParseCallbacks for grabbing macro-based constants. Should be more reliable compared to grepping | ||
|
||
let const_name = const_name.as_ref(); | ||
|
||
let value = regex::Regex::new(&format!( | ||
r"\s+const\s+{}\s*:\s*{}\s*=\s*(\S+)\s*;", | ||
const_name, | ||
const_type.as_ref() | ||
))? | ||
.captures(text.as_ref()) | ||
.ok_or_else(|| anyhow!("Failed to capture constant {}", const_name))? | ||
.get(1) | ||
.ok_or_else(|| anyhow!("Failed to capture the value of constant {}", const_name))? | ||
.as_str() | ||
.parse::<T>()?; | ||
|
||
Ok(value) | ||
} | ||
} |
Oops, something went wrong.