Merge remote-tracking branch 'eupn/xtask-simplify' into swap

This commit is contained in:
bunnie 2024-04-01 14:20:45 +08:00
commit 5add97db90
8 changed files with 173 additions and 222 deletions

View file

@ -472,6 +472,7 @@ perform the Xous firmware upgrade. This requires running manual update commands,
- @gsora has added the `hidapi` - apps can now register a HID descriptor for custom interactions over USB. See `apps/hidv2` for democumentation. - @gsora has added the `hidapi` - apps can now register a HID descriptor for custom interactions over USB. See `apps/hidv2` for democumentation.
- change kernel and loader targets to riscv-unknown-elf-none because `xous` is now a proper target (required for Rust 1.76 compatibility) - change kernel and loader targets to riscv-unknown-elf-none because `xous` is now a proper target (required for Rust 1.76 compatibility)
- `curve25519-dalek` API is now at 4.1.2, thanks to @kotval for pulling it together. The new API removes `engine-25519` and rolls hardware allocate/release into the forked crate, similar to how sha2 was ported. `engine-25519` crate now removed from source tree, as it is now depracted since all the functionality was pulled into `curve25519-dalek`. - `curve25519-dalek` API is now at 4.1.2, thanks to @kotval for pulling it together. The new API removes `engine-25519` and rolls hardware allocate/release into the forked crate, similar to how sha2 was ported. `engine-25519` crate now removed from source tree, as it is now depracted since all the functionality was pulled into `curve25519-dalek`.
- keymap is checked on every call to send a key to the USB keyboard. This allows us to toggle the keymap temporarily to allow typing into hosts with a different keymap (instead of requiring a reboot)
## Roadmap ## Roadmap
- Lots of testing and bug fixes - Lots of testing and bug fixes

View file

