mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-05 04:37:13 +00:00
swap out curve25519 backend for vexii-test targets
we don't have a curve25519 accelerator on the vexii-test device due to a lack of space to fit it. so for vexii-test targets we swap in the u32 (vs u32e) backend. This requires re-writing the config.toml file based on the presence (or absence) of a vexii-test flag.
This commit is contained in:
parent
a3d350b86f
commit
4dda0da6c9
1 changed files with 73 additions and 1 deletions
|
|
@ -7,7 +7,7 @@ use utils::*;
|
|||
mod builder;
|
||||
use builder::*;
|
||||
mod verifier;
|
||||
use std::env;
|
||||
use std::{env, fs, path::PathBuf};
|
||||
|
||||
use verifier::*;
|
||||
|
||||
|
|
@ -166,6 +166,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
builder.add_services(&extra_services);
|
||||
// extract features, and especially track language features
|
||||
let features = get_flag("--feature")?;
|
||||
|
||||
setup_curve25519_backend(&features);
|
||||
|
||||
let mut language_set = false;
|
||||
for feature in features {
|
||||
builder.add_feature(&feature);
|
||||
|
|
@ -945,3 +948,72 @@ fn get_flag(flag: &str) -> Result<Vec<String>, DynError> {
|
|||
}
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
fn setup_curve25519_backend(features: &Vec<String>) {
|
||||
// Determine workspace root (xtask assumed to be in subdir)
|
||||
let workspace_root = locate_workspace_root().expect("Failed to find workspace root");
|
||||
let config_path = workspace_root.join(".cargo/config.toml");
|
||||
|
||||
// assume that the system has the curve25519 accelerator if it's not the vexii-test config
|
||||
let has_accelerator = !features.contains(&"vexii-test".to_string());
|
||||
|
||||
// Desired cfg value
|
||||
let desired_cfg = if has_accelerator {
|
||||
"curve25519_dalek_backend=\"u32e_backend\""
|
||||
} else {
|
||||
"curve25519_dalek_backend=\"u32_backend\""
|
||||
};
|
||||
|
||||
// Read original lines
|
||||
let original = fs::read_to_string(&config_path).expect("Failed to read config.toml");
|
||||
let mut modified = false;
|
||||
let mut in_target = false;
|
||||
|
||||
let lines: Vec<String> = original
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let trimmed = line.trim();
|
||||
|
||||
// Detect section
|
||||
if trimmed.starts_with("[target.") && trimmed.contains("riscv32imac-unknown-xous-elf") {
|
||||
in_target = true;
|
||||
return line.to_string();
|
||||
}
|
||||
|
||||
if in_target && trimmed.starts_with('[') && trimmed != "[target.riscv32imac-unknown-xous-elf]" {
|
||||
in_target = false; // exited the block
|
||||
}
|
||||
|
||||
if in_target && trimmed.starts_with("rustflags") {
|
||||
if trimmed.contains(desired_cfg) {
|
||||
return line.to_string(); // already correct
|
||||
}
|
||||
|
||||
// Replace line with correct cfg
|
||||
modified = true;
|
||||
return format!(r#"rustflags = ["--cfg", '{}']"#, desired_cfg);
|
||||
}
|
||||
|
||||
line.to_string()
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Only write if modified
|
||||
if modified {
|
||||
fs::write(&config_path, lines.join("\n")).expect("Failed to write config.toml");
|
||||
println!("Updated .cargo/config.toml");
|
||||
} else {
|
||||
println!("No change needed in .cargo/config.toml");
|
||||
}
|
||||
}
|
||||
|
||||
/// Traverse upward to find workspace root (directory with `.cargo/config.toml`)
|
||||
fn locate_workspace_root() -> Option<PathBuf> {
|
||||
let mut dir = env::current_dir().ok()?;
|
||||
while !dir.join(".cargo/config.toml").exists() {
|
||||
if !dir.pop() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(dir)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue