Skip to content

Commit

Permalink
Process overrides in custom tools logic
Browse files Browse the repository at this point in the history
The custom tools parsing logic introduced in esp-rs#85 does not process the overrides in tools.json. This omission breaks compilation on macOS and likely several other platforms.

This commit adds override parsing logic to properly handle overrides from tools.json

Signed-off-by: Tom Stokes <[email protected]>
  • Loading branch information
tomstokes committed Jun 14, 2024
1 parent 04369e0 commit c9ba9d0
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/espidf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use serde::{Deserialize, Serialize};
use crate::python::PYTHON;
use crate::{cmd, git, path_buf, python};

use self::tools_schema::{PlatformDownloadInfo, ToolInfo, VersionInfo};
use self::tools_schema::{
PlatformDownloadInfo, PlatformOverrideInfoPlatformsItem, ToolInfo, VersionInfo,
};

#[cfg(feature = "elf")]
pub mod ulp_fsm;
Expand Down Expand Up @@ -273,6 +275,49 @@ fn parse_tools(
}
}
});

// Map OS and ARCH to platform names in esp-idf.
// Unfortunately, the Rust std lib doesn't differentiate between armel
// and armhf for 32-bit ARM platforms. This code defaults to armel for
// maximum compatibility
let platform = match (std::env::consts::OS, std::env::consts::ARCH) {
("linux", "x86") => Some(PlatformOverrideInfoPlatformsItem::LinuxI686),
("linux", "x86_64") => Some(PlatformOverrideInfoPlatformsItem::LinuxAmd64),
("linux", "arm") => Some(PlatformOverrideInfoPlatformsItem::LinuxArmel),
("linux", "aarch64") => Some(PlatformOverrideInfoPlatformsItem::LinuxArm64),
("macos", "x86_64") => Some(PlatformOverrideInfoPlatformsItem::Macos),
("macos", "aarch64") => Some(PlatformOverrideInfoPlatformsItem::MacosArm64),
("windows", "x86") => Some(PlatformOverrideInfoPlatformsItem::Win32),
("windows", "x86_64") => Some(PlatformOverrideInfoPlatformsItem::Win64),
_ => None,
};
// Process any overrides that match the detected platform.
// If additional fields from `tool_info` are used in the future, their
// corresponding overrides need to be processed here as well
if let Some(p) = platform {
tool_info.platform_overrides
.iter()
.filter(|info| info.platforms.contains(&p))
.for_each(|info| {
if let Some(export_path) = &info.export_paths {
// export_path can have multiple levels, but only the
// first is currently used in practice
if let Some(first_path) = export_path.first() {
tool.export_path = PathBuf::from_iter(
["tools", &tool.name, &tool.version].into_iter()
.chain(first_path.iter().map(String::as_str))
);
}
}
if let Some(version_cmd) = &info.version_cmd {
tool.version_cmd_args = version_cmd.to_vec();
}
if let Some(version_regex) = &info.version_regex {
tool.version_regex = version_regex.to_string();
}
});
}

log::debug!("{tool:?}");
tool
}
Expand Down

0 comments on commit c9ba9d0

Please sign in to comment.