@ -85,8 +85,6 @@ pub(crate) fn main_hw() -> ! {
let tt = ticktimer_server::Ticktimer::new().unwrap(); let tt = ticktimer_server::Ticktimer::new().unwrap();
#[cfg(not(feature = "minimal"))] #[cfg(not(feature = "minimal"))]
let native_kbd = keyboard::Keyboard::new(&xns).unwrap(); let native_kbd = keyboard::Keyboard::new(&xns).unwrap();
#[cfg(not(feature = "minimal"))]
let native_map = native_kbd.get_keymap().unwrap();
#[cfg(not(feature = "minimal"))] #[cfg(not(feature = "minimal"))]
let serial_number = format!("{:x}", llio.soc_dna().unwrap()); let serial_number = format!("{:x}", llio.soc_dna().unwrap());
@ -1165,6 +1163,7 @@ pub(crate) fn main_hw() -> ! {
match view { match view {
Views::FidoWithKbd => { Views::FidoWithKbd => {
if usb_dev.state() == UsbDeviceState::Configured { if usb_dev.state() == UsbDeviceState::Configured {
let native_map = native_kbd.get_keymap().unwrap();
let mut codes = Vec::<Keyboard>::new(); let mut codes = Vec::<Keyboard>::new();
if code0 != 0 { if code0 != 0 {
codes.push(match native_map { codes.push(match native_map {
@ -1262,6 +1261,9 @@ pub(crate) fn main_hw() -> ! {
match view { match view {
#[cfg(not(feature = "minimal"))] #[cfg(not(feature = "minimal"))]
Views::FidoWithKbd => { Views::FidoWithKbd => {
// check keymap on every call because we may need to toggle this for e.g. plugging
// into a new host with a different map
let native_map = native_kbd.get_keymap().unwrap();
for ch in usb_send.s.as_str().unwrap().chars() { for ch in usb_send.s.as_str().unwrap().chars() {
// ASSUME: user's keyboard type matches the preference on their Precursor device. // ASSUME: user's keyboard type matches the preference on their Precursor device.
let codes = match native_map { let codes = match native_map {

View file

@ -51,7 +51,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
// derive a working_set that is just the apps we requested // derive a working_set that is just the apps we requested
for app in apps { for app in apps {
if let Some(manifest) = manifest.get(app) { if let Some(manifest) = manifest.get(app) {
working_set.insert(app.to_string(), &manifest); working_set.insert(app.to_string(), manifest);
} }
} }
@ -63,7 +63,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
writeln!( writeln!(
gam_tokens, gam_tokens,
"pub const APP_NAME_{}: &'static str = \"{}\";", "pub const APP_NAME_{}: &'static str = \"{}\";",
app_name.to_uppercase().replace("-", "_"), app_name.to_uppercase().replace('-', "_"),
manifest.context_name, manifest.context_name,
) )
.unwrap(); .unwrap();
@ -73,7 +73,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
gam_tokens, gam_tokens,
"pub const APP_MENU_{}_{}: &'static str = \"{} Submenu {}\";", "pub const APP_MENU_{}_{}: &'static str = \"{} Submenu {}\";",
i, i,
app_name.to_uppercase().replace("-", "_"), app_name.to_uppercase().replace('-', "_"),
manifest.context_name, manifest.context_name,
i, i,
) )
@ -83,10 +83,10 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
} }
writeln!(gam_tokens, "\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &[").unwrap(); writeln!(gam_tokens, "\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &[").unwrap();
for (app_name, manifest) in working_set.iter() { for (app_name, manifest) in working_set.iter() {
writeln!(gam_tokens, " APP_NAME_{},", app_name.to_uppercase().replace("-", "_"),).unwrap(); writeln!(gam_tokens, " APP_NAME_{},", app_name.to_uppercase().replace('-', "_"),).unwrap();
if let Some(menu_count) = manifest.submenu { if let Some(menu_count) = manifest.submenu {
for i in 0..menu_count { for i in 0..menu_count {
writeln!(gam_tokens, " APP_MENU_{}_{},", i, app_name.to_uppercase().replace("-", "_"),) writeln!(gam_tokens, " APP_MENU_{}_{},", i, app_name.to_uppercase().replace('-', "_"),)
.unwrap(); .unwrap();
} }
} }
@ -98,7 +98,7 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
let mut menu = String::new(); let mut menu = String::new();
writeln!(menu, "#![cfg_attr(rustfmt, rustfmt_skip)]").unwrap(); writeln!(menu, "#![cfg_attr(rustfmt, rustfmt_skip)]").unwrap();
writeln!(menu, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap(); writeln!(menu, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap();
if apps.len() == 0 { if apps.is_empty() {
writeln!(menu, "// NO APPS SELECTED: suppressing warning messages!").unwrap(); writeln!(menu, "// NO APPS SELECTED: suppressing warning messages!").unwrap();
writeln!(menu, "#![allow(dead_code)]").unwrap(); writeln!(menu, "#![allow(dead_code)]").unwrap();
writeln!(menu, "#![allow(unused_imports)]").unwrap(); writeln!(menu, "#![allow(unused_imports)]").unwrap();
@ -139,7 +139,7 @@ pub(crate) fn app_dispatch(gam: &gam::Gam, token: [u32; 4], index: usize) -> Res
Ok(()) Ok(())
}},", }},",
index, index,
app_name.to_uppercase().replace("-", "_") app_name.to_uppercase().replace('-', "_")
) )
.unwrap(); .unwrap();
} }
@ -170,7 +170,7 @@ pub(crate) fn app_menu_items(menu_items: &mut Vec::<MenuItem>, status_conn: u32)
.unwrap(); .unwrap();
for (index, (_app_name, manifest)) in working_set.iter().enumerate() { for (index, (_app_name, manifest)) in working_set.iter().enumerate() {
writeln!(menu, " menu_items.push(MenuItem {{",).unwrap(); writeln!(menu, " menu_items.push(MenuItem {{",).unwrap();
assert!(manifest.menu_name.len() == 1, "Improper menu name record entry"); assert_eq!(manifest.menu_name.len(), 1, "Improper menu name record entry");
for name in manifest.menu_name.keys() { for name in manifest.menu_name.keys() {
writeln!(menu, " name: xous_ipc::String::from_str(t!(\"{}\", locales::LANG)),", name) writeln!(menu, " name: xous_ipc::String::from_str(t!(\"{}\", locales::LANG)),", name)
.unwrap(); .unwrap();

View file

@ -15,7 +15,7 @@ pub(crate) enum BuildStream {
Release, Release,
} }
impl BuildStream { impl BuildStream {
pub fn to_str(&self) -> &str { pub fn as_str(&self) -> &str {
match self { match self {
BuildStream::Debug => "debug", BuildStream::Debug => "debug",
BuildStream::Release => "release", BuildStream::Release => "release",
@ -180,7 +180,7 @@ impl Builder {
/// Specify an alternate loader key, as a String that can encode a file name /// Specify an alternate loader key, as a String that can encode a file name
/// in the local directory, or a path + filename. /// in the local directory, or a path + filename.
#[allow(dead_code)] #[allow(dead_code)]
pub fn loader_key_file<'a>(&'a mut self, filename: String) -> &'a mut Builder { pub fn loader_key_file(&mut self, filename: String) -> &mut Builder {
self.loader_key = filename; self.loader_key = filename;
self self
} }
@ -188,7 +188,7 @@ impl Builder {
/// Specify an alternate loader key, as a String that can encode a file name /// Specify an alternate loader key, as a String that can encode a file name
/// in the local directory, or a path + filename. /// in the local directory, or a path + filename.
#[allow(dead_code)] #[allow(dead_code)]
pub fn kernel_key_file<'a>(&'a mut self, filename: String) -> &'a mut Builder { pub fn kernel_key_file(&mut self, filename: String) -> &mut Builder {
self.kernel_key = filename; self.kernel_key = filename;
self self
} }
@ -202,26 +202,26 @@ impl Builder {
/// Set the build stream (debug or release) /// Set the build stream (debug or release)
#[allow(dead_code)] #[allow(dead_code)]
pub fn stream<'a>(&'a mut self, stream: BuildStream) -> &'a mut Builder { pub fn stream(&mut self, stream: BuildStream) -> &mut Builder {
self.stream = stream; self.stream = stream;
self self
} }
/// Disable default features on the loader /// Disable default features on the loader
#[allow(dead_code)] #[allow(dead_code)]
pub fn loader_disable_defaults<'a>(&'a mut self) -> &'a mut Builder { pub fn loader_disable_defaults(&mut self) -> &mut Builder {
self.loader_disable_defaults = true; self.loader_disable_defaults = true;
self self
} }
/// Disable default features on the loader /// Disable default features on the loader
#[allow(dead_code)] #[allow(dead_code)]
pub fn kernel_disable_defaults<'a>(&'a mut self) -> &'a mut Builder { pub fn kernel_disable_defaults(&mut self) -> &mut Builder {
self.kernel_disable_defaults = true; self.kernel_disable_defaults = true;
self self
} }
pub fn add_global_flag<'a>(&'a mut self, flag: &str) -> &'a mut Builder { pub fn add_global_flag(&mut self, flag: &str) -> &mut Builder {
self.global_flags.push(flag.to_string()); self.global_flags.push(flag.to_string());
self self
} }
@ -233,19 +233,19 @@ impl Builder {
/// version. Eventually (on the order of many months or years), this code gets retired, /// version. Eventually (on the order of many months or years), this code gets retired,
/// otherwise we accumulate rarely-used code ad nauseam. /// otherwise we accumulate rarely-used code ad nauseam.
#[allow(dead_code)] #[allow(dead_code)]
pub fn set_min_xous_ver<'a>(&'a mut self, min_ver_string: &str) -> &'a mut Builder { pub fn set_min_xous_ver(&mut self, min_ver_string: &str) -> &mut Builder {
self.min_ver = min_ver_string.to_string(); self.min_ver = min_ver_string.to_string();
self self
} }
/// specify a locale string to override for the current build /// specify a locale string to override for the current build
pub fn override_locale<'a>(&'a mut self, locale: &str) -> &'a mut Builder { pub fn override_locale(&mut self, locale: &str) -> &mut Builder {
self.locale_override = Some(locale.into()); self.locale_override = Some(locale.into());
self self
} }
/// Configure for hosted mode /// Configure for hosted mode
pub fn target_hosted<'a>(&'a mut self) -> &'a mut Builder { pub fn target_hosted(&mut self) -> &mut Builder {
self.loader = CrateSpec::None; self.loader = CrateSpec::None;
self.target = None; self.target = None;
self.target_kernel = None; self.target_kernel = None;
@ -256,7 +256,7 @@ impl Builder {
} }
/// Configure for renode targets /// Configure for renode targets
pub fn target_renode<'a>(&'a mut self) -> &'a mut Builder { pub fn target_renode(&mut self) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string()); self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string()); self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release; self.stream = BuildStream::Release;
@ -268,9 +268,9 @@ impl Builder {
} }
/// Configure for precursor targets. This is the default, but it's good practice /// Configure for precursor targets. This is the default, but it's good practice
/// to call it anyways just in case the defaults change. The `soc_version` should /// to call it anyway just in case the defaults change. The `soc_version` should
/// be just the gitrev of the soc version, not the entire feature name. /// be just the gitrev of the soc version, not the entire feature name.
pub fn target_precursor<'a>(&'a mut self, soc_version: &str) -> &'a mut Builder { pub fn target_precursor(&mut self, soc_version: &str) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string()); self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string()); self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release; self.stream = BuildStream::Release;
@ -281,7 +281,7 @@ impl Builder {
self self
} }
pub fn target_precursor_no_image<'a>(&'a mut self, soc_version: &str) -> &'a mut Builder { pub fn target_precursor_no_image(&mut self, soc_version: &str) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string()); self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string()); self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release; self.stream = BuildStream::Release;
@ -304,7 +304,7 @@ impl Builder {
} }
/// Configure various Cramium targets /// Configure various Cramium targets
pub fn target_cramium_fpga<'a>(&'a mut self) -> &'a mut Builder { pub fn target_cramium_fpga(&mut self) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string()); self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string()); self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release; self.stream = BuildStream::Release;
@ -315,7 +315,7 @@ impl Builder {
self self
} }
pub fn target_cramium_soc<'a>(&'a mut self) -> &'a mut Builder { pub fn target_cramium_soc(&mut self) -> &mut Builder {
self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string()); self.target = Some(crate::TARGET_TRIPLE_RISCV32.to_string());
self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string()); self.target_kernel = Some(crate::TARGET_TRIPLE_RISCV32_KERNEL.to_string());
self.stream = BuildStream::Release; self.stream = BuildStream::Release;
@ -329,14 +329,14 @@ impl Builder {
/// Override the default kernel. For example, to use the kernel from crates.io, specify as /// Override the default kernel. For example, to use the kernel from crates.io, specify as
/// "xous-kernel@0.9.9" /// "xous-kernel@0.9.9"
#[allow(dead_code)] #[allow(dead_code)]
pub fn use_kernel<'a>(&'a mut self, spec: &str) -> &'a mut Builder { pub fn use_kernel(&mut self, spec: &str) -> &mut Builder {
self.kernel = spec.into(); self.kernel = spec.into();
self self
} }
/// Override the default loader /// Override the default loader
#[allow(dead_code)] #[allow(dead_code)]
pub fn use_loader<'a>(&'a mut self, spec: &str) -> &'a mut Builder { pub fn use_loader(&mut self, spec: &str) -> &mut Builder {
self.loader = spec.into(); self.loader = spec.into();
self self
} }
@ -360,7 +360,7 @@ impl Builder {
} }
/// Add just one service /// Add just one service
pub fn add_service<'a>(&'a mut self, service_spec: &str, region: LoaderRegion) -> &'a mut Builder { pub fn add_service(&mut self, service_spec: &str, region: LoaderRegion) -> &mut Builder {
let mut spec: CrateSpec = service_spec.into(); let mut spec: CrateSpec = service_spec.into();
spec.set_region(region); spec.set_region(region);
self.services.push(spec); self.services.push(spec);
@ -368,16 +368,16 @@ impl Builder {
} }
/// Add a list of services /// Add a list of services
pub fn add_services<'a>(&'a mut self, service_list: &Vec<String>) -> &'a mut Builder { pub fn add_services<S: AsRef<str>>(&mut self, service_list: impl IntoIterator<Item = S>) -> &mut Builder {
for service in service_list { for service in service_list {
self.services.push(service.as_str().into()); self.services.push(service.as_ref().into());
} }
self self
} }
/// Add just one app. Apps can be remote or downloaded externally. /// Add just one app. Apps can be remote or downloaded externally.
#[allow(dead_code)] #[allow(dead_code)]
pub fn add_app<'a>(&'a mut self, app_spec: &str, region: LoaderRegion) -> &'a mut Builder { pub fn add_app(&mut self, app_spec: &str, region: LoaderRegion) -> &mut Builder {
let mut spec: CrateSpec = app_spec.into(); let mut spec: CrateSpec = app_spec.into();
spec.set_region(region); spec.set_region(region);
self.apps.push(spec); self.apps.push(spec);
@ -385,22 +385,22 @@ impl Builder {
} }
/// Add a list of apps. Apps can be remote or downloaded externally. /// Add a list of apps. Apps can be remote or downloaded externally.
pub fn add_apps<'a>(&'a mut self, app_list: &Vec<String>) -> &'a mut Builder { pub fn add_apps<S: AsRef<str>>(&mut self, app_list: impl IntoIterator<Item = S>) -> &mut Builder {
for app in app_list { for app in app_list {
self.apps.push(app.as_str().into()); self.apps.push(app.as_ref().into());
} }
self self
} }
/// add a feature to be passed on to services /// add a feature to be passed on to services
pub fn add_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder { pub fn add_feature(&mut self, feature: &str) -> &mut Builder {
self.features.push(feature.into()); self.features.push(feature.into());
self self
} }
/// remove a feature previously added by a previous call /// remove a feature previously added by a previous call
#[allow(dead_code)] #[allow(dead_code)]
pub fn remove_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder { pub fn remove_feature(&mut self, feature: &str) -> &mut Builder {
self.features.retain(|x| x != feature); self.features.retain(|x| x != feature);
self self
} }
@ -409,20 +409,20 @@ impl Builder {
pub fn has_feature(&self, feature: &str) -> bool { self.features.contains(&feature.to_string()) } pub fn has_feature(&self, feature: &str) -> bool { self.features.contains(&feature.to_string()) }
/// add a feature to be passed on to just the loader /// add a feature to be passed on to just the loader
pub fn add_loader_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder { pub fn add_loader_feature(&mut self, feature: &str) -> &mut Builder {
self.loader_features.push(feature.into()); self.loader_features.push(feature.into());
self self
} }
/// add a feature to be passed on to just the loader /// add a feature to be passed on to just the loader
#[allow(dead_code)] #[allow(dead_code)]
pub fn add_kernel_feature<'a>(&'a mut self, feature: &str) -> &'a mut Builder { pub fn add_kernel_feature(&mut self, feature: &str) -> &mut Builder {
self.kernel_features.push(feature.into()); self.kernel_features.push(feature.into());
self self
} }
/// only build a hosted target. don't run it. Used exclusively to confirm that hosted mode builds in CI. /// only build a hosted target. don't run it. Used exclusively to confirm that hosted mode builds in CI.
pub fn hosted_build_only<'a>(&'a mut self) -> &'a mut Builder { pub fn hosted_build_only(&mut self) -> &mut Builder {
self.dry_run = true; self.dry_run = true;
self self
} }
@ -432,12 +432,12 @@ impl Builder {
/// method, and it gets called repeatedly to build the kernel, loader, and services. /// method, and it gets called repeatedly to build the kernel, loader, and services.
fn builder( fn builder(
&self, &self,
packages: &Vec<CrateSpec>, packages: &[CrateSpec],
features: &Vec<String>, features: &[String],
target: &Option<&str>, target: &Option<&str>,
// the stream is specified separately here because the loader is special-case always release // the stream is specified separately here because the loader is special-case always release
stream: BuildStream, stream: BuildStream,
extra_args: &Vec<String>, extra_args: &[String],
no_default_features: bool, no_default_features: bool,
) -> Result<Vec<String>, DynError> { ) -> Result<Vec<String>, DynError> {
// list of build artifacts, as full paths specific to the host OS // list of build artifacts, as full paths specific to the host OS
@ -456,7 +456,7 @@ impl Builder {
Some(t) => format!("{}/", t), Some(t) => format!("{}/", t),
None => "".to_string(), None => "".to_string(),
}, },
stream.to_str(), stream.as_str(),
); );
remote_args.push(&output_root); remote_args.push(&output_root);
@ -494,13 +494,13 @@ impl Builder {
let mut remote_pkgs = Vec::<(&str, &str)>::new(); let mut remote_pkgs = Vec::<(&str, &str)>::new();
for pkg in packages.iter() { for pkg in packages.iter() {
match pkg { match pkg {
CrateSpec::Local(name, _region) => local_pkgs.push(&name), CrateSpec::Local(name, _region) => local_pkgs.push(name),
CrateSpec::CratesIo(name, version, _region) => remote_pkgs.push((&name, &version)), CrateSpec::CratesIo(name, version, _region) => remote_pkgs.push((&name, &version)),
_ => {} _ => {}
} }
} }
if local_pkgs.len() > 0 { if !local_pkgs.is_empty() {
for pkg in local_pkgs { for pkg in local_pkgs {
local_args.push("--package"); local_args.push("--package");
local_args.push(pkg); local_args.push(pkg);
@ -509,7 +509,7 @@ impl Builder {
if no_default_features { if no_default_features {
local_args.push("--no-default-features"); local_args.push("--no-default-features");
} }
if features.len() > 0 { if !features.is_empty() {
for feature in features { for feature in features {
local_args.push("--features"); local_args.push("--features");
local_args.push(feature); local_args.push(feature);
@ -528,12 +528,12 @@ impl Builder {
return Err("Local build failed".into()); return Err("Local build failed".into());
} }
} }
if remote_pkgs.len() > 0 { if !remote_pkgs.is_empty() {
// remote packages are installed one at a time // remote packages are installed one at a time
if no_default_features { if no_default_features {
local_args.push("--no-default-features"); local_args.push("--no-default-features");
} }
if features.len() > 0 { if !features.is_empty() {
for feature in features { for feature in features {
remote_args.push("--features"); remote_args.push("--features");
remote_args.push(feature); remote_args.push(feature);
@ -609,14 +609,14 @@ impl Builder {
// the service wasn't found in any of the other lists, mark it as non-xip // the service wasn't found in any of the other lists, mark it as non-xip
inie.push(service.to_string()); inie.push(service.to_string());
} }
assert!(inie.len() + inif.len() + inis.len() == services.len()); assert_eq!(inie.len() + inif.len() + inis.len(), services.len());
(inie, inif, inis) (inie, inif, inis)
} }
/// Consume the builder and execute the configured build task. This handles dispatching all /// Consume the builder and execute the configured build task. This handles dispatching all
/// configurations, including renode, hosted, and hardware targets. /// configurations, including renode, hosted, and hardware targets.
pub fn build(mut self) -> Result<(), DynError> { pub fn build(mut self) -> Result<(), DynError> {
if self.apps.len() == 0 && self.services.len() == 0 { if self.apps.is_empty() && self.services.is_empty() {
// no services were specified - don't build anything // no services were specified - don't build anything
return Ok(()); return Ok(());
} }
@ -658,8 +658,8 @@ impl Builder {
return Err("Target unknown: please check your UTRA target".into()); return Err("Target unknown: please check your UTRA target".into());
} }
crate::utils::ensure_compiler(&self.target.as_ref().map(|s| s.as_str()), false, false)?; crate::utils::ensure_compiler(&self.target.as_deref(), false, false)?;
crate::utils::ensure_kernel_compiler(&self.target_kernel.as_ref().map(|s| s.as_str()), false)?; crate::utils::ensure_kernel_compiler(&self.target_kernel.as_deref(), false)?;
self.locale_override(); // apply the locale override self.locale_override(); // apply the locale override
// ------ build the services & apps ------ // ------ build the services & apps ------
@ -668,12 +668,9 @@ impl Builder {
match app { match app {
CrateSpec::Local(name, _region) => app_names.push(name.into()), CrateSpec::Local(name, _region) => app_names.push(name.into()),
CrateSpec::CratesIo(name, _version, _region) => app_names.push(name.into()), CrateSpec::CratesIo(name, _version, _region) => app_names.push(name.into()),
CrateSpec::BinaryFile(name, _location, _region) => { CrateSpec::BinaryFile(Some(name), _location, _region) => {
// if binary file has a name, ensure it ends up in the app menu // if binary file has a name, ensure it ends up in the app menu
if let Some(n) = name { app_names.push(name.to_string())
app_names.push(n.to_string())
} else {
}
} }
_ => {} _ => {}
} }
@ -684,7 +681,7 @@ impl Builder {
&self.features, &self.features,
&self.target.as_deref(), &self.target.as_deref(),
self.stream, self.stream,
&vec![], &[],
false, false,
)?; )?;
@ -698,11 +695,8 @@ impl Builder {
// hosted mode doesn't specify a cross-compilation target! // hosted mode doesn't specify a cross-compilation target!
// throw a warning if prebuilt files are specified for hosted mode // throw a warning if prebuilt files are specified for hosted mode
for item in [&self.services[..], &self.apps[..]].concat() { for item in [&self.services[..], &self.apps[..]].concat() {
match item { if let CrateSpec::Prebuilt(name, _, _region) = item {
CrateSpec::Prebuilt(name, _, _region) => { println!("Warning! Pre-built binaries not supported for hosted mode ({})", name);
println!("Warning! Pre-built binaries not supported for hosted mode ({})", name)
}
_ => {}
} }
} }
// fixup windows paths // fixup windows paths
@ -712,9 +706,8 @@ impl Builder {
} }
} }
let mut hosted_args = vec!["run"]; let mut hosted_args = vec!["run"];
match self.stream { if let BuildStream::Release = self.stream {
BuildStream::Release => hosted_args.push("--release"), hosted_args.push("--release");
_ => {}
} }
hosted_args.push("--"); hosted_args.push("--");
for service in services_path.iter() { for service in services_path.iter() {
@ -733,8 +726,8 @@ impl Builder {
} }
for f in canonicalized_paths { for f in canonicalized_paths {
let path_as_str = f.to_str().expect("Couldn't canonicalize executable target").to_string(); let path_as_str = f.to_str().expect("Couldn't canonicalize executable target").to_string();
let windows_clean_path = if path_as_str.starts_with("\\\\?\\") { let windows_clean_path = if let Some(stripped) = path_as_str.strip_prefix("\\\\?\\") {
path_as_str[4..].to_owned() stripped.to_owned()
} else { } else {
path_as_str path_as_str
}; };
@ -759,11 +752,11 @@ impl Builder {
} else { } else {
// confirm the kernel can build before quitting // confirm the kernel can build before quitting
let _ = self.builder( let _ = self.builder(
&vec![CrateSpec::Local("xous-kernel".into(), LoaderRegion::Ram)], &[CrateSpec::Local("xous-kernel".into(), LoaderRegion::Ram)],
&self.kernel_features, &self.kernel_features,
&self.target_kernel.as_deref(), &self.target_kernel.as_deref(),
self.stream, self.stream,
&vec![], &[],
false, false,
)?; )?;
println!("Dry run requested: only building and not running"); println!("Dry run requested: only building and not running");
@ -775,7 +768,7 @@ impl Builder {
kernel_extra.push("--no-default-features".to_string()); kernel_extra.push("--no-default-features".to_string());
} }
let kernel_path = self.builder( let kernel_path = self.builder(
&vec![self.kernel.clone()], &[self.kernel.clone()],
&self.kernel_features, &self.kernel_features,
&self.target_kernel.as_deref(), &self.target_kernel.as_deref(),
self.stream, self.stream,
@ -786,18 +779,18 @@ impl Builder {
// ------ build the loader ------ // ------ build the loader ------
// stash any LTO settings applied to the kernel; proper layout of the loader // stash any LTO settings applied to the kernel; proper layout of the loader
// block depends on the loader being compact and highly optimized. // block depends on the loader being compact and highly optimized.
let existing_lto = std::env::var("CARGO_PROFILE_RELEASE_LTO").map(|v| Some(v)).unwrap_or(None); let existing_lto = env::var("CARGO_PROFILE_RELEASE_LTO").map(Some).unwrap_or(None);
let existing_codegen_units = let existing_codegen_units =
std::env::var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS").map(|v| Some(v)).unwrap_or(None); env::var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS").map(Some).unwrap_or(None);
// these settings will generate the most compact code (but also the hardest to debug) // these settings will generate the most compact code (but also the hardest to debug)
std::env::set_var("CARGO_PROFILE_RELEASE_LTO", "true"); env::set_var("CARGO_PROFILE_RELEASE_LTO", "true");
std::env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", "1"); env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", "1");
let mut loader_extra = vec![]; let mut loader_extra = vec![];
if self.loader_disable_defaults { if self.loader_disable_defaults {
loader_extra.push("--no-default-features".to_string()); loader_extra.push("--no-default-features".to_string());
} }
let loader = self.builder( let loader = self.builder(
&vec![self.loader.clone()], &[self.loader.clone()],
&self.loader_features, &self.loader_features,
&self.target_kernel.as_deref(), &self.target_kernel.as_deref(),
BuildStream::Release, // loader doesn't fit if you build with Debug BuildStream::Release, // loader doesn't fit if you build with Debug
@ -806,17 +799,17 @@ impl Builder {
)?; )?;
// restore the LTO settings // restore the LTO settings
if let Some(existing) = existing_lto { if let Some(existing) = existing_lto {
std::env::set_var("CARGO_PROFILE_RELEASE_LTO", existing); env::set_var("CARGO_PROFILE_RELEASE_LTO", existing);
} }
if let Some(existing) = existing_codegen_units { if let Some(existing) = existing_codegen_units {
std::env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", existing); env::set_var("CARGO_PROFILE_RELEASE_CODEGEN_UNITS", existing);
} }
// ------ if targeting renode, regenerate the Platform file ----- // ------ if targeting renode, regenerate the Platform file -----
if self.run_svd2repl { if self.run_svd2repl {
Command::new(cargo()) Command::new(cargo())
.current_dir(project_root()) .current_dir(project_root())
.args(&[ .args([
"run", "run",
"-p", "-p",
"svd2repl", "svd2repl",
@ -831,9 +824,9 @@ impl Builder {
let svd_spec_path = format!( let svd_spec_path = format!(
"target/{}/{}/build/SVD_PATH", "target/{}/{}/build/SVD_PATH",
self.target.as_ref().expect("target"), self.target.as_ref().expect("target"),
self.stream.to_str() self.stream.as_str()
); );
let mut svd_spec_file = OpenOptions::new().read(true).open(&svd_spec_path)?; let mut svd_spec_file = OpenOptions::new().read(true).open(svd_spec_path)?;
let mut svd_path_str = String::new(); let mut svd_path_str = String::new();
svd_spec_file.read_to_string(&mut svd_path_str)?; svd_spec_file.read_to_string(&mut svd_path_str)?;
let mut svd_paths = Vec::new(); let mut svd_paths = Vec::new();
@ -857,7 +850,7 @@ impl Builder {
loader_presign.push("loader_presign.bin"); loader_presign.push("loader_presign.bin");
let status = Command::new(cargo()) let status = Command::new(cargo())
.current_dir(project_root()) .current_dir(project_root())
.args(&[ .args([
"run", "run",
"--package", "--package",
"tools", "tools",
@ -874,7 +867,7 @@ impl Builder {
let status = Command::new(cargo()) let status = Command::new(cargo())
.current_dir(project_root()) .current_dir(project_root())
.args(&[ .args([
"run", "run",
"--package", "--package",
"tools", "tools",
@ -900,7 +893,7 @@ impl Builder {
let status = Command::new(cargo()) let status = Command::new(cargo())
.current_dir(project_root()) .current_dir(project_root())
.args(&[ .args([
"run", "run",
"--package", "--package",
"tools", "tools",
@ -939,19 +932,8 @@ impl Builder {
inis: &[String], inis: &[String],
memory_spec: Vec<String>, memory_spec: Vec<String>,
) -> Result<PathBuf, DynError> { ) -> Result<PathBuf, DynError> {
let stream = self.stream.to_str(); let stream = self.stream.as_str();
let mut args = vec!["run", "--package", "tools", "--bin", "create-image"]; let mut args = vec!["run", "--package", "tools", "--bin", "create-image", "--"];
args.push("--features");
if self.utra_target.contains("renode") {
args.push("renode");
} else if self.utra_target.contains("precursor") {
args.push("precursor");
} else if self.utra_target.contains("atsama5d2") {
args.push("atsama5d2");
} else if self.utra_target.contains("cramium-soc") {
args.push("cramium-soc")
}
args.push("--");
let mut output_file = PathBuf::new(); let mut output_file = PathBuf::new();
output_file.push("target"); output_file.push("target");
@ -966,14 +948,14 @@ impl Builder {
for i in init { for i in init {
args.push("--init"); args.push("--init");
// strip '@' version specifiers out of the package names, if they exist. // strip '@' version specifiers out of the package names, if they exist.
let i = if i.contains("@") { i.split("@").next().unwrap() } else { i }; let i = if i.contains('@') { i.split('@').next().unwrap() } else { i };
args.push(i); args.push(i);
} }
for i in inif { for i in inif {
args.push("--inif"); args.push("--inif");
// strip '@' version specifiers out of the package names, if they exist. // strip '@' version specifiers out of the package names, if they exist.
let i = if i.contains("@") { i.split("@").next().unwrap() } else { i }; let i = if i.contains('@') { i.split('@').next().unwrap() } else { i };
args.push(i); args.push(i);
} }
@ -1002,7 +984,7 @@ impl Builder {
args.push(&memory_spec[0]); args.push(&memory_spec[0]);
for spec in memory_spec[1..].iter() { for spec in memory_spec[1..].iter() {
args.push("--extra-svd"); args.push("--extra-svd");
args.push(&spec); args.push(spec);
} }
} }
@ -1017,12 +999,11 @@ impl Builder {
fn fetch_prebuilds(&self) -> Result<Vec<String>, DynError> { fn fetch_prebuilds(&self) -> Result<Vec<String>, DynError> {
let mut paths = Vec::<String>::new(); let mut paths = Vec::<String>::new();
for item in [&self.services[..], &self.apps[..]].concat() { for item in [&self.services[..], &self.apps[..]].concat() {
match item { if let CrateSpec::Prebuilt(name, url, _region) = item {
CrateSpec::Prebuilt(name, url, _region) => {
let exec_name = format!( let exec_name = format!(
"target/{}/{}/{}", "target/{}/{}/{}",
self.target.as_ref().expect("target"), self.target.as_ref().expect("target"),
self.stream.to_str(), self.stream.as_str(),
name name
); );
println!("Fetching {} executable from build server...", name); println!("Fetching {} executable from build server...", name);
@ -1038,8 +1019,6 @@ impl Builder {
println!("{} pre-built exec is {} bytes", name, exec_file.metadata().unwrap().len()); println!("{} pre-built exec is {} bytes", name, exec_file.metadata().unwrap().len());
paths.push(exec_name); paths.push(exec_name);
} }
_ => {}
}
} }
Ok(paths) Ok(paths)
} }
@ -1047,12 +1026,9 @@ impl Builder {
fn enumerate_binary_files(&self) -> Result<Vec<String>, DynError> { fn enumerate_binary_files(&self) -> Result<Vec<String>, DynError> {
let mut paths = Vec::<String>::new(); let mut paths = Vec::<String>::new();
for item in [&self.services[..], &self.apps[..]].concat() { for item in [&self.services[..], &self.apps[..]].concat() {
match item { if let CrateSpec::BinaryFile(_name, path, _region) = item {
CrateSpec::BinaryFile(_name, path, _region) => {
paths.push(path); paths.push(path);
} }
_ => {}
}
} }
Ok(paths) Ok(paths)
} }
@ -1075,7 +1051,7 @@ impl Builder {
.truncate(true) .truncate(true)
.open("locales/src/locale.rs") .open("locales/src/locale.rs")
.expect("Can't open locale for modification"); .expect("Can't open locale for modification");
write!(locale_override, "pub const LANG: &str = \"{}\";\n", locale).unwrap(); writeln!(locale_override, "pub const LANG: &str = \"{}\";", locale).unwrap();
} }
} }

View file

@ -31,7 +31,7 @@ const PRECURSOR_SOC_VERSION: &str = "pvt";
Backups older than this cannot be parsed because the migration code for that backup Backups older than this cannot be parsed because the migration code for that backup
was deprecated. The main purpose of this field is to assist the restore script was deprecated. The main purpose of this field is to assist the restore script
in selecting a kernel: it will automatically downgrade a kernel as far as it must in selecting a kernel: it will automatically downgrade a kernel as far as it must
to read a very old backup. This tag is *not* useful for enforcing a minimum read a very old backup. This tag is *not* useful for enforcing a minimum
version of the kernel to read a very *new* backup. version of the kernel to read a very *new* backup.
Instead, when picking a kernel to restore from, the latest kernel should always be picked, Instead, when picking a kernel to restore from, the latest kernel should always be picked,
@ -118,11 +118,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// ---- extract position independent args ---- // ---- extract position independent args ----
let loader_key = get_flag("--lkey")?; let loader_key = get_flag("--lkey")?;
if loader_key.len() != 0 { if !loader_key.is_empty() {
builder.loader_key_file(loader_key[0].to_string()); builder.loader_key_file(loader_key[0].to_string());
} }
let kernel_key = get_flag("--kkey")?; let kernel_key = get_flag("--kkey")?;
if kernel_key.len() != 0 { if !kernel_key.is_empty() {
builder.kernel_key_file(kernel_key[0].to_string()); builder.kernel_key_file(kernel_key[0].to_string());
} }
let swap_key = get_flag("--swap")?; let swap_key = get_flag("--swap")?;
@ -209,36 +209,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
// ----- renode configs -------- // ----- renode configs --------
Some("renode-image") => { Some("renode-image") => {
builder builder.target_renode().add_services(&user_pkgs).add_apps(&get_cratespecs());
.target_renode()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_apps(&get_cratespecs());
} }
Some("renode-image-debug") => { Some("renode-image-debug") => {
builder builder
.target_renode() .target_renode()
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.stream(BuildStream::Debug) .stream(BuildStream::Debug)
.add_apps(&get_cratespecs()); .add_apps(&get_cratespecs());
} }
Some("renode-test") => { Some("renode-test") => {
builder builder.target_renode().add_services(&base_pkgs).add_services(&get_cratespecs());
.target_renode()
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
} }
Some("libstd-test") => { Some("libstd-test") => {
builder builder.target_renode().add_services(&base_pkgs).add_services(&get_cratespecs());
.target_renode()
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.add_loader_feature("renode-bypass"); builder.add_loader_feature("renode-bypass");
} }
Some("libstd-net") => { Some("libstd-net") => {
builder builder.target_renode().add_services(&base_pkgs).add_services(&get_cratespecs());
.target_renode()
.add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.add_loader_feature("renode-bypass").add_loader_feature("renode-minimal"); builder.add_loader_feature("renode-bypass").add_loader_feature("renode-minimal");
builder builder
.add_service("net", LoaderRegion::Ram) .add_service("net", LoaderRegion::Ram)
@ -247,16 +235,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_service("dns", LoaderRegion::Ram); .add_service("dns", LoaderRegion::Ram);
} }
Some("renode-aes-test") => { Some("renode-aes-test") => {
builder builder.target_renode().add_services(&aes_test_pkgs).add_services(&get_cratespecs());
.target_renode()
.add_services(&aes_test_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
} }
Some("ffi-test") => { Some("ffi-test") => {
builder builder.target_renode().add_services(&gfx_base_pkgs).add_services(&get_cratespecs());
.target_renode()
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.add_service("ffi-test", LoaderRegion::Ram); builder.add_service("ffi-test", LoaderRegion::Ram);
builder.add_loader_feature("renode-bypass"); builder.add_loader_feature("renode-bypass");
} }
@ -280,7 +262,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("run") => { Some("run") => {
builder builder
.target_hosted() .target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("pddbtest") .add_feature("pddbtest")
.add_feature("ditherpunk") .add_feature("ditherpunk")
.add_feature("tracking-alloc") .add_feature("tracking-alloc")
@ -291,14 +273,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("pddb-ci") => { Some("pddb-ci") => {
builder builder
.target_hosted() .target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("pddb/ci") .add_feature("pddb/ci")
.add_feature("pddb/deterministic"); .add_feature("pddb/deterministic");
} }
Some("pddb-btest") => { Some("pddb-btest") => {
builder builder
.target_hosted() .target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("pddbtest") .add_feature("pddbtest")
.add_feature("autobasis") // this will make secret basis tracking synthetic and automated for stress testing .add_feature("autobasis") // this will make secret basis tracking synthetic and automated for stress testing
.add_feature("autobasis-ci") .add_feature("autobasis-ci")
@ -307,7 +289,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("hosted-debug") => { Some("hosted-debug") => {
builder builder
.target_hosted() .target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("pddbtest") .add_feature("pddbtest")
.add_feature("ditherpunk") .add_feature("ditherpunk")
.add_feature("tracking-alloc") .add_feature("tracking-alloc")
@ -318,30 +300,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("gfx-dev") => { Some("gfx-dev") => {
builder builder
.target_hosted() .target_hosted()
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect()) .add_services(&gfx_base_pkgs)
.add_services(&get_cratespecs()) .add_services(&get_cratespecs())
.add_feature("graphics-server/gfx-testing"); .add_feature("graphics-server/gfx-testing");
} }
Some("hosted-ci") => { Some("hosted-ci") => {
builder builder.target_hosted().add_services(&user_pkgs).hosted_build_only().add_apps(&get_cratespecs());
.target_hosted()
.add_services(&user_pkgs.into_iter().map(String::from).collect())
.hosted_build_only()
.add_apps(&get_cratespecs());
} }
// ------ Precursor hardware image configs ------ // ------ Precursor hardware image configs ------
Some("app-image") => { Some("app-image") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("mass-storage") // add this in by default to help with testing .add_feature("mass-storage") // add this in by default to help with testing
.add_apps(&get_cratespecs()); .add_apps(&get_cratespecs());
} }
Some("app-image-xip") => { Some("app-image-xip") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
//.add_services(&user_pkgs.into_iter().map(String::from).collect()) //.add_services(&user_pkgs)
.add_feature("mass-storage"); // add this in by default to help with testing .add_feature("mass-storage"); // add this in by default to help with testing
for service in user_pkgs { for service in user_pkgs {
if (service != "shellchat") && (service != "ime-plugin-shell" && (service != "net")) { if (service != "shellchat") && (service != "ime-plugin-shell" && (service != "net")) {
@ -371,7 +349,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// by the usb_update script. // by the usb_update script.
builder builder
.target_precursor("c809403-perflib") .target_precursor("c809403-perflib")
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_apps(&get_cratespecs()) .add_apps(&get_cratespecs())
.add_feature("perfcounter") .add_feature("perfcounter")
.add_kernel_feature("v2p"); .add_kernel_feature("v2p");
@ -399,7 +377,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
pkgs.push("ime-plugin-tts"); pkgs.push("ime-plugin-tts");
pkgs.retain(|&pkg| pkg != "ime-plugin-shell"); pkgs.retain(|&pkg| pkg != "ime-plugin-shell");
builder.add_services(&pkgs.into_iter().map(String::from).collect()) builder.add_services(&pkgs)
.add_apps(&get_cratespecs()) .add_apps(&get_cratespecs())
.add_service("espeak-embedded#https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/espeak-embedded", .add_service("espeak-embedded#https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/espeak-embedded",
LoaderRegion::Ram) LoaderRegion::Ram)
@ -410,13 +388,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("tiny") => { Some("tiny") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .add_services(&base_pkgs)
.add_services(&get_cratespecs()); .add_services(&get_cratespecs());
} }
Some("usbdev") => { Some("usbdev") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .add_services(&base_pkgs)
.add_services(&get_cratespecs()); .add_services(&get_cratespecs());
//builder.add_service("usb-test"); //builder.add_service("usb-test");
builder.add_service("usb-device-xous", LoaderRegion::Ram); builder.add_service("usb-device-xous", LoaderRegion::Ram);
@ -424,31 +402,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("pddb-dev") => { Some("pddb-dev") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&pddb_dev_pkgs.into_iter().map(String::from).collect()) .add_services(&pddb_dev_pkgs)
.add_services(&get_cratespecs()); .add_services(&get_cratespecs());
} }
Some("trng-test") => { Some("trng-test") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("urandomtest"); .add_feature("urandomtest");
} }
Some("ro-test") => { Some("ro-test") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("ringosctest"); .add_feature("ringosctest");
} }
Some("av-test") => { Some("av-test") => {
builder builder
.target_precursor(PRECURSOR_SOC_VERSION) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .add_services(&user_pkgs)
.add_feature("avalanchetest"); .add_feature("avalanchetest");
} }
Some("compile-apps") => { Some("compile-apps") => {
builder builder.target_precursor_no_image(PRECURSOR_SOC_VERSION).add_services(&gfx_base_pkgs);
.target_precursor_no_image(PRECURSOR_SOC_VERSION)
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect());
} }
// ------ Cramium hardware image configs ------ // ------ Cramium hardware image configs ------
@ -473,11 +449,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some("arm-tiny") => { Some("arm-tiny") => {
builder builder
.target_arm() .target_arm()
.add_services(&vec![ .add_services([
"xous-log".to_string(), "xous-log",
"xous-ticktimer".to_string(), "xous-ticktimer",
"xous-names".to_string(), "xous-names",
"ticktimer-test-client".to_string(), "ticktimer-test-client",
]) ])
.add_kernel_feature("v2p") // required to use LCD DMA with lcd-console .add_kernel_feature("v2p") // required to use LCD DMA with lcd-console
.add_feature("atsama5d27") .add_feature("atsama5d27")

View file

@ -82,7 +82,7 @@ fn get_sysroot(target: Option<&str>, check_version: bool) -> Result<Option<Strin
version_path.push("RUST_VERSION"); version_path.push("RUST_VERSION");
if let Ok(mut vp) = File::open(&version_path) { if let Ok(mut vp) = File::open(&version_path) {
let mut version_str = String::new(); let mut version_str = String::new();
if let Err(_) = vp.read_to_string(&mut version_str) { if vp.read_to_string(&mut version_str).is_err() {
return Err("Unable to get version string".to_owned()); return Err("Unable to get version string".to_owned());
} }
@ -102,12 +102,10 @@ fn get_sysroot(target: Option<&str>, check_version: bool) -> Result<Option<Strin
// return Err("Outdated toolchain installed".to_owned()); // return Err("Outdated toolchain installed".to_owned());
return Ok(None); return Ok(None);
} }
} else { } else if !Path::new(&version_path).exists() {
if !std::path::Path::new(&version_path).exists() {
return Ok(None); return Ok(None);
} }
} }
}
if have_toolchain { Ok(Some(toolchain_path)) } else { Ok(None) } if have_toolchain { Ok(Some(toolchain_path)) } else { Ok(None) }
} }
@ -145,7 +143,7 @@ pub(crate) fn ensure_kernel_compiler(target: &Option<&str>, force_install: bool)
let rustup_command = Command::new("rustup") let rustup_command = Command::new("rustup")
.stderr(Stdio::null()) .stderr(Stdio::null())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.args(&["target", "add", target]) .args(["target", "add", target])
.spawn() .spawn()
.map_err(|e| format!("could not run rustup: {}", e))?; .map_err(|e| format!("could not run rustup: {}", e))?;
@ -184,7 +182,7 @@ pub(crate) fn ensure_compiler(
if remove_existing { if remove_existing {
println!("Target path exists, removing it"); println!("Target path exists, removing it");
std::fs::remove_dir_all(version_path) std::fs::remove_dir_all(version_path)
.or_else(|e| Err(format!("unable to remove existing toolchain: {}", e)))?; .map_err(|e| format!("unable to remove existing toolchain: {}", e))?;
println!("Also removing target directories for existing toolchain"); println!("Also removing target directories for existing toolchain");
let mut target_main = project_root(); let mut target_main = project_root();
target_main.push("target"); target_main.push("target");
@ -234,7 +232,7 @@ pub(crate) fn ensure_compiler(
let url = TOOLCHAIN_RELEASE_URLS let url = TOOLCHAIN_RELEASE_URLS
.get(target) .get(target)
.ok_or_else(|| format!("Can't find toolchain URL for target {}", target))?; .ok_or_else(|| format!("Can't find toolchain URL for target {}", target))?;
let j: serde_json::Value = ureq::get(&url) let j: serde_json::Value = ureq::get(url)
.set("Accept", "application/vnd.github.v3+json") .set("Accept", "application/vnd.github.v3+json")
.call() .call()
.map_err(|e| format!("{}", e))? .map_err(|e| format!("{}", e))?
@ -272,7 +270,7 @@ pub(crate) fn ensure_compiler(
}, },
}; };
let first_asset = match assets.get(0) { let first_asset = match assets.first() {
None => continue, None => continue,
Some(s) => s, Some(s) => s,
}; };
@ -313,7 +311,7 @@ pub(crate) fn ensure_compiler(
/// Extract the zipfile to the target directory, ensuring that all files /// Extract the zipfile to the target directory, ensuring that all files
/// contained within are created. /// contained within are created.
fn extract_zip<P: std::io::Read + std::io::Seek, P2: AsRef<Path>>( fn extract_zip<P: Read + std::io::Seek, P2: AsRef<Path>>(
archive_data: P, archive_data: P,
extract_to: P2, extract_to: P2,
) -> Result<(), String> { ) -> Result<(), String> {
@ -335,12 +333,12 @@ pub(crate) fn ensure_compiler(
// Create the parent directory if necessary // Create the parent directory if necessary
if let Some(parent) = output_path.parent() { if let Some(parent) = output_path.parent() {
if !parent.exists() { if !parent.exists() {
std::fs::create_dir_all(&parent).map_err(|e| { std::fs::create_dir_all(parent).map_err(|e| {
format!("unable to create directory {}: {}", output_path.display(), e) format!("unable to create directory {}: {}", output_path.display(), e)
})?; })?;
} }
} }
let mut outfile = std::fs::File::create(&output_path) let mut outfile = File::create(&output_path)
.map_err(|e| format!("unable to create file {}: {}", output_path.display(), e))?; .map_err(|e| format!("unable to create file {}: {}", output_path.display(), e))?;
std::io::copy(&mut entry_in_archive, &mut outfile).map_err(|e| { std::io::copy(&mut entry_in_archive, &mut outfile).map_err(|e| {
format!("unable to write extracted file {}: {}", output_path.display(), e) format!("unable to write extracted file {}: {}", output_path.display(), e)
@ -364,11 +362,11 @@ pub(crate) fn generate_locales() -> Result<(), std::io::Error> {
filetime::set_file_mtime("locales/src/lib.rs", ts)?; filetime::set_file_mtime("locales/src/lib.rs", ts)?;
let mut path = project_root(); let mut path = project_root();
path.push("locales"); path.push("locales");
let status = Command::new(cargo()).current_dir(path).args(&["build", "--package", "locales"]).status()?; let status = Command::new(cargo()).current_dir(path).args(["build", "--package", "locales"]).status()?;
if !status.success() { if !status.success() {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Couldn't generate the locales")); return Err(std::io::Error::new(std::io::ErrorKind::Other, "Couldn't generate the locales"));
} }
return Ok(()); Ok(())
} }
/// Import the Wycheproof test vectors /// Import the Wycheproof test vectors
@ -377,7 +375,7 @@ pub(crate) fn wycheproof_import() -> Result<(), crate::DynError> {
let output_file = "services/shellchat/src/cmds/x25519_test.bin"; let output_file = "services/shellchat/src/cmds/x25519_test.bin";
let status = Command::new(cargo()) let status = Command::new(cargo())
.current_dir(project_root()) .current_dir(project_root())
.args(&["run", "--package", "wycheproof-import", "--", input_file, output_file]) .args(["run", "--package", "wycheproof-import", "--", input_file, output_file])
.status()?; .status()?;
if !status.success() { if !status.success() {
return Err("wycheproof-import failed. If any, the output will not be usable.".into()); return Err("wycheproof-import failed. If any, the output will not be usable.".into());
@ -386,23 +384,23 @@ pub(crate) fn wycheproof_import() -> Result<(), crate::DynError> {
println!(); println!();
println!("Wrote wycheproof x25519 testvectors to '{}'.", output_file); println!("Wrote wycheproof x25519 testvectors to '{}'.", output_file);
return Ok(()); Ok(())
} }
pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynError> { pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynError> {
let last_config = "target/LAST_LANG"; let last_config = "target/LAST_LANG";
let mut contents = String::new(); let mut contents = String::new();
let changed = match OpenOptions::new().read(true).open(&last_config) { let changed = match OpenOptions::new().read(true).open(last_config) {
Ok(mut file) => { Ok(mut file) => {
file.read_to_string(&mut contents).unwrap(); file.read_to_string(&mut contents).unwrap();
if contents != last_lang { true } else { false } contents != last_lang
} }
_ => true, _ => true,
}; };
if changed { if changed {
println!("Locale language changed to {}", last_lang); println!("Locale language changed to {}", last_lang);
let mut file = OpenOptions::new().create(true).write(true).truncate(true).open(&last_config).unwrap(); let mut file = OpenOptions::new().create(true).write(true).truncate(true).open(last_config).unwrap();
write!(file, "{}", last_lang).unwrap(); write!(file, "{}", last_lang).unwrap();
generate_locales()? generate_locales()?
} else { } else {

View file

@ -53,7 +53,7 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
cache_leaf.push_str(&regdir); cache_leaf.push_str(&regdir);
} }
} }
if cache_leaf.len() == 0 { if cache_leaf.is_empty() {
return Err("Can't find expected registry source location".into()); return Err("Can't find expected registry source location".into());
} }
// this now has the path to the cache directory // this now has the path to the cache directory
@ -79,8 +79,7 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
&& name != "svd2utra" && name != "svd2utra"
{ {
Path::new(&subdir) Path::new(&subdir)
} else { } else if name == "xous" {
if name == "xous" {
Path::new("./xous-rs") Path::new("./xous-rs")
} else if name == "xous-ipc" { } else if name == "xous-ipc" {
Path::new("./xous-ipc") Path::new("./xous-ipc")
@ -92,7 +91,6 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
Path::new("./svd2utra") Path::new("./svd2utra")
} else { } else {
panic!("Consistency error: special case handling did not find either xous or xous-ipc"); panic!("Consistency error: special case handling did not find either xous or xous-ipc");
}
}; };
// now recurse through the source path and check that it matches the cache, except for Cargo.toml // now recurse through the source path and check that it matches the cache, except for Cargo.toml

View file

@ -1,5 +1,5 @@
// Versioning infrastructure // Versioning infrastructure
// This generates the SEMVER data that is displayed when quering `xous ver` // This generates the SEMVER data that is displayed when querying `xous ver`
// It also generates timestamps, if demanded. // It also generates timestamps, if demanded.
use std::fs::OpenOptions; use std::fs::OpenOptions;
@ -46,10 +46,10 @@ pub(crate) fn generate_version(add_timestamp: bool) {
write!(new_data, "#[allow(dead_code)]\npub const TIMESTAMP: &'static str = \"unavailable\";\n") write!(new_data, "#[allow(dead_code)]\npub const TIMESTAMP: &'static str = \"unavailable\";\n")
.expect("couldn't add our timestamp"); .expect("couldn't add our timestamp");
} }
write!( writeln!(
new_data, new_data,
"pub const SEMVER: &'static str = \"{}\";\n", "pub const SEMVER: &'static str = \"{}\";",
semver.strip_suffix("\r\n").or(semver.strip_suffix("\n")).unwrap_or(&semver) semver.strip_suffix("\r\n").or(semver.strip_suffix('\n')).unwrap_or(&semver)
) )
.expect("couldn't add our semver"); .expect("couldn't add our semver");
@ -61,7 +61,7 @@ pub(crate) fn generate_version(add_timestamp: bool) {
.truncate(true) .truncate(true)
.open(version_file) .open(version_file)
.expect("Can't open our version file for writing"); .expect("Can't open our version file for writing");
vfile.write_all(&mut new_data).expect("couldn't write new timestamp to version.rs"); vfile.write_all(&new_data).expect("couldn't write new timestamp to version.rs");
} }
} }