-
-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial work to rewrite the elements logic for hotreload
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,7 @@ pub use js::*; | |
mod asset; | ||
pub use asset::*; | ||
|
||
mod metadata; | ||
pub use metadata::*; | ||
|
||
pub mod linker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters