dune icon indicating copy to clipboard operation
dune copied to clipboard

Dune does not recognise separate source map files from js_of_ocaml

Open katrinafyi opened this issue 1 year ago • 1 comments

Expected Behavior

Hello, I am compiling a module using jsoo using separate sourcemap files. After passing --sourcemap in both flags and link_flags, js_of_ocaml will emit both .bc.js and .bc.map file into the build folder.

We expect that Dune is aware of the .js and .map files, and we should be able to reference these in other rules. For example, this dune file should install both the compiled Javascript and its source map into the bin directory.

(executable
  (name builder)
  (modes js)
  (modules builder)

  (js_of_ocaml (flags --sourcemap :standard \ --source-map-inline)
               (link_flags --sourcemap :standard \ --source-map-inline)))

; static files for distribution
(install
 (files builder.bc.js builder.map.js)
 (section bin))

Actual Behavior

Dune does not recognise the .map file ("no rule found") and fails the build.

File "web/dune", line 28, characters 22-36:
28 |  (files builder.bc.js builder.bc.map index.html)
                           ^^^^^^^^^^^^^^
Error: No rule found for web/builder.bc.map

Reproduction

  • PR with a reproducing test:
  1. Attempt a build with a dune file similar to the above. For convenience, I have created a minimal dune project here: jsoo_sourcemap_missing.tar.gz.
  2. Observe the error when running dune build.
  3. Note the source map is present in the build directory: ls _build/default/web/
  4. Observe a successful build when omitting the .map.js from the install clause of web/dune.

Specifications

  • Version of dune (output of dune --version): 3.16.0
  • Version of ocaml (output of ocamlc --version): 4.14.2
  • Operating system (distribution and version): EndeavourOS Rolling Linux x86_64

katrinafyi avatar Jun 27 '24 09:06 katrinafyi

@hhugo what should we do?

rgrinberg avatar Jun 30 '24 20:06 rgrinberg

In the meantime, I have a script to generate standalone .map files from an embedded source map: https://github.com/katrinafyi/aslp-web/blob/1fe909c1a4d58a42aa98188840cd2e5e20d31427/sourcemap.py

This is certainly a hack.

katrinafyi avatar Jul 27 '24 00:07 katrinafyi

@rgrinberg, it's easy to compute targets based on flags. However, I'm blocked trying to implement it. The reason is that we need to be inside Action_builder.t to compute flags (because of :include) but the list of targets need to live outside Action_builder, or so it seems. Can you give me some guidance here ?

hhugo avatar Jul 29 '24 07:07 hhugo