* implement const cbor encoding + decoding for basic types * implement map encoding and decoding * fix map test * all tests passing * dynamically sized arrays * smaller str encoding * swap array and list and add more documentation * move serialization and deserialization for each struct together * support both legacy and new assets * bump const serialize version * fix asset conversion code * pull out manganis symbol struct from tuble * test reading old asset versions * more list/array cleanup and bump rust version * fix clippy * switch cli opt port * install playwright deps * split cli-optimization package to avoid two dioxus' in the same crate * fix clippy * force the toast.png asset to be included in the linker stage #[used] has platform depedant behavior * bundle both formats in the link section and only use the asset the cli changed * remove sudo which doesn't exist on windows * add binstall to the playwright workflow * separate bin target for the old cli * lockfile * cargo update to get versions shaken out * notes on binstalls, add back `.read()` for compat * use 0.8.0-alpha.0 for const-serialize instead of 0.8 this ensures we can still publish breaking changes on 0.8 without taking over the full version * fix clippy in example * small debug nits * update rust-overlay in nix * fix flake? * migrate to new structure * just comment out binstalls * just remove old test harness --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
45 lines
2.3 KiB
Rust
45 lines
2.3 KiB
Rust
use proc_macro2::TokenStream as TokenStream2;
|
|
use quote::ToTokens;
|
|
|
|
/// We store description of the assets an application uses in the executable.
|
|
/// We use the `link_section` attribute embed an extra section in the executable.
|
|
/// We force rust to store a serialized representation of the asset description
|
|
/// inside a particular region of the binary, with the label "manganis".
|
|
/// After linking, the "manganis" sections of the different object files will be merged.
|
|
pub fn generate_link_section(asset: impl ToTokens, asset_hash: &str) -> TokenStream2 {
|
|
let position = proc_macro2::Span::call_site();
|
|
let export_name = syn::LitStr::new(&format!("__ASSETS__{}", asset_hash), position);
|
|
let legacy_export_name = syn::LitStr::new(&format!("__MANGANIS__{}", asset_hash), position);
|
|
|
|
quote::quote! {
|
|
// We bundle both the legacy and new link sections for compatibility with older CLIs
|
|
static __LEGACY_LINK_SECTION: &'static [u8] = {
|
|
// First serialize the asset into a constant sized buffer
|
|
const __BUFFER: manganis::macro_helpers::const_serialize_07::ConstVec<u8> = manganis::macro_helpers::serialize_asset_07(&#asset);
|
|
// Then pull out the byte slice
|
|
const __BYTES: &[u8] = __BUFFER.as_ref();
|
|
// And the length of the byte slice
|
|
const __LEN: usize = __BYTES.len();
|
|
|
|
// Now that we have the size of the asset, copy the bytes into a static array
|
|
#[unsafe(export_name = #legacy_export_name)]
|
|
static __LINK_SECTION: [u8; __LEN] = manganis::macro_helpers::copy_bytes(__BYTES);
|
|
&__LINK_SECTION
|
|
};
|
|
|
|
static __LINK_SECTION: &'static [u8] = {
|
|
// First serialize the asset into a constant sized buffer
|
|
const __BUFFER: manganis::macro_helpers::const_serialize::ConstVec<u8> = manganis::macro_helpers::serialize_asset(&#asset);
|
|
// Then pull out the byte slice
|
|
const __BYTES: &[u8] = __BUFFER.as_ref();
|
|
// And the length of the byte slice
|
|
const __LEN: usize = __BYTES.len();
|
|
|
|
// Now that we have the size of the asset, copy the bytes into a static array
|
|
#[unsafe(export_name = #export_name)]
|
|
static __LINK_SECTION: [u8; __LEN] = manganis::macro_helpers::copy_bytes(__BYTES);
|
|
&__LINK_SECTION
|
|
};
|
|
}
|
|
}
|