add an env var that skips building the subs cache

This commit is contained in:
Folkert 2022-08-09 12:59:36 +02:00
parent 4766c78d61
commit 15665d612d
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 50 additions and 27 deletions

View file

@ -4,6 +4,13 @@ use bumpalo::Bump;
use roc_load_internal::file::{LoadingProblem, Threading};
use roc_module::symbol::ModuleId;
const SKIP_SUBS_CACHE: bool = {
match option_env!("ROC_SKIP_SUBS_CACHE") {
Some(s) => s.len() == 1 && s.as_bytes()[0] == b'1',
None => false,
}
};
const MODULES: &[(ModuleId, &str)] = &[
(ModuleId::BOOL, "Bool.roc"),
(ModuleId::RESULT, "Result.roc"),
@ -37,33 +44,39 @@ fn write_subs_for_module(module_id: ModuleId, filename: &str) {
let source = roc_builtins::roc::module_source(module_id);
let target_info = roc_target::TargetInfo::default_x86_64();
let res_module = roc_load_internal::file::load_and_typecheck_str(
&arena,
PathBuf::from(filename),
source,
src_dir,
Default::default(),
target_info,
roc_reporting::report::RenderTarget::ColorTerminal,
Threading::AllAvailable,
);
let module = match res_module {
Ok(v) => v,
Err(LoadingProblem::FormattedReport(report)) => {
panic!("{}", report);
}
Err(other) => {
panic!("build_file failed with error:\n{:?}", other);
}
};
let subs = module.solved.inner();
let exposed_vars_by_symbol: Vec<_> = module.exposed_to_host.into_iter().collect();
let mut output_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
output_path.extend(&[filename]);
output_path.set_extension("dat");
let mut file = std::fs::File::create(&output_path).unwrap();
subs.serialize(&exposed_vars_by_symbol, &mut file).unwrap();
if SKIP_SUBS_CACHE {
// write out a dummy file
std::fs::write(output_path, &[]).unwrap();
} else {
let res_module = roc_load_internal::file::load_and_typecheck_str(
&arena,
PathBuf::from(filename),
source,
src_dir,
Default::default(),
target_info,
roc_reporting::report::RenderTarget::ColorTerminal,
Threading::AllAvailable,
);
let module = match res_module {
Ok(v) => v,
Err(LoadingProblem::FormattedReport(report)) => {
panic!("{}", report);
}
Err(other) => {
panic!("build_file failed with error:\n{:?}", other);
}
};
let subs = module.solved.inner();
let exposed_vars_by_symbol: Vec<_> = module.exposed_to_host.into_iter().collect();
let mut file = std::fs::File::create(&output_path).unwrap();
subs.serialize(&exposed_vars_by_symbol, &mut file).unwrap();
}
}