properly expose all symbls in manganis without linker intercept (#3230)
* force a volatile read of manganis symbols to preserve them in the final binary
This commit is contained in:
1 parent
017478d212
commit
493c5c7532
4 files changed
+12
-25
No files matched your search
@@ -104,6 +104,8 @@ impl ToTokens for AssetParser {
|
||||
|
||||
// "/blahcss123.css"
|
||||
bundled: #bundled,
|
||||
|
||||
metadata: __volatile_reader as fn() -> u8,
|
||||
}
|
||||
}
|
||||
) #option_source
|
||||
|
||||
@@ -17,5 +17,9 @@ pub fn generate_link_section(asset: &impl Serialize) -> TokenStream2 {
|
||||
#[link_section = #section_name]
|
||||
#[used]
|
||||
static ASSET: [u8; #len] = * #asset_bytes;
|
||||
|
||||
fn __volatile_reader() -> u8 {
|
||||
unsafe { std::ptr::read_volatile(ASSET.as_ptr()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@ pub struct Asset {
|
||||
///
|
||||
/// `blah-123.css``
|
||||
pub bundled: &'static str,
|
||||
|
||||
/// The metadata for this asset plumbed by the compiler
|
||||
pub metadata: fn() -> u8,
|
||||
}
|
||||
|
||||
impl Asset {
|
||||
@@ -47,6 +50,9 @@ impl Asset {
|
||||
/// Attempts to resolve it against an `assets` folder in the current directory.
|
||||
/// If that doesn't exist, it will resolve against the cargo manifest dir
|
||||
pub fn resolve(&self) -> PathBuf {
|
||||
// Force a volatile read of the metadata to ensure the symbol makes it into the binary
|
||||
(self.metadata)();
|
||||
|
||||
// If the asset is relative, we resolve the asset at the current directory
|
||||
if !dioxus_core_types::is_bundled_app() {
|
||||
return PathBuf::from(self.local);
|
||||
|
||||
Reference in new issue
Block a user