Skip to content

Commit

Permalink
Fix CI bu disabling cc-rs target based flags generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Nov 5, 2024
1 parent 1e06374 commit e8ef996
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ build = "build/build.rs"
documentation = "https://docs.esp-rs.org/esp-idf-sys/"
rust-version = "1.66"

[patch.crates-io]
cmake = { git = "https://github.com/ivmarkov/cmake-rs" }

[lib]
harness = false

Expand Down
33 changes: 2 additions & 31 deletions build/native/cargo_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub fn build() -> Result<EspIdfBuildOutput> {
let version = idf.version.as_ref().ok().cloned();

let custom_linker = if !gcc12 && !chip.is_xtensa() {
// Another, even more annoying issue with the riscv targets is that since Rust nightly-2023-08-08
// An annoying issue with the riscv targets is that since Rust nightly-2023-08-08
// and the introduction of LLVM-17, rustc (and LLVM) claim to support RISCV ISA 2.1 spec
// (via the "attributes" section in elf object files)
//
Expand Down Expand Up @@ -454,40 +454,11 @@ pub fn build() -> Result<EspIdfBuildOutput> {

let mut cmake_config = cmake::Config::new(&out_dir);

if gcc12 && !chip.is_xtensa() {
// This code solves the following annoying issue:
// GCC-12+ follows the later V2.1 specification of the I riscv extension
// However LLVM and Rust are still on V2.0
//
// 2.1 is not backwards compatible with 2.0 in that zicsr and zifencei are no longer
// considered part of the I extension
//
// Therefore, explicitly tell GCC 12+ that we in fact want these extensions included
// This is done by passing a "made up" rustc target to cmake-rs (and tus to cc-rs)
// that happens to be parsed correctly and results in correct arguments passed
// downstream to GCC
//
// See these links for more info:
// https://github.com/esp-rs/esp-idf-sys/issues/176
// https://discourse.llvm.org/t/support-for-zicsr-and-zifencei-extensions/68369/3
if target == "riscv32imc-esp-espidf" {
cmake_config.target("riscv32imc_zicsr_zifencei-esp-espidf");
} else if target == "riscv32imac-esp-espidf" {
cmake_config.target("riscv32imac_zicsr_zifencei-esp-espidf");
} else if target == "riscv32imafc-esp-espidf" {
cmake_config.target("riscv32imafc_zicsr_zifencei-esp-espidf");
// workaround for a bug in cc-rs
// see https://github.com/rust-lang/cc-rs/issues/795 & https://github.com/rust-lang/cc-rs/pull/796
cmake_config.cflag("-mabi=ilp32f");
} else {
panic!("Unsupported target: {}", target);
}
}

cmake_config
.generator(cmake_generator.name())
.out_dir(&out_dir)
.no_build_target(true)
.no_default_flags(true)
.define("CMAKE_TOOLCHAIN_FILE", &cmake_toolchain_file)
.define("CMAKE_BUILD_TYPE", "")
.define("PYTHON", to_cmake_path_list([&idf.venv_python])?)
Expand Down

0 comments on commit e8ef996

Please sign in to comment.