Merge pull request #3894 from roc-lang/windows-disable-subs-caching

windows disable subs caching statically
This commit is contained in:
Brian Carroll 2022-08-25 20:50:10 +01:00 committed by GitHub
commit 35de4c6e6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 35 deletions

View file

@ -16,9 +16,11 @@ roc_collections = { path = "../collections" }
roc_reporting = { path = "../../reporting" }
[build-dependencies]
roc_load_internal = { path = "../load_internal" }
roc_builtins = { path = "../builtins" }
roc_module = { path = "../module" }
roc_reporting = { path = "../../reporting" }
roc_target = { path = "../roc_target" }
bumpalo = { version = "3.8.0", features = ["collections"] }
[target.'cfg(not(windows))'.build-dependencies]
roc_load_internal = { path = "../load_internal" }

View file

@ -1,7 +1,7 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
#[cfg(not(windows))]
use bumpalo::Bump;
use roc_load_internal::file::{LoadingProblem, Threading};
use roc_module::symbol::ModuleId;
const SKIP_SUBS_CACHE: bool = {
@ -39,44 +39,63 @@ fn write_subs_for_module(module_id: ModuleId, filename: &str) {
.join(filename);
println!("cargo:rerun-if-changed={}", filepath.to_str().unwrap());
let mut output_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
output_path.extend(&[filename]);
output_path.set_extension("dat");
#[cfg(not(windows))]
if SKIP_SUBS_CACHE {
write_subs_for_module_dummy(&output_path)
} else {
write_subs_for_module_real(module_id, filename, &output_path)
}
#[cfg(windows)]
{
let _ = SKIP_SUBS_CACHE;
let _ = module_id;
write_subs_for_module_dummy(&output_path)
}
}
fn write_subs_for_module_dummy(output_path: &Path) {
// write out a dummy file
std::fs::write(output_path, &[]).unwrap();
}
#[cfg(not(windows))]
fn write_subs_for_module_real(module_id: ModuleId, filename: &str, output_path: &Path) {
use roc_load_internal::file::{LoadingProblem, Threading};
let arena = Bump::new();
let src_dir = PathBuf::from(".");
let source = roc_builtins::roc::module_source(module_id);
let target_info = roc_target::TargetInfo::default_x86_64();
let mut output_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
output_path.extend(&[filename]);
output_path.set_extension("dat");
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,
);
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 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 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();
}
let mut file = std::fs::File::create(&output_path).unwrap();
subs.serialize(&exposed_vars_by_symbol, &mut file).unwrap();
}