From 121743a8f6aaee39d3560544e4b2748b28218889 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 13 Feb 2024 14:52:41 -0800 Subject: [PATCH] Fix includes of WIT source files to be bytes 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. --- Cargo.lock | 2 +- crates/rust-macro/Cargo.toml | 2 +- crates/rust-macro/src/lib.rs | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 940613ad2..9fb6e33e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2446,7 +2446,7 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.18.0" +version = "0.18.1" dependencies = [ "anyhow", "proc-macro2", diff --git a/crates/rust-macro/Cargo.toml b/crates/rust-macro/Cargo.toml index 338498990..5a1439a26 100644 --- a/crates/rust-macro/Cargo.toml +++ b/crates/rust-macro/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "wit-bindgen-rust-macro" authors = ["Alex Crichton "] -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" diff --git a/crates/rust-macro/src/lib.rs b/crates/rust-macro/src/lib.rs index a47c692ff..dfb329836 100644 --- a/crates/rust-macro/src/lib.rs +++ b/crates/rust-macro/src/lib.rs @@ -176,13 +176,16 @@ impl Config { } let mut contents = src.parse::().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::() - .unwrap(), + format!( + "const _: &[u8] = include_bytes!(r#\"{}\"#);\n", + file.display() + ) + .parse::() + .unwrap(), ); }