[PATCH] Fix embedded data being duplicated in binary

4 views
Skip to first unread message

Lambda

unread,
5:54 AM (13 hours ago) 5:54 AM
to rust-em...@googlegroups.com
`const` items are always inlined, which is a problem because `ENTRIES`
is used both to find the index of the requested file and to retrieve its
content. In release builds, this is usually optimized away, but with the
`debug-embed` feature enabled, the entire embedded data is reliably
embedded twice in the binary:

$ cargo build --quiet --example basic --features debug-embed && \
strings target/debug/examples/basic | grep -F console.log
main.jsconsole.log("Awesomeness we can has")
main.jsconsole.log("Awesomeness we can has")
---
impl/src/lib.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/impl/src/lib.rs b/impl/src/lib.rs
index 15e8974..c22bd21 100644
--- a/impl/src/lib.rs
+++ b/impl/src/lib.rs
@@ -80,7 +80,7 @@ fn embedded(
pub fn get(file_path: &str) ->
::std::option::Option<#crate_path::EmbeddedFile> {
#handle_prefix
let key = file_path.replace("\\", "/");
- const ENTRIES: &'static [(&'static str, #value_type)] = &[
+ static ENTRIES: &'static [(&'static str, #value_type)] = &[
#(#match_values)*];
let position = ENTRIES.binary_search_by_key(&key.as_str(),
|entry| entry.0);
position.ok().map(#get_value)
--
2.54.0

Peter John

unread,
11:37 AM (8 hours ago) 11:37 AM
to rust-embed-devs
Thanks. I've added your patch in a commit and will release a new version soon.

Regards,
Peter
Reply all
Reply to author
Forward
0 new messages