Add support for embedding resources in the rust generator

This is relatively straight-forward via a pass in the compiler to
collect the resources to embed and then use include_bytes! (once per
resource).

What's really annoying is that the rust resource enum can't store a
&'static [u8] because cbindgen doesn't represent that, probably because
the slice representation isn't guaranteed to stay as it is. So instead
this, for now, uses raw pointers.
This commit is contained in:
Simon Hausmann 2020-06-09 22:00:37 +02:00
parent 82a7c3e070
commit 1404cb73ae
15 changed files with 105 additions and 98 deletions

View file

@ -53,7 +53,15 @@ pub fn compile(path: impl AsRef<std::path::Path>) -> Result<(), CompileError> {
let mut tr = typeregister::TypeRegister::builtin();
let doc = object_tree::Document::from_node(syntax_node, &mut diag, &mut tr);
run_passes(&doc, &mut diag, &mut tr);
let mut compiler_config = CompilerConfiguration::default();
if let Some(target) = env::var("TARGET").ok() {
if target == "wasm32-unknown-unknown" {
compiler_config.embed_resources = true;
}
};
run_passes(&doc, &mut diag, &mut tr, &compiler_config);
if diag.has_error() {
let vec = diag.inner.iter().map(|d| d.message.clone()).collect();