Skip to content

Commit

Permalink
initial work to rewrite the elements logic for hotreload
Browse files Browse the repository at this point in the history
  • Loading branch information
rambip committed Dec 9, 2024
1 parent f257529 commit f878665
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/cli/src/elements_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use manganis_core::linker::LinkSection;
use manganis_core::BundledMetadata;
use object::{read::archive::ArchiveFile, File as ObjectFile, Object, ObjectSection};
use serde::{Deserialize, Serialize};

/// Fill this manifest with whatever tables might come from the object file
fn collect_elements_metadata(&mut self, obj: &ObjectFile) -> anyhow::Result<HasMap<ConstStr, ConstStr>> {
for section in obj.sections() {
let Ok(section_name) = section.name() else {
continue;
};

// Check if the link section matches the asset section for one of the platforms we support. This may not be the current platform if the user is cross compiling
let matches = LinkSection::ALL
.iter()
.any(|x| x.link_section == section_name);

if !matches {
continue;
}

let bytes = section
.uncompressed_data()
.context("Could not read uncompressed data from object file")?;

let mut buffer = const_serialize::ConstReadBuffer::new(&bytes);
while let Some((remaining_buffer, asset)) =
const_serialize::deserialize_const!(BundledMetadata, buffer)
{
self.assets
.insert(asset.absolute_source_path().into(), asset);
buffer = remaining_buffer;
}
}

Ok(())
}
3 changes: 3 additions & 0 deletions packages/html/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repository = "https://github.com/DioxusLabs/dioxus/"
homepage = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react"]

[lib]
crate-type = ["dylib"]

[dependencies]
dioxus-core = { workspace = true }
dioxus-core-macro = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions packages/manganis/manganis-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ pub use js::*;
mod asset;
pub use asset::*;

mod metadata;
pub use metadata::*;

pub mod linker;
32 changes: 32 additions & 0 deletions packages/manganis/manganis-core/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use const_serialize::{ConstStr, SerializeConst};
use std::path::PathBuf;

#[derive(
Debug,
PartialEq,
PartialOrd,
Clone,
Copy,
Hash,
SerializeConst,
serde::Serialize,
serde::Deserialize,
)]
pub struct Metadata {
key: ConstStr,
value: ConstStr,
keep_link_section: fn() -> u8,
}

impl Metadata {
#[doc(hidden)]
/// This should only be called from the macro
/// Create a new metadata
pub const fn new(key: &'static str, value: &'static str, keep_link_section: fn() -> u8) -> Self {
Self {
key: ConstStr::new(key),
value: ConstStr::new(value),
keep_link_section,
}
}
}
6 changes: 6 additions & 0 deletions packages/manganis/manganis/src/macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ pub const fn serialize_asset(asset: &BundledAsset) -> ConstVec<u8> {
serialize_const(asset, write)
}

/// Serialize metadata to a const buffer
pub const fn selialize_metadata(metadata: &BundledMetadata) -> ConstVec<u8> {
let write = ConstVec::new();
serialize_const(metadata, write)
}

/// Copy a slice into a constant sized buffer at compile time
pub const fn copy_bytes<const N: usize>(bytes: &[u8]) -> [u8; N] {
let mut out = [0; N];
Expand Down

0 comments on commit f878665

Please sign in to comment.