Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions cli/common/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified by @jderochervlk that we don't need this for Deno.


if (typeof import.meta.resolve === "function") {
const url = import.meta.resolve(specifier);
Expand Down
4 changes: 3 additions & 1 deletion compiler/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 4 additions & 1 deletion rewatch/src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> {
pub fn get_runtime_path_args(
package_config: &Config,
project_context: &ProjectContext,
) -> Result<Vec<String>> {
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") {
Expand Down
43 changes: 36 additions & 7 deletions rewatch/src/build/namespaces.rs
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -51,20 +53,47 @@ 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<String> = 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()
.map(StrippedVerbatimPath::to_stripped_verbatim_path)
.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(())
}
18 changes: 15 additions & 3 deletions rewatch/src/build/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::process::Command;
pub fn generate_asts(
build_state: &mut BuildState,
inc: impl Fn() + std::marker::Sync,
) -> Result<String, String> {
) -> anyhow::Result<String> {
let mut has_failure = false;
let mut stderr = "".to_string();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading