Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/experimental/sddf/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ license = "BSD-2-Clause"
links = "sddf"

[build-dependencies]
bindgen = "0.72.1"
bindgen = { version = "0.72.1", features = ["runtime"], default-features = false }
cc = "1.2.43"
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.103"
quote = "1.0.41"
syn = { version = "2.0.108", features = ["full"] }
syn = { version = "2.0.108", features = ["full"], default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.103"
quote = "1.0.41"
syn = { version = "2.0.108", features = ["full"] }
syn = { version = "2.0.108", features = ["full"], default-features = false }
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ optional = true
[dependencies.rkyv]
version = "0.8.12"
default-features = false
features = ["alloc", "bytecheck", "pointer_width_32"]
features = ["alloc", "pointer_width_32"]

[dependencies.serde]
version = "1.0.228"
Expand Down
4 changes: 2 additions & 2 deletions crates/sel4-capdl-initializer/types/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ proc-macro = true

[dependencies]
proc-macro2 = "1.0.103"
quote = "1.0.41"
syn = "2.0.108"
quote = { version = "1.0.41", default-features = false }
syn = { version = "2.0.108", default-features = false }
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl SpecForInitializer {
}

pub fn access(buf: &[u8]) -> Result<&<Self as Archive>::Archived, rancor::Error> {
rkyv::access(buf)
Ok(unsafe { rkyv::access_unchecked(buf) })
}

#[allow(clippy::missing_safety_doc)]
Expand Down
1 change: 0 additions & 1 deletion crates/sel4-kernel-loader/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ mk {
quote
object
serde
prettyplease
cc
glob
;
Expand Down
3 changes: 1 addition & 2 deletions crates/sel4-kernel-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ cc = "1.2.43"
glob = "0.3.3"
object = "0.38.1"
postcard = { version = "1.1.3", default-features = false, features = ["alloc"] }
prettyplease = "0.2.37"
proc-macro2 = "1.0.103"
quote = "1.0.41"
sel4-build-env = { path = "../sel4/build-env" }
sel4-config = { path = "../sel4/config" }
sel4-kernel-loader-payload-types = { path = "payload-types" }
sel4-platform-info = { path = "../sel4-platform-info" }
serde = "1.0.228"
syn = { version = "2.0.108", features = ["parsing"] }
syn = { version = "2.0.108", features = ["parsing"], default-features = false }

[target."cfg(any(target_arch = \"arm\", target_arch = \"aarch64\"))".dependencies]
sel4-bcm2835-aux-uart-driver = { path = "../drivers/bcm2835-aux-uart" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-root-task/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.103"
quote = "1.0.41"
syn = { version = "2.0.108", features = ["full"] }
syn = { version = "2.0.108", features = ["full"], default-features = false }
43 changes: 40 additions & 3 deletions crates/sel4/build-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ pub const SEL4_PREFIX_ENV: &str = "SEL4_PREFIX";
pub const SEL4_INCLUDE_DIRS_ENV: &str = "SEL4_INCLUDE_DIRS";

fn get_asserting_valid_unicode(var: &str) -> Option<String> {
get_asserting_valid_unicode_runtime(var)
.inspect(|_| {
println!("cargo::rerun-if-env-changed={var}");
})
}

fn get_asserting_valid_unicode_runtime(var: &str) -> Option<String> {
env::var(var)
.map_err(|err| {
if let VarError::NotUnicode(val) = err {
panic!("the value of environment variable {var:?} is not valid unicode: {val:?}");
}
})
.ok()
.inspect(|_| {
println!("cargo::rerun-if-env-changed={var}");
})
}


pub fn get_with_sel4_prefix_relative_fallback(
var: &str,
relative_path_from_fallback: impl AsRef<Path>,
Expand All @@ -48,6 +53,10 @@ pub fn get_sel4_prefix() -> Option<PathBuf> {
get_asserting_valid_unicode(SEL4_PREFIX_ENV).map(PathBuf::from)
}

pub fn get_sel4_prefix_runtime() -> Option<PathBuf> {
get_asserting_valid_unicode_runtime(SEL4_PREFIX_ENV).map(PathBuf::from)
}

pub fn get_libsel4_include_dirs() -> impl Iterator<Item = PathBuf> {
get_asserting_valid_unicode(SEL4_INCLUDE_DIRS_ENV)
.map(|val| val.split(':').map(PathBuf::from).collect())
Expand All @@ -59,6 +68,14 @@ pub fn get_libsel4_include_dirs() -> impl Iterator<Item = PathBuf> {
})
}

pub fn get_libsel4_include_dirs_runtime() -> impl Iterator<Item = PathBuf> {
get_asserting_valid_unicode_runtime(SEL4_INCLUDE_DIRS_ENV)
.map(|val| val.split(':').map(PathBuf::from).collect())
.or_else(|| get_sel4_prefix_runtime().map(|sel4_prefix| vec![sel4_prefix.join("libsel4/include")]))
.unwrap_or_else(|| panic!("{SEL4_INCLUDE_DIRS_ENV} or {SEL4_PREFIX_ENV} must be set"))
.into_iter()
}

pub fn try_find_in_libsel4_include_dirs(relative_path: impl AsRef<Path>) -> Option<PathBuf> {
for d in get_libsel4_include_dirs() {
let path = Path::new(&d).join(relative_path.as_ref());
Expand All @@ -78,3 +95,23 @@ pub fn find_in_libsel4_include_dirs(relative_path: impl AsRef<Path>) -> PathBuf
)
})
}

pub fn try_find_in_libsel4_include_dirs_runtime(relative_path: impl AsRef<Path>) -> Option<PathBuf> {
for d in get_libsel4_include_dirs_runtime() {
let path = Path::new(&d).join(relative_path.as_ref());
if path.exists() {
return Some(path);
}
}
None
}

pub fn find_in_libsel4_include_dirs_runtime(relative_path: impl AsRef<Path>) -> PathBuf {
let relative_path = relative_path.as_ref();
try_find_in_libsel4_include_dirs_runtime(relative_path).unwrap_or_else(|| {
panic!(
"{} not found in libsel4 include path",
relative_path.display()
)
})
}
1 change: 0 additions & 1 deletion crates/sel4/config/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mk {
};
build-dependencies = {
inherit (versions)
prettyplease
proc-macro2
quote
;
Expand Down
3 changes: 1 addition & 2 deletions crates/sel4/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ license = "BSD-2-Clause"
sel4-config-macros = { path = "macros" }

[build-dependencies]
prettyplease = "0.2.37"
proc-macro2 = "1.0.103"
quote = "1.0.41"
sel4-config-data = { path = "data" }
sel4-config-types = { path = "types" }
syn = { version = "2.0.108", features = ["parsing"] }
syn = { version = "2.0.108", features = ["parsing"], default-features = false }
3 changes: 2 additions & 1 deletion crates/sel4/config/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use sel4_config_types::{Configuration, Value};

fn main() {
let toks = generate_consts(get_kernel_config());
let formatted = prettyplease::unparse(&syn::parse2(toks).unwrap());
let syntax_tree: syn::File = syn::parse2(toks).unwrap();
let formatted = quote!(#syntax_tree).to_string();
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(&out_dir).join("consts_gen.rs");
fs::write(out_path, formatted).unwrap();
Expand Down
12 changes: 8 additions & 4 deletions crates/sel4/config/data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ authors = ["Nick Spinale <nick.spinale@coliasgroup.com>"]
edition = "2024"
license = "BSD-2-Clause"

[features]
embedded-config = []

[dependencies]
sel4-config-types = { path = "../types", features = ["serde"] }
serde_json = "1.0.145"
sel4-build-env = { path = "../../build-env" }
sel4-config-types = { path = "../types", features = [] }
tinyjson = { version = "2.5.1", default-features = false }

[build-dependencies]
sel4-build-env = { path = "../../build-env" }
sel4-config-types = { path = "../types", features = ["serde"] }
serde_json = "1.0.145"
sel4-config-types = { path = "../types", features = [] }
tinyjson = { version = "2.5.1", default-features = false }
31 changes: 28 additions & 3 deletions crates/sel4/config/data/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
//

use std::env;
use std::io::Write;
use std::fs::File;
use std::path::{Path, PathBuf};

use sel4_build_env::find_in_libsel4_include_dirs;
use sel4_config_types::Configuration;
use sel4_config_types::{Configuration, Value};
use tinyjson::JsonValue;

#[cfg(feature = "embedded-config")]
fn main() {
let config = {
let kernel_config = from_path(find_in_libsel4_include_dirs("kernel/gen_config.json"));
Expand All @@ -23,9 +26,31 @@ fn main() {

let out_dir = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(&out_dir).join("kernel_config.json");
serde_json::to_writer_pretty(File::create(out_path).unwrap(), &config).unwrap()
let mut out_file = File::create(out_path).unwrap();
let out_json = JsonValue::Object(config.iter().map(|(k, v)| {
(k.clone(), match v {
Value::String(v) => JsonValue::String(v.to_string()),
Value::Bool(v) => JsonValue::Boolean(*v),
})
}).collect());
let out_json_str: String = out_json.format().unwrap();
write!(out_file, "{}", out_json_str).unwrap();
}

#[cfg(not(feature = "embedded-config"))]
fn main() {}

fn from_path(path: impl AsRef<Path>) -> Configuration {
serde_json::from_reader(File::open(path).unwrap()).unwrap()
let json = std::fs::read_to_string(path).unwrap();
let json: JsonValue = json.parse().unwrap();
let JsonValue::Object(ref map) = json else {
panic!("invalid json: {json:#?}");
};
Configuration::new(map.into_iter().map(|(k, v)| {
(k.clone(), match v {
JsonValue::String(v) => Value::String(v.to_string()),
JsonValue::Boolean(v) => Value::Bool(*v),
_ => panic!("unsupported jsonvalue: key '{k}', value '{v:#?}'"),
})
}).collect())
}
49 changes: 47 additions & 2 deletions crates/sel4/config/data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,59 @@
#![allow(unused_imports)]

use std::sync::LazyLock;
use std::path::Path;

pub use sel4_config_types::Configuration;
use sel4_build_env::find_in_libsel4_include_dirs_runtime;
pub use sel4_config_types::{Configuration, Value};
use tinyjson::JsonValue;

pub fn get_kernel_config() -> &'static Configuration {
&KERNEL_CONFIG
}

pub fn config_as_bool(string: &str) -> bool {
get_kernel_config().get(string).map(|v| v.as_bool().expect("expected bool")).expect("missing config key")
}

pub fn config_as_string(string: &str) -> &str {
get_kernel_config().get(string).map(|v| v.as_str()).expect("expected string").expect("missing config key")
}

#[cfg(feature = "embedded-config")]
static KERNEL_CONFIG: LazyLock<Configuration> =
LazyLock::new(|| from_string(KERNEL_CONFIG_JSON));

#[cfg(not(feature = "embedded-config"))]
static KERNEL_CONFIG: LazyLock<Configuration> =
LazyLock::new(|| serde_json::from_str(KERNEL_CONFIG_JSON).unwrap());
LazyLock::new(|| {
let kernel_config = from_path(find_in_libsel4_include_dirs_runtime("kernel/gen_config.json"));
let libsel4_config = from_path(find_in_libsel4_include_dirs_runtime("sel4/gen_config.json"));
let mut this = Configuration::empty();
this.append(kernel_config);
this.append(libsel4_config);
this
});

#[cfg(feature = "embedded-config")]
const KERNEL_CONFIG_JSON: &str = include_str!(concat!(env!("OUT_DIR"), "/kernel_config.json"));

fn from_path(path: impl AsRef<Path>) -> Configuration {
let json = std::fs::read_to_string(path).unwrap();
from_string(&json)
}


fn from_string(string: &str) -> Configuration {
let json: JsonValue = string.parse().unwrap();
let JsonValue::Object(ref map) = json else {
panic!("invalid json: {json:#?}");
};
Configuration::new(map.into_iter().map(|(k, v)| {
(k.clone(), match v {
JsonValue::String(v) => Value::String(v.to_string()),
JsonValue::Boolean(v) => Value::Bool(*v),
_ => panic!("unsupported jsonvalue: key '{k}', value '{v:#?}'"),
})
}).collect())
}

2 changes: 1 addition & 1 deletion crates/sel4/sys/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mk {
};
build-dependencies = {
inherit (versions)
proc-macro2 quote prettyplease
proc-macro2 quote
bindgen xmltree glob
regex pest pest_derive
;
Expand Down
Loading
Loading