diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a72c55f3d..9bd1d04c4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ #### :bug: Bug fix +- Include `-runtime-path` as bsc argument when generating `.mlmap` file. https://github.com/rescript-lang/rescript/pull/7888 + #### :memo: Documentation #### :nail_care: Polish diff --git a/cli/common/runtime.js b/cli/common/runtime.js index 2b9af59ec0..9967e1cef5 100644 --- a/cli/common/runtime.js +++ b/cli/common/runtime.js @@ -42,10 +42,7 @@ async function resolvePackageInDeno(pkgName) { } async function resolvePackageRoot(pkgName) { - const specifier = - typeof globalThis.Deno !== "undefined" - ? `npm:${pkgName}/package.json` - : `${pkgName}/package.json`; + const specifier = `${pkgName}/package.json`; if (typeof import.meta.resolve === "function") { const url = import.meta.resolve(specifier); diff --git a/compiler/bsb/bsb_ninja_rule.ml b/compiler/bsb/bsb_ninja_rule.ml index 2f90bb42e9..b5a41f407b 100644 --- a/compiler/bsb/bsb_ninja_rule.ml +++ b/compiler/bsb/bsb_ninja_rule.ml @@ -206,7 +206,9 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) let mi, mi_dev = aux ~read_cmi:`is_cmi ~postbuild:None ~name:"mi" in let build_package = define - ~command:(bsc ^ " -w -49 -color always -no-alias-deps $i") + ~command: + (bsc ^ " -w -49 -color always -no-alias-deps -runtime-path " + ^ !Runtime_package.path ^ " $i") ~restat:() "build_package" in { diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index 578ce4c112..67074c9ddd 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -336,7 +336,10 @@ pub fn compile( Ok((compile_errors, compile_warnings, num_compiled_modules)) } -fn get_runtime_path_args(package_config: &Config, project_context: &ProjectContext) -> Result> { +pub fn get_runtime_path_args( + package_config: &Config, + project_context: &ProjectContext, +) -> Result> { match std::env::var("RESCRIPT_RUNTIME") { Ok(runtime_path) => Ok(vec!["-runtime-path".to_string(), runtime_path]), Err(_) => match helpers::try_package_path(package_config, project_context, "@rescript/runtime") { diff --git a/rewatch/src/build/namespaces.rs b/rewatch/src/build/namespaces.rs index 4bd63501b5..9042e8a2ec 100644 --- a/rewatch/src/build/namespaces.rs +++ b/rewatch/src/build/namespaces.rs @@ -1,12 +1,14 @@ +use crate::build::compile::get_runtime_path_args; use crate::build::packages; use crate::helpers::StrippedVerbatimPath; +use crate::project_context::ProjectContext; use ahash::AHashSet; +use anyhow::{Result, anyhow}; use std::fs::File; use std::io::Write; use std::path::Path; use std::path::PathBuf; use std::process::Command; - // Namespaces work like the following: The build system will generate a file // called `MyModule.mlmap` which contains all modules that are in the namespace // @@ -51,12 +53,28 @@ pub fn gen_mlmap( path } -pub fn compile_mlmap(package: &packages::Package, namespace: &str, bsc_path: &Path) { +pub fn compile_mlmap( + project_context: &ProjectContext, + package: &packages::Package, + namespace: &str, + bsc_path: &Path, +) -> Result<()> { let build_path_abs = package.get_build_path(); let mlmap_name = format!("{namespace}.mlmap"); - let args = vec!["-w", "-49", "-color", "always", "-no-alias-deps", &mlmap_name]; + let mut args: Vec = vec![]; + // include `-runtime-path` arg + args.extend(get_runtime_path_args(&package.config, project_context)?); + // remaining flags + args.extend([ + "-w".to_string(), + "-49".to_string(), + "-color".to_string(), + "always".to_string(), + "-no-alias-deps".to_string(), + ]); + args.push(mlmap_name.clone()); - let _ = Command::new(bsc_path) + let output = Command::new(bsc_path) .current_dir( build_path_abs .canonicalize() @@ -64,7 +82,18 @@ pub fn compile_mlmap(package: &packages::Package, namespace: &str, bsc_path: &Pa .ok() .unwrap(), ) - .args(args) - .output() - .expect("err"); + .args(&args) + .output()?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr).to_string(); + return Err(anyhow!( + "Failed to compile namespace mlmap {} in {}: {}", + namespace, + build_path_abs.to_string_lossy(), + stderr + )); + } + + Ok(()) } diff --git a/rewatch/src/build/parse.rs b/rewatch/src/build/parse.rs index 6e0380f671..f1a8583ffe 100644 --- a/rewatch/src/build/parse.rs +++ b/rewatch/src/build/parse.rs @@ -16,7 +16,7 @@ use std::process::Command; pub fn generate_asts( build_state: &mut BuildState, inc: impl Fn() + std::marker::Sync, -) -> Result { +) -> anyhow::Result { let mut has_failure = false; let mut stderr = "".to_string(); @@ -192,7 +192,15 @@ pub fn generate_asts( // specific to compiling mlmaps let compile_path = package.get_mlmap_compile_path(); let mlmap_hash = helpers::compute_file_hash(Path::new(&compile_path)); - namespaces::compile_mlmap(package, module_name, &build_state.bsc_path); + if let Err(err) = namespaces::compile_mlmap( + &build_state.project_context, + package, + module_name, + &build_state.bsc_path, + ) { + has_failure = true; + stderr.push_str(&format!("{}\n", err)); + } let mlmap_hash_after = helpers::compute_file_hash(Path::new(&compile_path)); let suffix = package @@ -232,7 +240,11 @@ pub fn generate_asts( } }); - if has_failure { Err(stderr) } else { Ok(stderr) } + if has_failure { + Err(anyhow!(stderr)) + } else { + Ok(stderr) + } } pub fn parser_args(