Fix issue where precompiled plugins were compiled with the wrong settings

This commit is contained in:
Isaac Clayton 2022-07-13 16:31:47 +02:00
parent 01a2d53638
commit 3fb1cd0726
2 changed files with 18 additions and 8 deletions

View file

@ -43,7 +43,8 @@ fn main() {
assert!(build_successful); assert!(build_successful);
// Find all compiled binaries // Find all compiled binaries
let engine = create_default_engine(); let epoch_engine = create_epoch_engine();
let fuel_engine = create_fuel_engine();
let binaries = std::fs::read_dir(base.join("target/wasm32-wasi").join(profile_target)) let binaries = std::fs::read_dir(base.join("target/wasm32-wasi").join(profile_target))
.expect("Could not find compiled plugins in target"); .expect("Could not find compiled plugins in target");
@ -61,26 +62,35 @@ fn main() {
if let Some(path) = is_wasm() { if let Some(path) = is_wasm() {
let out_path = base.join("bin").join(path.file_name().unwrap()); let out_path = base.join("bin").join(path.file_name().unwrap());
std::fs::copy(&path, &out_path).expect("Could not copy compiled plugin to bin"); std::fs::copy(&path, &out_path).expect("Could not copy compiled plugin to bin");
precompile(&out_path, &engine); precompile(&out_path, &epoch_engine, "epoch");
precompile(&out_path, &fuel_engine, "fuel");
} }
} }
} }
/// Creates a default engine for compiling Wasm. fn create_epoch_engine() -> Engine {
fn create_default_engine() -> Engine {
let mut config = Config::default(); let mut config = Config::default();
config.async_support(true); config.async_support(true);
config.epoch_interruption(true);
Engine::new(&config).expect("Could not create engine") Engine::new(&config).expect("Could not create engine")
} }
fn precompile(path: &Path, engine: &Engine) { fn create_fuel_engine() -> Engine {
let mut config = Config::default();
config.async_support(true);
config.consume_fuel(true);
Engine::new(&config).expect("Could not create engine")
}
fn precompile(path: &Path, engine: &Engine, engine_name: &str) {
let bytes = std::fs::read(path).expect("Could not read wasm module"); let bytes = std::fs::read(path).expect("Could not read wasm module");
let compiled = engine let compiled = engine
.precompile_module(&bytes) .precompile_module(&bytes)
.expect("Could not precompile module"); .expect("Could not precompile module");
let out_path = path.parent().unwrap().join(&format!( let out_path = path.parent().unwrap().join(&format!(
"{}.pre", "{}.{}.pre",
path.file_name().unwrap().to_string_lossy() path.file_name().unwrap().to_string_lossy(),
engine_name,
)); ));
let mut out_file = std::fs::File::create(out_path) let mut out_file = std::fs::File::create(out_path)
.expect("Could not create output file for precompiled module"); .expect("Could not create output file for precompiled module");

View file

@ -26,7 +26,7 @@ pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
.map(|output| output.stdout) .map(|output| output.stdout)
})? })?
.init(PluginBinary::Precompiled(include_bytes!( .init(PluginBinary::Precompiled(include_bytes!(
"../../../../plugins/bin/json_language.wasm.pre" "../../../../plugins/bin/json_language.wasm.epoch.pre"
))) )))
.await?; .await?;