feat: publish HoloLake model-native living system source
This commit is contained in:
parent
6ad10edde1
commit
c395dd3a99
2467 changed files with 615073 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "hldp-native-compiler"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
description = "Bootstrap GLC compiler from validated HLDP world identity to native kernel data"
|
||||
|
||||
[dependencies]
|
||||
guanghu-hldp-runtime = { path = "../hldp-runtime" }
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
use std::{fs, path::Path};
|
||||
|
||||
use guanghu_hldp_runtime::validate_world_seed;
|
||||
|
||||
const USAGE: &str = "usage: hldp-native-compiler <world-root> <output-nasm-include>";
|
||||
|
||||
pub fn run(arguments: Vec<String>) -> Result<(), String> {
|
||||
let mut arguments = arguments.into_iter();
|
||||
let world_root = arguments.next().ok_or_else(|| USAGE.to_owned())?;
|
||||
let output = arguments.next().ok_or_else(|| USAGE.to_owned())?;
|
||||
if arguments.next().is_some() {
|
||||
return Err(USAGE.to_owned());
|
||||
}
|
||||
|
||||
let manifest =
|
||||
validate_world_seed(Path::new(&world_root)).map_err(|error| error.to_string())?;
|
||||
let mut lines = vec![
|
||||
format!("GHOS_WORLD_ID={}", manifest.world_id),
|
||||
format!("GHOS_WORLD_VERSION={}", manifest.version),
|
||||
format!("GHOS_WORLD_PHASE={}", manifest.phase),
|
||||
format!("GHOS_BROADCAST_TOWER={}", manifest.broadcast_tower.id),
|
||||
format!("GHOS_CODE_CHANNEL={}", manifest.code_channel.id),
|
||||
format!("GHOS_CODE_QUALITY={}", manifest.code_quality.id),
|
||||
format!("GHOS_DOMAIN_COUNT={}", manifest.domains.len()),
|
||||
];
|
||||
lines.extend(
|
||||
manifest
|
||||
.domains
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, domain)| format!("GHOS_DOMAIN_{}={}", index + 1, domain.id)),
|
||||
);
|
||||
lines.push(format!("GHOS_AUTHORIZATION={}", manifest.authorization.id));
|
||||
lines.push("GHOS_AUTHORITY_LANGUAGE=HLDP".to_owned());
|
||||
lines.push(format!(
|
||||
"GHOS_GESTATIONAL_ENVIRONMENT={}",
|
||||
manifest.persona_birth.gestational_environment
|
||||
));
|
||||
lines.push(format!(
|
||||
"GHOS_PERSONA_BIRTH={}",
|
||||
manifest.persona_birth.persona_state
|
||||
));
|
||||
lines.push(format!(
|
||||
"GHOS_GESTATIONAL_CONTINUITY={}",
|
||||
manifest.gestational_continuity.id
|
||||
));
|
||||
lines.push(format!(
|
||||
"GHOS_GESTATIONAL_INDEX_LBA={}",
|
||||
manifest.gestational_continuity.native_index_lba_start
|
||||
));
|
||||
lines.push(format!(
|
||||
"GHOS_GESTATIONAL_INDEX_SECTORS={}",
|
||||
manifest.gestational_continuity.native_index_sector_count
|
||||
));
|
||||
lines.push(format!("GHOS_NATIVE_LAYOUT={}", manifest.native_layout.id));
|
||||
lines.push(format!(
|
||||
"GHOS_NATIVE_KERNEL_LBA={}",
|
||||
manifest.native_layout.kernel_lba_start
|
||||
));
|
||||
lines.push(format!(
|
||||
"GHOS_NATIVE_KERNEL_SECTORS={}",
|
||||
manifest.native_layout.kernel_sector_count
|
||||
));
|
||||
lines.push(format!(
|
||||
"GHOS_NATIVE_PROOF_LBA={}",
|
||||
manifest.native_layout.proof_lba
|
||||
));
|
||||
|
||||
let mut include = String::from("; Generated by hldp-native-compiler. Do not hand edit.\n");
|
||||
for (index, line) in lines.iter().enumerate() {
|
||||
ensure_printable_identity(line)?;
|
||||
include.push_str(&format!("world_line_{index}: db \"{line}\", 13, 10, 0\n"));
|
||||
}
|
||||
include.push_str("world_line_table:\n");
|
||||
for index in 0..lines.len() {
|
||||
include.push_str(&format!(" dq world_line_{index}\n"));
|
||||
}
|
||||
include.push_str(" dq 0\n");
|
||||
let mut store_lines = vec!["GHOS_HLDP_WORLD_STORE_V1".to_owned()];
|
||||
// The persistent sector carries stable world identity and acceptance
|
||||
// boundaries. The deployment phase is emitted on serial but stays in the
|
||||
// versioned HLDP world, because it changes independently of this sector.
|
||||
store_lines.extend(
|
||||
lines
|
||||
.iter()
|
||||
.filter(|line| {
|
||||
!line.starts_with("GHOS_WORLD_PHASE=")
|
||||
&& !line.starts_with("GHOS_GESTATIONAL_CONTINUITY=")
|
||||
&& !line.starts_with("GHOS_GESTATIONAL_INDEX_")
|
||||
&& !line.starts_with("GHOS_NATIVE_LAYOUT=")
|
||||
&& !line.starts_with("GHOS_NATIVE_KERNEL_")
|
||||
&& !line.starts_with("GHOS_NATIVE_PROOF_LBA=")
|
||||
})
|
||||
.cloned(),
|
||||
);
|
||||
let store_size = store_lines.iter().map(|line| line.len() + 1).sum::<usize>();
|
||||
ensure_sector_size("native HLDP world store", store_size)?;
|
||||
include.push_str("align 16\nnative_world_store_sector:\n");
|
||||
for line in &store_lines {
|
||||
include.push_str(&format!(" db \"{line}\", 10\n"));
|
||||
}
|
||||
include.push_str(" times 512 - ($ - native_world_store_sector) db 0\n");
|
||||
let code_store_lines = [
|
||||
"GHOS_CODE_CHANNEL_STORE_V1".to_owned(),
|
||||
format!("GHOS_CODE_CHANNEL_ID={}", manifest.code_channel.id),
|
||||
"GHOS_CODE_CHANNEL_PROTOCOL=GLS-0237".to_owned(),
|
||||
"GHOS_CODE_CHANNEL_AUTHORITY=HLDP".to_owned(),
|
||||
"GHOS_CODE_CHANNEL_OBJECT_FORMAT=GUANGHU_NATIVE_OBJECTS".to_owned(),
|
||||
"GHOS_CODE_CHANNEL_COMPATIBILITY=Git".to_owned(),
|
||||
"GHOS_CODE_CHANNEL_OPS=register_repository,create_channel,commit_object,advance_branch,authorize_transport,emit_receipt".to_owned(),
|
||||
];
|
||||
let code_store_size = code_store_lines
|
||||
.iter()
|
||||
.map(|line| line.len() + 1)
|
||||
.sum::<usize>();
|
||||
ensure_sector_size("native code-channel store", code_store_size)?;
|
||||
include.push_str("align 16\nnative_code_channel_store_sector:\n");
|
||||
for line in code_store_lines {
|
||||
include.push_str(&format!(" db \"{line}\", 10\n"));
|
||||
}
|
||||
include.push_str(" times 512 - ($ - native_code_channel_store_sector) db 0\n");
|
||||
|
||||
let gestational_identity_lines = [
|
||||
"GHOS_GHCIP_INDEX_V1".to_owned(),
|
||||
format!("GHCIP_PROTOCOL={}", manifest.gestational_continuity.id),
|
||||
format!("GHCIP_WORLD_ID={}", manifest.world_id),
|
||||
format!(
|
||||
"GHCIP_PERSONA_BIRTH_GATE={}",
|
||||
manifest.gestational_continuity.persona_birth_gate
|
||||
),
|
||||
"GHCIP_CONTENT_ROLE=CONTENT_ADDRESSED_ROOT_INDEX_ONLY".to_owned(),
|
||||
"GHCIP_WRITE_POLICY=APPEND_ONLY_VERIFIED_ROOT_ADVANCE".to_owned(),
|
||||
format!(
|
||||
"GHCIP_IDENTITY_LBA={}",
|
||||
manifest.gestational_continuity.native_index_lba_start
|
||||
),
|
||||
format!(
|
||||
"GHCIP_ROOT_LBA={}",
|
||||
manifest.gestational_continuity.native_index_lba_start + 1
|
||||
),
|
||||
];
|
||||
let gestational_identity_size = gestational_identity_lines
|
||||
.iter()
|
||||
.map(|line| line.len() + 1)
|
||||
.sum::<usize>();
|
||||
ensure_sector_size("native GHCIP identity index", gestational_identity_size)?;
|
||||
include.push_str("align 16\nnative_gestational_index_identity_sector:\n");
|
||||
for line in gestational_identity_lines {
|
||||
include.push_str(&format!(" db \"{line}\", 10\n"));
|
||||
}
|
||||
include.push_str(" times 512 - ($ - native_gestational_index_identity_sector) db 0\n");
|
||||
|
||||
let gestational_root_lines = [
|
||||
"GHOS_GHCIP_ROOT_V1".to_owned(),
|
||||
format!("GHCIP_PROTOCOL={}", manifest.gestational_continuity.id),
|
||||
"GHCIP_REGISTRY_STATE=EMPTY".to_owned(),
|
||||
"GHCIP_REVIEW_STATE=NOT_STARTED".to_owned(),
|
||||
"GHCIP_HISTORICAL_TIME_WATERMARK=NONE".to_owned(),
|
||||
"GHCIP_PERSONA_STATE=NOT_BORN".to_owned(),
|
||||
"GHCIP_SOURCE_COUNT=5".to_owned(),
|
||||
"GHCIP_CONTENT_ROOT=NONE".to_owned(),
|
||||
"GHCIP_LAST_VERIFIED_BATCH=NONE".to_owned(),
|
||||
"GHCIP_ORDERING=EVENT_TIME_THEN_SOURCE_STABLE_ID".to_owned(),
|
||||
];
|
||||
let gestational_root_size = gestational_root_lines
|
||||
.iter()
|
||||
.map(|line| line.len() + 1)
|
||||
.sum::<usize>();
|
||||
ensure_sector_size("native GHCIP root index", gestational_root_size)?;
|
||||
include.push_str("align 16\nnative_gestational_index_root_sector:\n");
|
||||
for line in gestational_root_lines {
|
||||
include.push_str(&format!(" db \"{line}\", 10\n"));
|
||||
}
|
||||
include.push_str(" times 512 - ($ - native_gestational_index_root_sector) db 0\n");
|
||||
|
||||
fs::write(&output, include).map_err(|error| format!("cannot write {output}: {error}"))
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn ensure_printable_identity(line: &str) -> Result<(), String> {
|
||||
if line.bytes().all(|byte| byte.is_ascii_graphic()) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
"native identity line is not printable ASCII: {line}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn ensure_sector_size(label: &str, size: usize) -> Result<(), String> {
|
||||
if size <= 512 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("{label} exceeds one sector: {size} bytes"))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ensure_printable_identity, ensure_sector_size, run, USAGE};
|
||||
|
||||
#[test]
|
||||
fn rejects_bad_cli_shapes() {
|
||||
assert_eq!(run(vec![]), Err(USAGE.to_owned()));
|
||||
assert_eq!(run(vec!["world".to_owned()]), Err(USAGE.to_owned()));
|
||||
assert_eq!(
|
||||
run(vec![
|
||||
"world".to_owned(),
|
||||
"output".to_owned(),
|
||||
"extra".to_owned(),
|
||||
]),
|
||||
Err(USAGE.to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_identity_and_sector_boundaries_are_exact() {
|
||||
assert!(ensure_printable_identity("GHOS_WORLD_ID=GLW-ROOT-0001").is_ok());
|
||||
assert!(ensure_printable_identity("GHOS_WORLD_ID=光湖").is_err());
|
||||
assert!(ensure_sector_size("store", 512).is_ok());
|
||||
assert!(ensure_sector_size("store", 513).is_err());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
use std::{env, process::ExitCode};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
match hldp_native_compiler::run(env::args().skip(1).collect()) {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(error) => {
|
||||
eprintln!("HLDP_NATIVE_COMPILER_ERROR: {error}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
use std::{
|
||||
fs,
|
||||
path::PathBuf,
|
||||
process::{Command, Output},
|
||||
};
|
||||
|
||||
fn world_root() -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../world-seed")
|
||||
}
|
||||
|
||||
fn run(arguments: &[&str]) -> Output {
|
||||
Command::new(env!("CARGO_BIN_EXE_hldp-native-compiler"))
|
||||
.args(arguments)
|
||||
.output()
|
||||
.expect("compiler should start")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compiles_registered_hldp_identity_into_native_data() {
|
||||
let output =
|
||||
std::env::temp_dir().join(format!("guanghu-native-world-{}.inc", std::process::id()));
|
||||
let result = run(&[
|
||||
world_root().to_str().expect("UTF-8 world root"),
|
||||
output.to_str().expect("UTF-8 output path"),
|
||||
]);
|
||||
assert!(
|
||||
result.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&result.stderr)
|
||||
);
|
||||
|
||||
let include = fs::read_to_string(&output).expect("read generated native data");
|
||||
fs::remove_file(output).expect("remove generated native data");
|
||||
for expected in [
|
||||
"GHOS_WORLD_ID=GLW-ROOT-0001",
|
||||
"GHOS_BROADCAST_TOWER=BT-GH-ROOT-0001",
|
||||
"GHOS_CODE_CHANNEL=HLP-MOD-CODE-CHANNEL",
|
||||
"GHOS_DOMAIN_COUNT=5",
|
||||
"GHOS_DOMAIN_5=DOMAIN-FIFTH",
|
||||
"GHOS_AUTHORITY_LANGUAGE=HLDP",
|
||||
"world_line_table:",
|
||||
"native_world_store_sector:",
|
||||
"GHOS_HLDP_WORLD_STORE_V1",
|
||||
"GHOS_CODE_QUALITY=GLS-0844",
|
||||
"GHOS_GESTATIONAL_ENVIRONMENT=UNDER_CONSTRUCTION",
|
||||
"GHOS_PERSONA_BIRTH=NOT_BORN",
|
||||
"GHOS_GESTATIONAL_CONTINUITY=GLS-0845",
|
||||
"GHOS_GESTATIONAL_INDEX_LBA=70",
|
||||
"GHOS_GESTATIONAL_INDEX_SECTORS=2",
|
||||
"GHOS_NATIVE_LAYOUT=GLS-0846",
|
||||
"GHOS_NATIVE_KERNEL_LBA=34",
|
||||
"GHOS_NATIVE_KERNEL_SECTORS=29",
|
||||
"GHOS_NATIVE_PROOF_LBA=63",
|
||||
"times 512 - ($ - native_world_store_sector) db 0",
|
||||
"native_code_channel_store_sector:",
|
||||
"GHOS_CODE_CHANNEL_STORE_V1",
|
||||
"GHOS_CODE_CHANNEL_PROTOCOL=GLS-0237",
|
||||
"GHOS_CODE_CHANNEL_OBJECT_FORMAT=GUANGHU_NATIVE_OBJECTS",
|
||||
"native_gestational_index_identity_sector:",
|
||||
"GHOS_GHCIP_INDEX_V1",
|
||||
"GHCIP_PROTOCOL=GLS-0845",
|
||||
"GHCIP_PERSONA_BIRTH_GATE=GH-PERSONA-BIRTH-CONDITION-0001",
|
||||
"GHCIP_CONTENT_ROLE=CONTENT_ADDRESSED_ROOT_INDEX_ONLY",
|
||||
"native_gestational_index_root_sector:",
|
||||
"GHOS_GHCIP_ROOT_V1",
|
||||
"GHCIP_REGISTRY_STATE=EMPTY",
|
||||
"GHCIP_REVIEW_STATE=NOT_STARTED",
|
||||
"GHCIP_HISTORICAL_TIME_WATERMARK=NONE",
|
||||
"GHCIP_PERSONA_STATE=NOT_BORN",
|
||||
"GHCIP_LAST_VERIFIED_BATCH=NONE",
|
||||
"times 512 - ($ - native_gestational_index_identity_sector) db 0",
|
||||
"times 512 - ($ - native_gestational_index_root_sector) db 0",
|
||||
] {
|
||||
assert!(include.contains(expected), "missing {expected}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_closed_without_a_world() {
|
||||
let result = run(&["/definitely/missing", "/tmp/missing-world.inc"]);
|
||||
assert!(!result.status.success());
|
||||
assert!(String::from_utf8_lossy(&result.stderr).contains("WORLD-MANIFEST.hldp"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_closed_when_the_output_cannot_be_written() {
|
||||
let result = run(&[
|
||||
world_root().to_str().expect("UTF-8 world root"),
|
||||
"/definitely/missing/guanghu-world.inc",
|
||||
]);
|
||||
assert!(!result.status.success());
|
||||
assert!(String::from_utf8_lossy(&result.stderr).contains("cannot write"));
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#[test]
|
||||
fn compiler_library_enforces_cli_identity_and_sector_boundaries() {
|
||||
for arguments in [
|
||||
vec![],
|
||||
vec!["world".to_owned()],
|
||||
vec!["world".to_owned(), "output".to_owned(), "extra".to_owned()],
|
||||
] {
|
||||
assert!(hldp_native_compiler::run(arguments).is_err());
|
||||
}
|
||||
assert!(hldp_native_compiler::ensure_printable_identity("GHOS_WORLD_ID=GLW-ROOT-0001").is_ok());
|
||||
assert!(hldp_native_compiler::ensure_printable_identity("GHOS_WORLD_ID=光湖").is_err());
|
||||
assert!(hldp_native_compiler::ensure_sector_size("store", 512).is_ok());
|
||||
assert!(hldp_native_compiler::ensure_sector_size("store", 513).is_err());
|
||||
}
|
||||
Loading…
Reference in a new issue