Merge pull request #476 from kotval/out_of_tree_app

Modify xtask to permit named BinaryFile
This commit is contained in:
bunnie 2024-01-09 04:08:23 +08:00 committed by GitHub
commit 3c3435f0dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 305 additions and 228 deletions

18
Cargo.lock generated
View file

@ -40,7 +40,7 @@ dependencies = [
name = "aes" name = "aes"
version = "0.8.1" version = "0.8.1"
dependencies = [ dependencies = [
"cipher 0.4.3", "cipher 0.4.4",
] ]
[[package]] [[package]]
@ -51,7 +51,7 @@ checksum = "ae0784134ba9375416d469ec31e7c5f9fa94405049cf08c5ce5b4698be673e0d"
dependencies = [ dependencies = [
"aead", "aead",
"aes 0.8.1", "aes 0.8.1",
"cipher 0.4.3", "cipher 0.4.4",
"ctr", "ctr",
"polyval", "polyval",
"subtle", "subtle",
@ -488,7 +488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"cipher 0.4.3", "cipher 0.4.4",
] ]
[[package]] [[package]]
@ -563,7 +563,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
dependencies = [ dependencies = [
"cipher 0.4.3", "cipher 0.4.4",
] ]
[[package]] [[package]]
@ -679,9 +679,9 @@ dependencies = [
[[package]] [[package]]
name = "cipher" name = "cipher"
version = "0.4.3" version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [ dependencies = [
"crypto-common", "crypto-common",
"inout", "inout",
@ -1180,7 +1180,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d14f329cfbaf5d0e06b5e87fff7e265d2673c5ea7d2c27691a2c107db1442a0" checksum = "0d14f329cfbaf5d0e06b5e87fff7e265d2673c5ea7d2c27691a2c107db1442a0"
dependencies = [ dependencies = [
"cipher 0.4.3", "cipher 0.4.4",
] ]
[[package]] [[package]]
@ -3352,7 +3352,7 @@ dependencies = [
"bitfield", "bitfield",
"bitflags 1.3.2", "bitflags 1.3.2",
"blowfish 0.9.1", "blowfish 0.9.1",
"cipher 0.4.3", "cipher 0.4.4",
"digest 0.9.0", "digest 0.9.0",
"gam", "gam",
"hex 0.4.3", "hex 0.4.3",
@ -4079,7 +4079,7 @@ dependencies = [
"aes-kw", "aes-kw",
"blowfish 0.8.0", "blowfish 0.8.0",
"byteorder", "byteorder",
"cipher 0.4.3", "cipher 0.4.4",
"com", "com",
"curve25519-dalek", "curve25519-dalek",
"digest 0.9.0", "digest 0.9.0",

View file

@ -1,19 +1,19 @@
// This module supports generating the app menus from the JSON manifest in the apps/ directory. // This module supports generating the app menus from the JSON manifest in the apps/ directory.
use std::{
fs::{OpenOptions, File},
io::{Read, Write},
string::String,
fmt::Write as StdWrite,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use std::{
fmt::Write as StdWrite,
fs::{File, OpenOptions},
io::{Read, Write},
string::String,
};
#[derive(Deserialize, Serialize, Debug)] #[derive(Deserialize, Serialize, Debug)]
struct AppManifest { struct AppManifest {
context_name: String, context_name: String,
menu_name: HashMap<String, HashMap<String, String>>, menu_name: HashMap<String, HashMap<String, String>>,
submenu: Option::<u8>, submenu: Option<u8>,
} }
#[derive(Deserialize, Serialize, Debug)] #[derive(Deserialize, Serialize, Debug)]
struct Locales { struct Locales {
@ -89,9 +89,14 @@ pub(crate) fn generate_app_menus(apps: &Vec<String>) {
gam_tokens, gam_tokens,
"\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &[" "\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &["
) )
.unwrap(); .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!( writeln!(

View file

@ -22,7 +22,7 @@ impl BuildStream {
} }
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub enum CrateSpec { pub enum CrateSpec {
/// name of the crate /// name of the crate
Local(String, bool), Local(String, bool),
@ -30,8 +30,8 @@ pub enum CrateSpec {
CratesIo(String, String, bool), CratesIo(String, String, bool),
/// a prebuilt package: (name of executable, URL for download) /// a prebuilt package: (name of executable, URL for download)
Prebuilt(String, String, bool), Prebuilt(String, String, bool),
/// a prebuilt binary, done using command line tools /// a prebuilt binary, done using command line tools: (Optional name, path)
BinaryFile(String, bool), BinaryFile(Option<String>, String, bool),
/// an empty entry /// an empty entry
None, None,
} }
@ -41,16 +41,17 @@ impl CrateSpec {
CrateSpec::Local(_s, xip) => *xip, CrateSpec::Local(_s, xip) => *xip,
CrateSpec::CratesIo(_n, _v, xip) => *xip, CrateSpec::CratesIo(_n, _v, xip) => *xip,
CrateSpec::Prebuilt(_n, _u, xip) => *xip, CrateSpec::Prebuilt(_n, _u, xip) => *xip,
CrateSpec::BinaryFile(_path, xip) => *xip, CrateSpec::BinaryFile(_n, _path, xip) => *xip,
_ => false _ => false
} }
} }
pub fn set_xip(&mut self, xip: bool) { pub fn set_xip(&mut self, xip: bool) {
*self = match self { *self = match self {
//TODO: why do these to_strings need to be here?
CrateSpec::Local(s, _xip) => CrateSpec::Local(s.to_string(), xip), CrateSpec::Local(s, _xip) => CrateSpec::Local(s.to_string(), xip),
CrateSpec::CratesIo(n, v, _xip) => CrateSpec::CratesIo(n.to_string(), v.to_string(), xip), CrateSpec::CratesIo(n, v, _xip) => CrateSpec::CratesIo(n.to_string(), v.to_string(), xip),
CrateSpec::Prebuilt(n, u, _xip) => CrateSpec::Prebuilt(n.to_string(), u.to_string(), xip), CrateSpec::Prebuilt(n, u, _xip) => CrateSpec::Prebuilt(n.to_string(), u.to_string(), xip),
CrateSpec::BinaryFile(path, _xip) => CrateSpec::BinaryFile(path.to_string(), xip), CrateSpec::BinaryFile(n, path, _xip) => CrateSpec::BinaryFile(n.as_ref().or(None).cloned(), path.to_string(), xip),
CrateSpec::None => CrateSpec::None, CrateSpec::None => CrateSpec::None,
} }
} }
@ -59,22 +60,18 @@ impl CrateSpec {
CrateSpec::Local(s, _xip) => Some(s.to_string()), CrateSpec::Local(s, _xip) => Some(s.to_string()),
CrateSpec::CratesIo(n, _v, _xip) => Some(n.to_string()), CrateSpec::CratesIo(n, _v, _xip) => Some(n.to_string()),
CrateSpec::Prebuilt(n, _u, _xip) => Some(n.to_string()), CrateSpec::Prebuilt(n, _u, _xip) => Some(n.to_string()),
CrateSpec::BinaryFile(path, _xip) => Some(path.to_string()), CrateSpec::BinaryFile(n, path, _xip) => {
if let Some(name) = n {
Some(name.to_string())
}
else {
Some(path.to_string())
}
},
_ => None, _ => None,
} }
} }
} }
impl Clone for CrateSpec {
fn clone(&self) -> CrateSpec {
match self {
CrateSpec::Local(s, xip) => CrateSpec::Local(s.to_string(), *xip),
CrateSpec::CratesIo(n, v, xip) => CrateSpec::CratesIo(n.to_string(), v.to_string(), *xip),
CrateSpec::Prebuilt(n, u, xip) => CrateSpec::Prebuilt(n.to_string(), u.to_string(), *xip),
CrateSpec::BinaryFile(path, xip) => CrateSpec::BinaryFile(path.to_string(), *xip),
CrateSpec::None => CrateSpec::None,
}
}
}
impl From<&str> for CrateSpec { impl From<&str> for CrateSpec {
fn from(spec: &str) -> CrateSpec { fn from(spec: &str) -> CrateSpec {
// remote crates are specified as "name@version", i.e. "xous-names@0.9.9" // remote crates are specified as "name@version", i.e. "xous-names@0.9.9"
@ -99,7 +96,13 @@ impl From<&str> for CrateSpec {
// Note that this is after a test for the '#' character, so that disambiguates URL slashes // Note that this is after a test for the '#' character, so that disambiguates URL slashes
// It does mean that files with a '#' character in them are mistaken for URL coded paths, and '@' as remote crates. // It does mean that files with a '#' character in them are mistaken for URL coded paths, and '@' as remote crates.
} else if spec.contains('/') || spec.contains('\\') { } else if spec.contains('/') || spec.contains('\\') {
CrateSpec::BinaryFile(spec.to_string(), false) //optionally a BinaryFile can have a name associated with it as "name:path"
if spec.find(':').is_some() {
let (name,path) = spec.split_once(':').unwrap();
CrateSpec::BinaryFile(Some(name.to_string()), path.to_string(), false)
} else {
CrateSpec::BinaryFile(None, spec.to_string(), false)
}
} else { } else {
CrateSpec::Local(spec.to_string(), false) CrateSpec::Local(spec.to_string(), false)
} }
@ -323,7 +326,6 @@ impl Builder {
} }
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<'a>(&'a mut self, feature: &str) -> &'a mut Builder {
self.features.push(feature.into()); self.features.push(feature.into());
@ -595,6 +597,12 @@ impl Builder {
match app { match app {
CrateSpec::Local(name, _xip) => app_names.push(name.into()), CrateSpec::Local(name, _xip) => app_names.push(name.into()),
CrateSpec::CratesIo(name, _version, _xip) => app_names.push(name.into()), CrateSpec::CratesIo(name, _version, _xip) => app_names.push(name.into()),
CrateSpec::BinaryFile(name, _location, _xip) => {
// if binary file has a name, ensure it ends up in the app menu
if let Some(n) = name {
app_names.push(n.to_string())
} else {}
},
_ => {} _ => {}
} }
} }
@ -930,7 +938,7 @@ impl Builder {
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 { match item {
CrateSpec::BinaryFile(path, _xip) => { CrateSpec::BinaryFile(_name, path, _xip) => {
paths.push(path); paths.push(path);
} }
_ => {} _ => {}

View file

@ -60,22 +60,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// A base set of packages. This is all you need for a normal // A base set of packages. This is all you need for a normal
// operating system that can run libstd // operating system that can run libstd
let base_pkgs = [ let base_pkgs = [
"xous-ticktimer", // "well known" service: thread scheduling "xous-ticktimer", // "well known" service: thread scheduling
"xous-log", // "well known" service: debug logging "xous-log", // "well known" service: debug logging
"xous-names", // "well known" service: manage inter-server connection lookup "xous-names", // "well known" service: manage inter-server connection lookup
"xous-susres", // ticktimer registers with susres to coordinate time continuity across sleeps "xous-susres", // ticktimer registers with susres to coordinate time continuity across sleeps
].to_vec(); ]
.to_vec();
// minimal set of packages to do bare-iron graphical I/O // minimal set of packages to do bare-iron graphical I/O
let gfx_base_pkgs = [ let gfx_base_pkgs = [
&base_pkgs[..], &base_pkgs[..],
&[ &[
"graphics-server", // raw (unprotected) frame buffer primitives "graphics-server", // raw (unprotected) frame buffer primitives
"early_settings", // required by keyboard "early_settings", // required by keyboard
"keyboard", // required by graphics-server "keyboard", // required by graphics-server
"spinor", // required by keyboard - to save key mapping "spinor", // required by keyboard - to save key mapping
"llio", // required by spinor "llio", // required by spinor
] ],
].concat(); ]
.concat();
// packages in the user image - most of the services at this layer have cross-dependencies // packages in the user image - most of the services at this layer have cross-dependencies
let user_pkgs = [ let user_pkgs = [
&gfx_base_pkgs[..], &gfx_base_pkgs[..],
@ -103,16 +105,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"pddb", "pddb",
// usb services // usb services
"usb-device-xous", "usb-device-xous",
]
].concat();
// for fast testing of compilation targets of the PDDB to real hardware
let pddb_dev_pkgs = [
&base_pkgs[..],
&[
"pddb",
"sha2",
], ],
].concat(); ]
.concat();
// for fast testing of compilation targets of the PDDB to real hardware
let pddb_dev_pkgs = [&base_pkgs[..], &["pddb", "sha2"]].concat();
// for fast checking of AES hardware accelerator // for fast checking of AES hardware accelerator
let aestest_pkgs = ["xous-ticktimer", "xous-log", "aes-test"].to_vec(); let aestest_pkgs = ["xous-ticktimer", "xous-log", "aes-test"].to_vec();
@ -145,7 +142,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
builder.add_kernel_feature(&feature); builder.add_kernel_feature(&feature);
} }
if !language_set { // the default language is english if !language_set {
// the default language is english
track_language_changes("en")?; track_language_changes("en")?;
} }
let gdb_stub = env::args().filter(|x| x == "--gdb-stub").count() != 0; let gdb_stub = env::args().filter(|x| x == "--gdb-stub").count() != 0;
@ -170,112 +168,130 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
// ----- renode configs -------- // ----- renode configs --------
Some("renode-image") => { Some("renode-image") => {
builder.target_renode() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_renode()
.add_apps(&get_cratespecs()); .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_apps(&get_cratespecs());
} }
Some("renode-image-debug") => { Some("renode-image-debug") => {
builder.target_renode() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_renode()
.stream(BuildStream::Debug) .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_apps(&get_cratespecs()); .stream(BuildStream::Debug)
.add_apps(&get_cratespecs());
} }
Some("renode-test") => { Some("renode-test") => {
builder.target_renode() builder
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .target_renode()
.add_services(&get_cratespecs()); .add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
} }
Some("libstd-test") => { Some("libstd-test") => {
builder.target_renode() builder
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .target_renode()
.add_services(&get_cratespecs()); .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.target_renode() builder
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .target_renode()
.add_services(&get_cratespecs()); .add_services(&base_pkgs.into_iter().map(String::from).collect())
builder.add_loader_feature("renode-bypass") .add_services(&get_cratespecs());
.add_loader_feature("renode-minimal"); builder
builder.add_service("net", false) .add_loader_feature("renode-bypass")
.add_loader_feature("renode-minimal");
builder
.add_service("net", false)
.add_service("com", false) .add_service("com", false)
.add_service("llio", false) .add_service("llio", false)
.add_service("dns", false); .add_service("dns", false);
} }
Some("renode-aes-test") => { Some("renode-aes-test") => {
builder.target_renode() builder
.add_services(&aestest_pkgs.into_iter().map(String::from).collect()) .target_renode()
.add_services(&get_cratespecs()); .add_services(&aestest_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
} }
Some("ffi-test") => { Some("ffi-test") => {
builder.target_renode() builder
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect()) .target_renode()
.add_services(&get_cratespecs()); .add_services(&gfx_base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
builder.add_service("ffi-test", false); builder.add_service("ffi-test", false);
builder.add_loader_feature("renode-bypass"); builder.add_loader_feature("renode-bypass");
} }
// ------- hosted mode configs ------- // ------- hosted mode configs -------
Some("run") => { Some("run") => {
builder.target_hosted() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_hosted()
.add_feature("pddbtest") .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("ditherpunk") .add_feature("pddbtest")
.add_feature("tracking-alloc") .add_feature("ditherpunk")
.add_feature("tls") .add_feature("tracking-alloc")
// .add_feature("test-rekey") .add_feature("tls")
.add_apps(&get_cratespecs()); // .add_feature("test-rekey")
.add_apps(&get_cratespecs());
} }
Some("pddb-ci") => { Some("pddb-ci") => {
builder.target_hosted() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_hosted()
.add_feature("pddb/ci") .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("pddb/deterministic"); .add_feature("pddb/ci")
.add_feature("pddb/deterministic");
} }
Some("pddb-btest") => { Some("pddb-btest") => {
builder.target_hosted() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_hosted()
.add_feature("pddbtest") .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("autobasis") // this will make secret basis tracking synthetic and automated for stress testing .add_feature("pddbtest")
.add_feature("autobasis-ci") .add_feature("autobasis") // this will make secret basis tracking synthetic and automated for stress testing
.add_feature("pddb/deterministic"); .add_feature("autobasis-ci")
.add_feature("pddb/deterministic");
} }
Some("hosted-debug") => { Some("hosted-debug") => {
builder.target_hosted() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_hosted()
.add_feature("pddbtest") .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("ditherpunk") .add_feature("pddbtest")
.add_feature("tracking-alloc") .add_feature("ditherpunk")
.add_feature("tls") .add_feature("tracking-alloc")
.stream(BuildStream::Debug) .add_feature("tls")
.add_apps(&get_cratespecs()); .stream(BuildStream::Debug)
.add_apps(&get_cratespecs());
} }
Some("gfx-dev") => { Some("gfx-dev") => {
builder.target_hosted() builder
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect()) .target_hosted()
.add_services(&get_cratespecs()) .add_services(&gfx_base_pkgs.into_iter().map(String::from).collect())
.add_feature("graphics-server/gfx-testing"); .add_services(&get_cratespecs())
}, .add_feature("graphics-server/gfx-testing");
}
Some("hosted-ci") => { Some("hosted-ci") => {
builder.target_hosted() builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_hosted()
.hosted_build_only() .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_apps(&get_cratespecs()); .hosted_build_only()
.add_apps(&get_cratespecs());
} }
// ------ Precursor hardware image configs ------ // ------ Precursor hardware image configs ------
Some("app-image") => { Some("app-image") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_feature("mass-storage") // add this in by default to help with testing .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_apps(&get_cratespecs()); .add_feature("mass-storage") // add this in by default to help with testing
.add_apps(&get_cratespecs());
} }
Some("app-image-xip") => { Some("app-image-xip") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
//.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_feature("mass-storage"); // add this in by default to help with testing //.add_services(&user_pkgs.into_iter().map(String::from).collect())
.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"))
{
builder.add_service(service, false); builder.add_service(service, false);
} else { } else {
builder.add_service(service, true); builder.add_service(service, true);
@ -298,26 +314,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// ` python3 .\..\usb_update.py --dump v2p.txt --dump-file .\ring_aes_8.bin` // ` python3 .\..\usb_update.py --dump v2p.txt --dump-file .\ring_aes_8.bin`
// where the `v2p.txt` file contains a virtual to physical mapping that is generated by the `perflib` framework and // where the `v2p.txt` file contains a virtual to physical mapping that is generated by the `perflib` framework and
// formatted in a fashion that can be automatically extracted by the usb_update script. // formatted in a fashion that can be automatically extracted by the usb_update script.
builder.target_precursor("c809403-perflib") builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_precursor("c809403-perflib")
.add_apps(&get_cratespecs()) .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("perfcounter") .add_apps(&get_cratespecs())
.add_kernel_feature("v2p"); .add_feature("perfcounter")
.add_kernel_feature("v2p");
} }
Some("dvt-image") => { Some("dvt-image") => {
// this image targets a mostly deprecated DVT hardware generation. The purpose of it is to re-use some // this image targets a mostly deprecated DVT hardware generation. The purpose of it is to re-use some
// of the now-defunct hardware for eFuse code testing, especially since FPGAs have gotten very scarce. // of the now-defunct hardware for eFuse code testing, especially since FPGAs have gotten very scarce.
// Once the eFuse path is validated, we could remove this target. // Once the eFuse path is validated, we could remove this target.
let mut services: Vec<String> = user_pkgs let mut services: Vec<String> = user_pkgs.into_iter().map(String::from).collect();
.into_iter()
.map(String::from).collect();
services.retain(|x| x != "codec"); // codec is not compatible with DVT boards services.retain(|x| x != "codec"); // codec is not compatible with DVT boards
builder.target_precursor("2753c12-dvt") builder
.add_services(&services) .target_precursor("2753c12-dvt")
.add_feature("no-codec") .add_services(&services)
.add_feature("dvt") .add_feature("no-codec")
.add_apps(&get_cratespecs()); .add_feature("dvt")
.add_apps(&get_cratespecs());
} }
Some("tts") => { Some("tts") => {
builder.target_precursor(PRECURSOR_SOC_VERSION); builder.target_precursor(PRECURSOR_SOC_VERSION);
@ -335,50 +351,53 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_feature("braille"); .add_feature("braille");
} }
Some("tiny") => { Some("tiny") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&get_cratespecs()); .add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
} }
Some("usbdev") => { Some("usbdev") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&base_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&get_cratespecs()); .add_services(&base_pkgs.into_iter().map(String::from).collect())
.add_services(&get_cratespecs());
//builder.add_service("usb-test"); //builder.add_service("usb-test");
builder.add_service("usb-device-xous", false); builder.add_service("usb-device-xous", false);
} }
Some("pddb-dev") => { Some("pddb-dev") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&pddb_dev_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_services(&get_cratespecs()); .add_services(&pddb_dev_pkgs.into_iter().map(String::from).collect())
}, .add_services(&get_cratespecs());
}
Some("trng-test") => { Some("trng-test") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_feature("urandomtest"); .add_services(&user_pkgs.into_iter().map(String::from).collect())
}, .add_feature("urandomtest");
}
Some("ro-test") => { Some("ro-test") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_feature("ringosctest"); .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("ringosctest");
} }
Some("av-test") => { Some("av-test") => {
builder.target_precursor(PRECURSOR_SOC_VERSION) builder
.add_services(&user_pkgs.into_iter().map(String::from).collect()) .target_precursor(PRECURSOR_SOC_VERSION)
.add_feature("avalanchetest"); .add_services(&user_pkgs.into_iter().map(String::from).collect())
.add_feature("avalanchetest");
}
Some("compile-apps") => {
builder
.target_precursor_no_image(PRECURSOR_SOC_VERSION)
.add_services(&gfx_base_pkgs.into_iter().map(String::from).collect());
} }
Some("compile-apps") => {
builder.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 ------
Some("cramium-fpga") | Some("cramium-soc") => { Some("cramium-fpga") | Some("cramium-soc") => {
let cramium_pkgs = [ let cramium_pkgs =
"xous-log", ["xous-log", "xous-names", "xous-ticktimer", "cram-console"].to_vec();
"xous-names",
"xous-ticktimer",
"cram-console",
].to_vec();
match task.as_deref() { match task.as_deref() {
Some("cramium-fpga") => builder.target_cramium_fpga(), Some("cramium-fpga") => builder.target_cramium_fpga(),
Some("cramium-soc") => builder.target_cramium_soc(), Some("cramium-soc") => builder.target_cramium_soc(),
@ -392,7 +411,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// ------ ARM hardware image configs ------ // ------ ARM hardware image configs ------
Some("arm-tiny") => { Some("arm-tiny") => {
builder.target_arm() builder
.target_arm()
.add_services(&vec![ .add_services(&vec![
"xous-log".to_string(), "xous-log".to_string(),
"xous-ticktimer".to_string(), "xous-ticktimer".to_string(),
@ -461,6 +481,10 @@ fn print_help() {
[name#URL] pre-built binary crate of 'name' downloaded from a server at 'URL' [name#URL] pre-built binary crate of 'name' downloaded from a server at 'URL'
[path-to-binary] file path to a prebuilt binary image on local machine. [path-to-binary] file path to a prebuilt binary image on local machine.
Files in '.' must be specified as './file' to avoid confusion with local source Files in '.' must be specified as './file' to avoid confusion with local source
[name:path-to-binary] file path to a prebuilt binary image on local machine which will be renamed.
This is useful if the binary image is an app since the name will be required
for registration with the gam.
Files in '.' must be specified as './file' to avoid confusion with local source
The [cratespecs] list is treated as apps or services based on the context of [verb]. Additional crates can The [cratespecs] list is treated as apps or services based on the context of [verb]. Additional crates can
be merged in with explicit app/service treatment with the following flags: be merged in with explicit app/service treatment with the following flags:
@ -543,16 +567,19 @@ fn get_flag(flag: &str) -> Result<Vec<String>, DynError> {
for arg in args { for arg in args {
if arg == flag { if arg == flag {
flag_found = true; flag_found = true;
continue continue;
} }
if flag_found { if flag_found {
if arg.starts_with('-') { if arg.starts_with('-') {
eprintln!("Malformed arguments. Expected argument after flag {}, but found {}", flag, arg); eprintln!(
"Malformed arguments. Expected argument after flag {}, but found {}",
flag, arg
);
return Err("Bad arguments".into()); return Err("Bad arguments".into());
} }
list.push(arg); list.push(arg);
flag_found = false; flag_found = false;
continue continue;
} }
} }
Ok(list) Ok(list)

View file

@ -8,15 +8,19 @@ use std::{
}; };
use crate::{cargo, project_root}; use crate::{cargo, project_root};
use crate::{TARGET_TRIPLE_RISCV32, TARGET_TRIPLE_ARM}; use crate::{TARGET_TRIPLE_ARM, TARGET_TRIPLE_RISCV32};
const TOOLCHAIN_RELEASE_URL_RISCV32: &str = "https://api.github.com/repos/betrusted-io/rust/releases"; const TOOLCHAIN_RELEASE_URL_RISCV32: &str =
"https://api.github.com/repos/betrusted-io/rust/releases";
const TOOLCHAIN_RELEASE_URL_ARM: &str = const TOOLCHAIN_RELEASE_URL_ARM: &str =
"https://api.github.com/repos/Foundation-Devices/rust/releases"; "https://api.github.com/repos/Foundation-Devices/rust/releases";
lazy_static! { lazy_static! {
static ref TOOLCHAIN_RELEASE_URLS: HashMap<String, String> = HashMap::from([ static ref TOOLCHAIN_RELEASE_URLS: HashMap<String, String> = HashMap::from([
(TARGET_TRIPLE_RISCV32.to_owned(), TOOLCHAIN_RELEASE_URL_RISCV32.to_owned()), (
TARGET_TRIPLE_RISCV32.to_owned(),
TOOLCHAIN_RELEASE_URL_RISCV32.to_owned()
),
( (
TARGET_TRIPLE_ARM.to_owned(), TARGET_TRIPLE_ARM.to_owned(),
TOOLCHAIN_RELEASE_URL_ARM.to_owned() TOOLCHAIN_RELEASE_URL_ARM.to_owned()
@ -402,9 +406,7 @@ pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynEr
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() let changed = match OpenOptions::new().read(true).open(&last_config) {
.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 { if contents != last_lang {
@ -413,7 +415,7 @@ pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynEr
false false
} }
} }
_ => true _ => true,
}; };
if changed { if changed {
println!("Locale language changed to {}", last_lang); println!("Locale language changed to {}", last_lang);
@ -421,7 +423,8 @@ pub(crate) fn track_language_changes(last_lang: &str) -> Result<(), crate::DynEr
.create(true) .create(true)
.write(true) .write(true)
.truncate(true) .truncate(true)
.open(&last_config).unwrap(); .open(&last_config)
.unwrap();
write!(file, "{}", last_lang).unwrap(); write!(file, "{}", last_lang).unwrap();
generate_locales()? generate_locales()?
} else { } else {

View file

@ -1,9 +1,9 @@
use std::env;
use crate::builder::CrateSpec; use crate::builder::CrateSpec;
use std::path::Path; use std::env;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use std::io::{BufReader, Read}; use std::io::{BufReader, Read};
use std::path::Path;
use crate::DynError; use crate::DynError;
@ -47,19 +47,23 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
let path = entry.path(); let path = entry.path();
// this should *really* exist if the build system is stable, so just unwrap all the things // this should *really* exist if the build system is stable, so just unwrap all the things
let regdir = path.file_name().unwrap().to_str().unwrap().to_string(); let regdir = path.file_name().unwrap().to_str().unwrap().to_string();
if regdir.contains("crates.io") { // crates.io sticks sources in something with git yadda yadda...docs don't really say what/why/how... if regdir.contains("crates.io") {
// crates.io sticks sources in something with git yadda yadda...docs don't really say what/why/how...
cache_leaf.push_str(&regdir); cache_leaf.push_str(&regdir);
} }
} }
if cache_leaf.len() == 0 { if cache_leaf.len() == 0 {
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
cache_path.push(cache_leaf); cache_path.push(cache_leaf);
// form the package source name // form the package source name
cache_path.push(format!("{}-{}", name, version)); cache_path.push(format!("{}-{}", name, version));
if !cache_path.exists() { if !cache_path.exists() {
println!("Package not in registry, skipping consistency check: {}", cache_path.as_os_str().to_str().unwrap()); println!(
"Package not in registry, skipping consistency check: {}",
cache_path.as_os_str().to_str().unwrap()
);
return Ok(()); return Ok(());
} }
@ -71,8 +75,12 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
}; };
let subdir = format!("./{}/{}/", subdir, name); let subdir = format!("./{}/{}/", subdir, name);
// handle special cases of xous kernel and ipc crates // handle special cases of xous kernel and ipc crates
let src_path = if name != "xous" && name != "xous-ipc" && name != "xous-kernel" let src_path = if name != "xous"
&& name != "utralib" && name != "svd2utra" { && name != "xous-ipc"
&& name != "xous-kernel"
&& name != "utralib"
&& name != "svd2utra"
{
Path::new(&subdir) Path::new(&subdir)
} else { } else {
if name == "xous" { if name == "xous" {
@ -86,26 +94,33 @@ pub fn verify(spec: CrateSpec, hard_failure: bool) -> Result<(), DynError> {
} else if name == "svd2utra" { } else if name == "svd2utra" {
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
println!("Comparing {} <-> {}", src_path.as_os_str().to_str().unwrap(), cache_path.as_os_str().to_str().unwrap()); println!(
"Comparing {} <-> {}",
src_path.as_os_str().to_str().unwrap(),
cache_path.as_os_str().to_str().unwrap()
);
match compare_dirs(src_path, &cache_path) { match compare_dirs(src_path, &cache_path) {
Ok(true) => Ok(()), Ok(true) => Ok(()),
Ok(false) => if hard_failure { Ok(false) => {
Err("Crates.io downloaded data does not match local source".into())} if hard_failure {
else { Err("Crates.io downloaded data does not match local source".into())
} else {
println!("**WARNING**: Local package does not match the published source. Third parties downloading from crates.io will be inconsistent with this build."); println!("**WARNING**: Local package does not match the published source. Third parties downloading from crates.io will be inconsistent with this build.");
Ok(()) Ok(())
}, }
}
_ => Err("Error matching local source to crates.io cache files".into()), _ => Err("Error matching local source to crates.io cache files".into()),
} }
} else { } else {
Err("Can't verify crates that aren't from crates.io".into()) Err("Can't verify crates that aren't from crates.io".into())
} }
} }
fn compare_dirs(src: &Path, other: &Path) -> Result<bool, DynError> { fn compare_dirs(src: &Path, other: &Path) -> Result<bool, DynError> {
@ -115,30 +130,34 @@ fn compare_dirs(src: &Path, other: &Path) -> Result<bool, DynError> {
let fname = entry.file_name(); let fname = entry.file_name();
if fname.as_os_str().to_str().unwrap() == "Cargo.toml" { if fname.as_os_str().to_str().unwrap() == "Cargo.toml" {
/* /*
This is awful. The Cargo.toml file is parsed and reformatted by the packaging tool to normalize its contents. This is awful. The Cargo.toml file is parsed and reformatted by the packaging tool to normalize its contents.
Thus, the Cargo.toml file of the downloaded version never matches the Cargo.toml file that's actually used. Thus, the Cargo.toml file of the downloaded version never matches the Cargo.toml file that's actually used.
Unfortunately, there doesn't seem to be an easy way to check the equivalence of two Cargo.toml files, Unfortunately, there doesn't seem to be an easy way to check the equivalence of two Cargo.toml files,
except for recursively and deeply parsing through and comparing all the possibile keys and values of except for recursively and deeply parsing through and comparing all the possibile keys and values of
the abstract key/value tree. the abstract key/value tree.
As a hack, we compare to the Cargo.toml.orig file. Which is...kind of OK, but really, this opens us As a hack, we compare to the Cargo.toml.orig file. Which is...kind of OK, but really, this opens us
up to attacks where someone just has to replace a version on a package or even just swap out an up to attacks where someone just has to replace a version on a package or even just swap out an
entire package for a malicious one by just using package name re-assignment which is a thing that entire package for a malicious one by just using package name re-assignment which is a thing that
the format supports. In other words, all this checking is kind of pointless because it's super-easy the format supports. In other words, all this checking is kind of pointless because it's super-easy
to swap out key crates for whole other crates and have it go undetected. to swap out key crates for whole other crates and have it go undetected.
*/ */
let mut other_file = other.to_path_buf(); let mut other_file = other.to_path_buf();
other_file.push("Cargo.toml.orig"); other_file.push("Cargo.toml.orig");
let mut src_file = src.to_path_buf(); let mut src_file = src.to_path_buf();
src_file.push(&fname); src_file.push(&fname);
// println!("comparing {} <-> {}", src_file.as_os_str().to_str().unwrap(), other_file.as_os_str().to_str().unwrap()); // println!("comparing {} <-> {}", src_file.as_os_str().to_str().unwrap(), other_file.as_os_str().to_str().unwrap());
match compare_files(&src_file, &other_file) { match compare_files(&src_file, &other_file) {
Ok(true) => {}, Ok(true) => {}
Ok(false) => { Ok(false) => {
println!("Cargo.toml FAIL: {} <-> {}", src_file.as_os_str().to_str().unwrap(), other_file.as_os_str().to_str().unwrap()); println!(
return Ok(false) "Cargo.toml FAIL: {} <-> {}",
}, src_file.as_os_str().to_str().unwrap(),
Err(_) => return Err("Access error comparing remote and local crates".into()) other_file.as_os_str().to_str().unwrap()
);
return Ok(false);
}
Err(_) => return Err("Access error comparing remote and local crates".into()),
} }
// Cargo.toml's do *not* match // Cargo.toml's do *not* match
/* turns out it's *really hard* to check equivalence of cargo files...you have to deep parse it into all the values. /* turns out it's *really hard* to check equivalence of cargo files...you have to deep parse it into all the values.
@ -205,18 +224,29 @@ fn compare_dirs(src: &Path, other: &Path) -> Result<bool, DynError> {
// println!("comparing {} <-> {}", src_file.as_os_str().to_str().unwrap(), other_file.as_os_str().to_str().unwrap()); // println!("comparing {} <-> {}", src_file.as_os_str().to_str().unwrap(), other_file.as_os_str().to_str().unwrap());
if (src_file.as_os_str().to_str().unwrap().contains("ticktimer") if (src_file.as_os_str().to_str().unwrap().contains("ticktimer")
&& fname.as_os_str().to_str().unwrap() == "version.rs") && fname.as_os_str().to_str().unwrap() == "version.rs")
|| src_file.as_os_str().to_str().unwrap().contains("Cargo.lock") { || src_file
.as_os_str()
.to_str()
.unwrap()
.contains("Cargo.lock")
{
// don't compare the version.rs, as it's supposed to be different due to the timestamp // don't compare the version.rs, as it's supposed to be different due to the timestamp
// don't compare Cargo.lock files that happen to be checked into packages // don't compare Cargo.lock files that happen to be checked into packages
// println!("skipping ticktimer version.rs or Cargo.lock file"); // this line is helpful to ensure our skip exception isn't too broad. // println!("skipping ticktimer version.rs or Cargo.lock file"); // this line is helpful to ensure our skip exception isn't too broad.
} else { } else {
match compare_files(&src_file, &other_file) { match compare_files(&src_file, &other_file) {
Ok(true) => {}, Ok(true) => {}
Ok(false) => { Ok(false) => {
println!("DIFF FAIL: {} <-> {}", src_file.as_os_str().to_str().unwrap(), other_file.as_os_str().to_str().unwrap()); println!(
return Ok(false) "DIFF FAIL: {} <-> {}",
}, src_file.as_os_str().to_str().unwrap(),
Err(_) => return Err("Access error comparing remote and local crates".into()) other_file.as_os_str().to_str().unwrap()
);
return Ok(false);
}
Err(_) => {
return Err("Access error comparing remote and local crates".into())
}
} }
} }
} }
@ -232,12 +262,16 @@ fn compare_dirs(src: &Path, other: &Path) -> Result<bool, DynError> {
src_dir.push(&dname); src_dir.push(&dname);
// println!("comparing {}/ <-> {}/", src_dir.as_os_str().to_str().unwrap(), &other_dir.as_os_str().to_str().unwrap()); // println!("comparing {}/ <-> {}/", src_dir.as_os_str().to_str().unwrap(), &other_dir.as_os_str().to_str().unwrap());
match compare_dirs(&src_dir, &other_dir) { match compare_dirs(&src_dir, &other_dir) {
Ok(true) => {}, Ok(true) => {}
Ok(false) => { Ok(false) => {
println!("DIR FAIL: {}/ <-> {}/", src_dir.as_os_str().to_str().unwrap(), &other_dir.as_os_str().to_str().unwrap()); println!(
return Ok(false) "DIR FAIL: {}/ <-> {}/",
}, src_dir.as_os_str().to_str().unwrap(),
Err(_) => return Err("Access error comparing remote to local crates".into()) &other_dir.as_os_str().to_str().unwrap()
);
return Ok(false);
}
Err(_) => return Err("Access error comparing remote to local crates".into()),
}; };
} }
} }
@ -279,4 +313,4 @@ fn compare_files(a: &Path, b: &Path) -> Result<bool, DynError> {
} }
Ok(true) Ok(true)
} }
} }

View file

@ -2,10 +2,10 @@
// This generates the SEMVER data that is displayed when quering `xous ver` // This generates the SEMVER data that is displayed when quering `xous ver`
// It also generates timestamps, if demanded. // It also generates timestamps, if demanded.
use std::io::{Write, Read};
use std::fs::OpenOptions;
use std::process::Command;
use chrono::Local; use chrono::Local;
use std::fs::OpenOptions;
use std::io::{Read, Write};
use std::process::Command;
pub(crate) fn generate_version(add_timestamp: bool) { pub(crate) fn generate_version(add_timestamp: bool) {
let output = if cfg!(target_os = "windows") { let output = if cfg!(target_os = "windows") {