From d889031cc134d5166eba139fad7f02ecf19f0523 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 20 Apr 2024 11:38:33 +0530 Subject: [PATCH] refactor: let `Metadata::create_env_patched_bin` handle compiler defaults In the previous commit, I had moved `LuaCompiler` construction into the CLI command, which was not necessary. This reverts that. --- src/cli/build.rs | 14 +++----------- src/standalone/metadata.rs | 6 +++++- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/cli/build.rs b/src/cli/build.rs index 861e046..a9b6bc8 100644 --- a/src/cli/build.rs +++ b/src/cli/build.rs @@ -10,7 +10,6 @@ use async_zip::base::read::seek::ZipFileReader; use clap::Parser; use console::style; use directories::BaseDirs; -use mlua::Compiler; use once_cell::sync::Lazy; use thiserror::Error; use tokio::{ @@ -69,16 +68,9 @@ impl BuildCommand { style("Compile").green().bold(), style(input_path_displayed).underlined() ); - let patched_bin = Metadata::create_env_patched_bin( - base_exe_path, - source_code.clone(), - Compiler::new() - .set_optimization_level(2) - .set_coverage_level(0) - .set_debug_level(1), - ) - .await - .context("failed to create patched binary")?; + let patched_bin = Metadata::create_env_patched_bin(base_exe_path, source_code.clone()) + .await + .context("failed to create patched binary")?; // And finally write the patched binary to the output file println!( diff --git a/src/standalone/metadata.rs b/src/standalone/metadata.rs index e546196..f2ddfd9 100644 --- a/src/standalone/metadata.rs +++ b/src/standalone/metadata.rs @@ -51,8 +51,12 @@ impl Metadata { pub async fn create_env_patched_bin( base_exe_path: PathBuf, script_contents: impl Into>, - compiler: LuaCompiler, ) -> Result> { + let compiler = LuaCompiler::new() + .set_optimization_level(2) + .set_coverage_level(0) + .set_debug_level(1); + let mut patched_bin = fs::read(base_exe_path).await?; // Compile luau input into bytecode