Skip to content

Commit

Permalink
fix: Place generated files in OUT_DIR (#542)
Browse files Browse the repository at this point in the history
* Place generated files in OUT_DIR

* Remove unused import
  • Loading branch information
richarddavison authored Aug 14, 2024
1 parent 7d49710 commit eeabd8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
17 changes: 7 additions & 10 deletions llrt_core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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");

Expand Down Expand Up @@ -52,7 +51,9 @@ async fn main() -> StdResult<(), Box<dyn Error>> {
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::<String>::new();
Expand Down Expand Up @@ -100,7 +101,7 @@ async fn main() -> StdResult<(), Box<dyn Error>> {

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 = {
Expand Down Expand Up @@ -130,11 +131,7 @@ async fn main() -> StdResult<(), Box<dyn Error>> {

ph_map.entry(
module_name,
&format!(
"include_bytes!(\"..{}{}\")",
MAIN_SEPARATOR_STR, &lrt_filename
)
.replace(MAIN_SEPARATOR_STR, "/"),
&format!("include_bytes!(\"{}\")", &lrt_filename),
);
}

Expand All @@ -154,7 +151,7 @@ async fn main() -> StdResult<(), Box<dyn Error>> {
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();
Expand Down
5 changes: 3 additions & 2 deletions llrt_core/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<DecoderDictionary> =
Lazy::new(|| DecoderDictionary::copy(COMPRESSION_DICT));
Expand Down

0 comments on commit eeabd8f

Please sign in to comment.