From 49a51f5544ecf6ad0b1fc2f084abecf278388621 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Tue, 17 Oct 2023 20:40:14 +0000 Subject: [PATCH] Branch by arch in cmake generation --- cmake/cargo-generate.toml | 3 ++ cmake/pre-script.rhai | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 cmake/pre-script.rhai diff --git a/cmake/cargo-generate.toml b/cmake/cargo-generate.toml index f579cc8..fe0d43c 100644 --- a/cmake/cargo-generate.toml +++ b/cmake/cargo-generate.toml @@ -1,6 +1,9 @@ [template] cargo_generate_version = ">=0.17.4" +[hooks] +pre = ["pre-script.rhai"] + [placeholders.advanced] type = "bool" prompt = "Configure advanced template options?" diff --git a/cmake/pre-script.rhai b/cmake/pre-script.rhai new file mode 100644 index 0000000..7514b6e --- /dev/null +++ b/cmake/pre-script.rhai @@ -0,0 +1,59 @@ +let targets = #{ + esp32: #{ + arch: "xtensa", + rust_target: "xtensa-esp32-espidf", + gcc_target: "xtensa-esp32-elf", + wokwi_board: "board-esp32-devkit-v1", + }, + esp32c2: #{ + arch: "riscv", + rust_target: "riscv32imc-esp-espidf", + gcc_target: "riscv32-esp-elf", + wokwi_board: "", + }, + esp32c3: #{ + arch: "riscv", + rust_target: "riscv32imc-esp-espidf", + gcc_target: "riscv32-esp-elf", + wokwi_board: "board-esp32-c3-devkitm-1", + }, + esp32c6: #{ + arch: "riscv", + rust_target: "riscv32imac-esp-espidf", + gcc_target: "riscv32-esp-elf", + wokwi_board: "board-esp32-c6-devkitm-1", + }, + esp32h2: #{ + arch: "riscv", + rust_target: "riscv32imac-esp-espidf", + gcc_target: "riscv32-esp-elf", + wokwi_board: "", + }, + esp32s2: #{ + arch: "xtensa", + rust_target: "xtensa-esp32s2-espidf", + gcc_target: "xtensa-esp32s2-elf", + wokwi_board: "board-esp32-s2-devkitm-1", + }, + esp32s3: #{ + arch: "xtensa", + rust_target: "xtensa-esp32s3-espidf", + gcc_target: "xtensa-esp32s3-elf", + wokwi_board: "board-esp32-s3-devkitc-1", + }, +}; + +let target = variable::get("mcu"); +let target_properties = targets.get(target); +for key in target_properties.keys() { + variable::set(key, target_properties.get(key)); +} + +let advanced = variable::get("advanced"); +if !advanced { + variable::set("hal", true); + variable::set("std", true); + variable::set("espidfver", "v5.1"); + variable::set("devcontainer", false); + variable::set("wokwi", false); +}