Make objdiff-core no_std + huge WASM rework

This commit is contained in:
2025-02-07 00:10:49 -07:00
parent d938988d43
commit e8de35b78e
49 changed files with 1463 additions and 1046 deletions

View File

@@ -1,8 +1,7 @@
use std::path::{Component, Path};
use anyhow::Result;
use globset::Glob;
use objdiff_core::config::{try_project_config, ProjectObject, DEFAULT_WATCH_PATTERNS};
use objdiff_core::config::{try_project_config, DEFAULT_WATCH_PATTERNS};
use typed_path::{Utf8UnixComponent, Utf8UnixPath};
use crate::app::{AppState, ObjectConfig};
@@ -47,32 +46,19 @@ fn find_dir<'a>(
unreachable!();
}
fn build_nodes(
units: &mut [ProjectObject],
project_dir: &Path,
target_obj_dir: Option<&Path>,
base_obj_dir: Option<&Path>,
) -> Vec<ProjectObjectNode> {
fn build_nodes(units: &mut [ObjectConfig]) -> Vec<ProjectObjectNode> {
let mut nodes = vec![];
for (idx, unit) in units.iter_mut().enumerate() {
unit.resolve_paths(project_dir, target_obj_dir, base_obj_dir);
let mut out_nodes = &mut nodes;
let path = if let Some(name) = &unit.name {
Path::new(name)
} else if let Some(path) = &unit.path {
path
} else {
continue;
};
let path = Utf8UnixPath::new(&unit.name);
if let Some(parent) = path.parent() {
for component in parent.components() {
if let Component::Normal(name) = component {
let name = name.to_str().unwrap();
if let Utf8UnixComponent::Normal(name) = component {
out_nodes = find_dir(name, out_nodes);
}
}
}
let filename = path.file_name().unwrap().to_str().unwrap().to_string();
let filename = path.file_name().unwrap().to_string();
out_nodes.push(ProjectObjectNode::Unit(filename, idx));
}
// Within the top-level module directories, join paths. Leave the
@@ -90,13 +76,18 @@ pub fn load_project_config(state: &mut AppState) -> Result<()> {
let Some(project_dir) = &state.config.project_dir else {
return Ok(());
};
if let Some((result, info)) = try_project_config(project_dir) {
if let Some((result, info)) = try_project_config(project_dir.as_ref()) {
let project_config = result?;
state.config.custom_make = project_config.custom_make.clone();
state.config.custom_args = project_config.custom_args.clone();
state.config.target_obj_dir =
project_config.target_dir.as_deref().map(|p| project_dir.join(p));
state.config.base_obj_dir = project_config.base_dir.as_deref().map(|p| project_dir.join(p));
state.config.target_obj_dir = project_config
.target_dir
.as_deref()
.map(|p| project_dir.join(p.with_platform_encoding()));
state.config.base_obj_dir = project_config
.base_dir
.as_deref()
.map(|p| project_dir.join(p.with_platform_encoding()));
state.config.build_base = project_config.build_base.unwrap_or(true);
state.config.build_target = project_config.build_target.unwrap_or(false);
if let Some(watch_patterns) = &project_config.watch_patterns {
@@ -109,21 +100,28 @@ pub fn load_project_config(state: &mut AppState) -> Result<()> {
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect();
}
state.watcher_change = true;
state.objects = project_config.units.clone().unwrap_or_default();
state.object_nodes = build_nodes(
&mut state.objects,
project_dir,
state.config.target_obj_dir.as_deref(),
state.config.base_obj_dir.as_deref(),
);
state.objects = project_config
.units
.as_deref()
.unwrap_or_default()
.iter()
.map(|o| {
ObjectConfig::new(
o,
project_dir,
state.config.target_obj_dir.as_deref(),
state.config.base_obj_dir.as_deref(),
)
})
.collect::<Vec<_>>();
state.object_nodes = build_nodes(&mut state.objects);
state.current_project_config = Some(project_config);
state.project_config_info = Some(info);
// Reload selected object
if let Some(selected_obj) = &state.config.selected_obj {
if let Some(obj) = state.objects.iter().find(|o| o.name() == selected_obj.name) {
let config = ObjectConfig::from(obj);
state.set_selected_obj(config);
if let Some(obj) = state.objects.iter().find(|o| o.name == selected_obj.name) {
state.set_selected_obj(obj.clone());
} else {
state.clear_selected_obj();
}