From eeabd8fd1916d036c3606c389569d37cf0f57c67 Mon Sep 17 00:00:00 2001 From: richarddavison <89518095+richarddavison@users.noreply.github.com> Date: Wed, 14 Aug 2024 06:42:24 +0200 Subject: [PATCH] fix: Place generated files in OUT_DIR (#542) * Place generated files in OUT_DIR * Remove unused import --- llrt_core/build.rs | 17 +++++++---------- llrt_core/src/vm.rs | 5 +++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/llrt_core/build.rs b/llrt_core/build.rs index 0e571d0ae2..819047a1da 100644 --- a/llrt_core/build.rs +++ b/llrt_core/build.rs @@ -6,7 +6,7 @@ use std::{ error::Error, fs::{self, File}, io::{self, BufWriter}, - path::{Path, PathBuf, MAIN_SEPARATOR_STR}, + path::{Path, PathBuf}, process::Command, result::Result as StdResult, }; @@ -17,7 +17,6 @@ use jwalk::WalkDir; use rquickjs::{CatchResultExt, CaughtError, Context, Module, Runtime}; const BUNDLE_JS_DIR: &str = "../bundle/js"; -const BUNDLE_LRT_DIR: &str = "../bundle/lrt"; include!("src/bytecode.rs"); @@ -52,7 +51,9 @@ async fn main() -> StdResult<(), Box> { rt.set_loader(resolver, loader); let ctx = Context::full(&rt)?; - let sdk_bytecode_path = Path::new("src").join("bytecode_cache.rs"); + let out_dir = env::var("OUT_DIR").unwrap(); + + let sdk_bytecode_path = Path::new(&out_dir).join("bytecode_cache.rs"); let mut sdk_bytecode_file = BufWriter::new(File::create(sdk_bytecode_path)?); let mut ph_map = phf_codegen::Map::::new(); @@ -100,7 +101,7 @@ async fn main() -> StdResult<(), Box> { info!("Compiling module: {}", module_name); - let lrt_path = PathBuf::from(BUNDLE_LRT_DIR).join(path.with_extension(BYTECODE_EXT)); + let lrt_path = PathBuf::from(&out_dir).join(path.with_extension(BYTECODE_EXT)); let lrt_filename = lrt_path.to_string_lossy().to_string(); lrt_filenames.push(lrt_filename.clone()); let bytes = { @@ -130,11 +131,7 @@ async fn main() -> StdResult<(), Box> { ph_map.entry( module_name, - &format!( - "include_bytes!(\"..{}{}\")", - MAIN_SEPARATOR_STR, &lrt_filename - ) - .replace(MAIN_SEPARATOR_STR, "/"), + &format!("include_bytes!(\"{}\")", &lrt_filename), ); } @@ -154,7 +151,7 @@ async fn main() -> StdResult<(), Box> { human_file_size(total_bytes) ); - let compression_dictionary_path = Path::new(BUNDLE_LRT_DIR) + let compression_dictionary_path = Path::new(&out_dir) .join("compression.dict") .to_string_lossy() .to_string(); diff --git a/llrt_core/src/vm.rs b/llrt_core/src/vm.rs index cc920750a8..75e0e6d35d 100644 --- a/llrt_core/src/vm.rs +++ b/llrt_core/src/vm.rs @@ -34,7 +34,7 @@ use rquickjs::{ use tracing::trace; use zstd::{bulk::Decompressor, dict::DecoderDictionary}; -include!("./bytecode_cache.rs"); +include!(concat!(env!("OUT_DIR"), "/bytecode_cache.rs")); use crate::modules::{ console, @@ -60,7 +60,8 @@ pub fn uncompressed_size(input: &[u8]) -> StdResult<(usize, &[u8]), io::Error> { Ok((uncompressed_size, rest)) } -pub(crate) static COMPRESSION_DICT: &[u8] = include_bytes!("../../bundle/lrt/compression.dict"); +pub(crate) static COMPRESSION_DICT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/compression.dict")); static DECOMPRESSOR_DICT: Lazy = Lazy::new(|| DecoderDictionary::copy(COMPRESSION_DICT));