Skip to content

Commit

Permalink
Fix includes of WIT source files to be bytes
Browse files Browse the repository at this point in the history
Instead of using `include_str!` use `include_bytes!` since the inputs
may now be in the wasm binary format instead of source file in utf-8.
  • Loading branch information
alexcrichton committed Feb 13, 2024
1 parent 3faf486 commit 121743a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rust-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wit-bindgen-rust-macro"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
version = "0.18.0"
version = "0.18.1"
edition.workspace = true
repository = 'https://github.com/bytecodealliance/wit-bindgen'
license = "Apache-2.0 WITH LLVM-exception"
Expand Down
11 changes: 7 additions & 4 deletions crates/rust-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,16 @@ impl Config {
}
let mut contents = src.parse::<TokenStream>().unwrap();

// Include a dummy `include_str!` for any files we read so rustc knows that
// Include a dummy `include_bytes!` for any files we read so rustc knows that
// we depend on the contents of those files.
for file in self.files.iter() {
contents.extend(
format!("const _: &str = include_str!(r#\"{}\"#);\n", file.display())
.parse::<TokenStream>()
.unwrap(),
format!(
"const _: &[u8] = include_bytes!(r#\"{}\"#);\n",
file.display()
)
.parse::<TokenStream>()
.unwrap(),
);
}

Expand Down

0 comments on commit 121743a

Please sign in to comment.