Skip to content

Commit

Permalink
fix(melange): use output of virtual library when compiling its source (
Browse files Browse the repository at this point in the history
…#11248)

* test(melange): show crash when depending on public virtual lib impl

Signed-off-by: Antonio Nuno Monteiro <[email protected]>

* fix(melange): use output of virtual library when compiling its source
modules

Signed-off-by: Antonio Nuno Monteiro <[email protected]>

* chore: add changelog entry

Signed-off-by: Antonio Nuno Monteiro <[email protected]>

---------

Signed-off-by: Antonio Nuno Monteiro <[email protected]>
  • Loading branch information
anmonteiro authored Dec 29, 2024
1 parent 4757aa6 commit f0137df
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/changes/11248.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fix a crash in the Melange rules that would prevent compiling public library
implementations of virtual libraries. (@amonteiro, #11248)

1 change: 1 addition & 0 deletions src/dune_rules/melange/melange_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions test/blackbox-tests/test-cases/melange/virtual-lib-public-impl.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Test virtual libraries where the virtual implementation is a public library

$ mkdir -p vlib js_impl test
$ cat > dune-project <<EOF
> (lang dune 3.13)
> (using melange 0.1)
> (package (name the_lib))
> (package (name concrete_lib))
> EOF
$ cat > vlib/dune <<EOF
> (library
> (name the_lib)
> (modes melange native)
> (public_name the_lib)
> (virtual_modules virt))
> EOF
$ cat > vlib/the_lib.mli <<EOF
> module Time : sig
> val gettimeofday : unit -> float
> end
> EOF
$ cat > vlib/the_lib.ml <<EOF
> module Time = struct
> let gettimeofday () = Virt.gettimeofday ()
> end
> EOF
$ cat > vlib/virt.mli <<EOF
> val gettimeofday : unit -> float
> EOF

$ cat > js_impl/dune <<EOF
> (library
> (name timeJs)
> (public_name concrete_lib)
> (implements the_lib)
> (modes melange)
> (preprocess (pps melange.ppx)))
> EOF
$ cat > js_impl/virt.ml <<EOF
> let gettimeofday : unit -> float = fun () -> 42.
> EOF

$ cat > test/dune <<EOF
> (melange.emit
> (target output)
> (libraries the_lib concrete_lib)
> (emit_stdlib false))
> EOF

$ dune build @melange

0 comments on commit f0137df

Please sign in to comment.