Skip to content

Seperate out the chips.gcc_toolchain in the context of idf-install.py Vs linking #283

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build/native/cargo_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn build() -> Result<EspIdfBuildOutput> {
);

let mut tools = vec![];
let mut subtools = vec![chip.gcc_toolchain(version.as_ref().ok())];
let mut subtools = vec![chip.gcc_toolchain_install(version.as_ref().ok())];

// Use custom cmake for esp-idf<4.4, because we need at least cmake-3.20
match version.as_ref().map(|v| (v.major, v.minor, v.patch)) {
Expand All @@ -109,7 +109,7 @@ pub fn build() -> Result<EspIdfBuildOutput> {
subtools.push("ninja")
}
if !cfg!(target_os = "linux") || !cfg!(target_arch = "aarch64") {
subtools.extend(chip.ulp_gcc_toolchain(version.as_ref().ok()));
subtools.extend(chip.ulp_gcc_toolchain_install(version.as_ref().ok()));
}
tools.push(espidf::Tools::new(subtools));

Expand Down Expand Up @@ -251,13 +251,13 @@ pub fn build() -> Result<EspIdfBuildOutput> {
.install_dir(linker_install_dir.path().map(Into::into))
.with_tools(move |_, _| {
Ok(vec![espidf::Tools::new(vec![
chip.gcc_toolchain(version_for_installer.as_ref())
chip.gcc_toolchain_install(version_for_installer.as_ref())
])])
})
.install()
.context("Could not install GCC linker")?;

let linker_name = format!("{}-gcc", chip.gcc_toolchain(version.as_ref()));
let linker_name = format!("{}-gcc", chip.gcc_toolchain_link(version.as_ref()));

let linker =
which::which_in_global(linker_name.clone(), Some(installer.exported_path.clone()))?
Expand Down
39 changes: 34 additions & 5 deletions build/native/cargo_driver/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ impl Chip {
matches!(self, Self::ESP32 | Self::ESP32S2 | Self::ESP32S3)
}

/// The name of the gcc toolchain (to compile the `esp-idf`) for `idf_tools.py`.
pub fn gcc_toolchain(&self, version: Option<&EspIdfVersion>) -> &'static str {
/// The name of the gcc toolchain (to compile the `esp-idf`) that `idf_tools.py`
/// should find and install. idf_tools.py might install additional components based
/// on what is specified here, for example an xtensa-esp-elf can also end up installing
/// xtensa-espXX-elf also
pub fn gcc_toolchain_install(&self, version: Option<&EspIdfVersion>) -> &'static str {
let new = version
.map(|version| version.major > 5 || version.major == 5 && version.minor > 1)
.unwrap_or(true);
Expand Down Expand Up @@ -94,9 +97,28 @@ impl Chip {
}
}

/// The name of the gcc toolchain for the ultra low-power co-processor for
/// `idf_tools.py`.
pub fn ulp_gcc_toolchain(&self, version: Option<&EspIdfVersion>) -> Option<&'static str> {
/// The name of the gcc toolchain that should be actually used to compile/link
/// for the specific idf target
pub fn gcc_toolchain_link(&self, _version: Option<&EspIdfVersion>) -> &'static str {
match self {
Self::ESP32 => "xtensa-esp32-elf",
Self::ESP32S2 => "xtensa-esp32s2-elf",
Self::ESP32S3 => "xtensa-esp32s3-elf",
Self::ESP32C2
| Self::ESP32C3
| Self::ESP32H2
| Self::ESP32C5
| Self::ESP32C6
| Self::ESP32P4 => "riscv32-esp-elf",
}
}

/// The name of the gcc toolchain for the ultra low-power co-processor that
/// `idf_tools.py` should install
pub fn ulp_gcc_toolchain_install(
&self,
version: Option<&EspIdfVersion>,
) -> Option<&'static str> {
match self {
Self::ESP32 => Some("esp32ulp-elf"),
Self::ESP32S2 | Self::ESP32S3 | Self::ESP32C6 | Self::ESP32P4 => Some(
Expand All @@ -117,6 +139,13 @@ impl Chip {
}
}

/// The name of the gcc toolchain for the ultra low-power co-processor
/// that is actually used to compile/link for the specific idf target
#[allow(dead_code)]
pub fn ulp_gcc_toolchain_link(&self, version: Option<&EspIdfVersion>) -> Option<&'static str> {
self.ulp_gcc_toolchain_install(version)
}

pub fn cmake_toolchain_file(self) -> String {
format!("toolchain-{self}.cmake")
}
Expand Down