Skip to content
Merged
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
4 changes: 4 additions & 0 deletions ci/check_rust_toolchain_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def validate_discovered_pins(relative: str, text: str) -> list[str]:
for line_number, line in enumerate(text.splitlines(), 1):
versions: set[str] = set()
for pattern in patterns:
if pattern is PIN_FIELD_PATTERNS[1] and Path(relative).suffix not in {".yml", ".yaml"}:
# `toolchain:` is also an ordinary Rust struct field; only
# workflow YAML declares a Rust toolchain with that spelling.
continue
match = pattern.search(line)
if match is not None:
versions.add(match.group("selector"))
Expand Down
8 changes: 8 additions & 0 deletions ci/test_rust_toolchain_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def test_unrelated_toolchain_package_version_is_not_a_rust_pin(self) -> None:

self.assertEqual(failures, [])

def test_rust_toolchain_struct_field_is_not_a_workflow_pin(self) -> None:
failures = check_rust_toolchain_pins.validate_discovered_pins(
"crates/example/src/platform_source.rs",
" toolchain: require_platform_package(&requirements, name),\n",
)

self.assertEqual(failures, [])


if __name__ == "__main__":
unittest.main()
41 changes: 40 additions & 1 deletion crates/fbuild-build-mcu/src/ch32v/mcu_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ pub fn normalize_march(march: &str) -> String {

/// Apply board ISA and ABI values to compiler and linker flags.
pub fn apply_board_isa(config: &mut Ch32vMcuConfig, march: Option<&str>, mabi: Option<&str>) {
apply_board_isa_for_toolchain(config, march, mabi, "riscv-none-elf");
}

/// Preserve WCH's vendor ISA extensions for its own compiler; only the xPack
/// compiler requires the stripped/modernized `zicsr` spelling.
pub fn apply_board_isa_for_toolchain(
config: &mut Ch32vMcuConfig,
march: Option<&str>,
mabi: Option<&str>,
executable_prefix: &str,
) {
fn replace(flags: &mut [String], prefix: &str, value: &str) {
for flag in flags {
if flag.starts_with(prefix) {
Expand All @@ -107,7 +118,11 @@ pub fn apply_board_isa(config: &mut Ch32vMcuConfig, march: Option<&str>, mabi: O
}

if let Some(march) = march {
let normalized = normalize_march(march);
let normalized = if executable_prefix == "riscv-none-elf" {
normalize_march(march)
} else {
march.to_ascii_lowercase()
};
replace(&mut config.compiler_flags.common, "-march=", &normalized);
replace(&mut config.linker_flags, "-march=", &normalized);
}
Expand All @@ -129,6 +144,30 @@ mod tests {
assert_eq!(normalize_march("rv32ecxw"), "rv32ec_zicsr");
}

#[test]
fn platformio_gcc8_preserves_wch_vendor_isa() {
let mut config = get_ch32v_config_for_mcu("ch32v003").unwrap();
apply_board_isa_for_toolchain(
&mut config,
Some("rv32ecxw"),
Some("ilp32e"),
"riscv-none-embed",
);
assert!(
config
.compiler_flags
.common
.contains(&"-march=rv32ecxw".into())
);
assert!(config.linker_flags.contains(&"-march=rv32ecxw".into()));
assert!(
!config
.compiler_flags
.common
.contains(&"-march=rv32ec_zicsr".into())
);
}

#[test]
fn test_apply_board_isa_updates_compiler_and_linker() {
let mut config = get_ch32v_config_for_mcu("ch32v003").unwrap();
Expand Down
12 changes: 9 additions & 3 deletions crates/fbuild-build-mcu/src/ch32v/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! CH32V RISC-V platform build support (WCH CH32V003, CH32V203, etc.)
//! CH32V RISC-V platform build support (WCH CH32V003, CH32V203, etc.)

pub mod ch32v_compiler;
pub mod ch32v_linker;
pub mod mcu_config;
pub mod orchestrator;
mod platform_source;

pub use ch32v_compiler::Ch32vCompiler;
pub use ch32v_linker::Ch32vLinker;
Expand All @@ -28,8 +29,13 @@ impl crate::PlatformSupport for Ch32vPlatformSupport {
orchestrator::validate_ch32v_framework(
inputs.env_config.get("framework").map(String::as_str),
)?;
let (toolchain, cores) =
orchestrator::ch32v_packages(inputs.project_dir, Some(inputs.env_config));
let (toolchain, cores, _, _) = orchestrator::ch32v_packages(
inputs.project_dir,
Some(inputs.env_config),
&inputs.board.core,
mode.fetches(),
)
.await?;
Ok(vec![
provision_package(PackageKind::Toolchain, &toolchain, mode).await,
provision_package(PackageKind::Framework, &cores, mode).await,
Expand Down
Loading
Loading