diff --git a/crates/compiler/load/Cargo.toml b/crates/compiler/load/Cargo.toml index 330ee5d8a5..530aeadf86 100644 --- a/crates/compiler/load/Cargo.toml +++ b/crates/compiler/load/Cargo.toml @@ -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" } diff --git a/crates/compiler/load/build.rs b/crates/compiler/load/build.rs index 1fe50fea82..d663e4b03b 100644 --- a/crates/compiler/load/build.rs +++ b/crates/compiler/load/build.rs @@ -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(); }