From d44acf9d98de1cf5a896e55db418f20323c9e2ef Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 26 Dec 2024 22:41:42 -0800 Subject: [PATCH 1/3] test(melange): show crash when depending on public virtual lib impl Signed-off-by: Antonio Nuno Monteiro --- .../melange/virtual-lib-public-impl.t | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t diff --git a/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t b/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t new file mode 100644 index 00000000000..d353789ecf1 --- /dev/null +++ b/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t @@ -0,0 +1,51 @@ +Test a case of virtual libraries where the virtual library is transitive + + $ mkdir -p vlib js_impl test + $ cat > dune-project < (lang dune 3.13) + > (using melange 0.1) + > (package (name the_lib)) + > (package (name the_liba)) + > EOF + $ cat > vlib/dune < (library + > (name the_lib) + > (modes melange native) + > (public_name the_lib) + > (virtual_modules virt)) + > EOF + $ cat > vlib/the_lib.mli < module Time : sig + > val gettimeofday : unit -> float + > end + > EOF + $ cat > vlib/the_lib.ml < module Time = struct + > let gettimeofday () = Virt.gettimeofday () + > end + > EOF + $ cat > vlib/virt.mli < val gettimeofday : unit -> float + > EOF + + $ cat > js_impl/dune < (library + > (name timeJs) + > (public_name the_liba.js) + > (implements the_lib) + > (modes melange) + > (preprocess (pps melange.ppx))) + > EOF + $ cat > js_impl/virt.ml < let gettimeofday : unit -> float = fun () -> 42. + > EOF + + $ cat > test/dune < (melange.emit + > (target output) + > (libraries the_lib timeJs) + > (emit_stdlib false)) + > EOF + + $ dune build @melange 2>&1 | grep -io 'must not crash' + must not crash From d9430cc8f09cb5b230a8914a8ab988298ad650bc Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 26 Dec 2024 23:16:41 -0800 Subject: [PATCH 2/3] fix(melange): use output of virtual library when compiling its source modules Signed-off-by: Antonio Nuno Monteiro --- src/dune_rules/melange/melange_rules.ml | 1 + .../test-cases/melange/virtual-lib-public-impl.t | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dune_rules/melange/melange_rules.ml b/src/dune_rules/melange/melange_rules.ml index a9b1644649a..0e2411dddb3 100644 --- a/src/dune_rules/melange/melange_rules.ml +++ b/src/dune_rules/melange/melange_rules.ml @@ -597,6 +597,7 @@ let setup_js_rules_libraries = in cmj_includes ~requires_link ~scope lib_config in + let output = output_of_lib ~target_dir vlib in parallel_build_source_modules ~sctx ~scope diff --git a/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t b/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t index d353789ecf1..893df4cfa48 100644 --- a/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t +++ b/test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t @@ -1,11 +1,11 @@ -Test a case of virtual libraries where the virtual library is transitive +Test virtual libraries where the virtual implementation is a public library $ mkdir -p vlib js_impl test $ cat > dune-project < (lang dune 3.13) > (using melange 0.1) > (package (name the_lib)) - > (package (name the_liba)) + > (package (name concrete_lib)) > EOF $ cat > vlib/dune < (library @@ -31,7 +31,7 @@ Test a case of virtual libraries where the virtual library is transitive $ cat > js_impl/dune < (library > (name timeJs) - > (public_name the_liba.js) + > (public_name concrete_lib) > (implements the_lib) > (modes melange) > (preprocess (pps melange.ppx))) @@ -43,9 +43,8 @@ Test a case of virtual libraries where the virtual library is transitive $ cat > test/dune < (melange.emit > (target output) - > (libraries the_lib timeJs) + > (libraries the_lib concrete_lib) > (emit_stdlib false)) > EOF - $ dune build @melange 2>&1 | grep -io 'must not crash' - must not crash + $ dune build @melange From 8ae566fb1957fb503730cb825db2a4d236d61197 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 26 Dec 2024 23:26:41 -0800 Subject: [PATCH 3/3] chore: add changelog entry Signed-off-by: Antonio Nuno Monteiro --- doc/changes/11248.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 doc/changes/11248.md diff --git a/doc/changes/11248.md b/doc/changes/11248.md new file mode 100644 index 00000000000..e99f2a2734b --- /dev/null +++ b/doc/changes/11248.md @@ -0,0 +1,3 @@ +- Fix a crash in the Melange rules that would prevent compiling public library + implementations of virtual libraries. (@amonteiro, #11248) +