-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
melange: add runtime_deps
field to library stanza
#6643
Conversation
Signed-off-by: Javier Chavarri <[email protected]>
@@ -131,6 +131,23 @@ end = struct | |||
let f ~dir = Load.get sctx ~dir >>= artifacts in | |||
Expander.set_lookup_ml_sources expander ~f | |||
|
|||
let buildable_files (buildable : Buildable.t) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing changes in this function, just moved from lines 166-179 below, to be able to split the Library
and Executable
cases.
src/dune_rules/simple_rules.ml
Outdated
let copy_files sctx ~dir ~expander ~src_dir (def : Copy_files.t) = | ||
Expander.eval_blang expander def.enabled_if >>= function | ||
| true -> copy_files sctx ~dir ~expander ~src_dir def | ||
| false -> Memo.return Path.Set.empty | ||
|
||
let extra_files_melange sctx ~dir ~expander ~src_dir files = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally tried to create this function inside Melange_rules
but got some cyclic dependency error:
Error: dependency cycle between modules in _build/default/src/dune_rules:
Virtual_rules
-> Dir_contents
-> Compilation_context
-> Dir_contents
extra_files
field to library stanza
I just remembered we discussed a couple of things:
I will update the PR to apply both changes above, please hold on any reviews until then. |
Signed-off-by: Javier Chavarri <[email protected]>
Could adding extra files in |
Signed-off-by: Javier Chavarri <[email protected]>
Maybe. In any case, I took a stab at it and ultimately decided to leave the runtime deps as a separate field. Adding it inside This is ready to review now. |
extra_files
field to library stanzaruntime_deps
field to library stanza
It depends on when are these files being accessed. Are they being accessed at all by the compiler? |
Seems like it's worth it to add a TODO to make this an error in the future. |
These files are fonts, images and / or css stylesheets that are included in the resulting bundle. See for example https://webpack.js.org/guides/asset-management/. I can't think of any examples where they would be accessed by the compiler. |
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
I was not sure how the TODO should be added (inline or new issue) so I went ahead and handled the error already as part of this PR: 7fc58cf. |
Signed-off-by: Javier Chavarri <[email protected]>
src/dune_rules/dir_contents.ml
Outdated
"Library %S is using \"melange.runtime_deps\", but it \ | ||
is not a Melange library. To fix this error, you must \ | ||
add \"melange\" to \"modes\", or remove \ | ||
\"melange.runtime_deps\"." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked the other errors in our code, and we don't quote field names. I'd drop the quotes here for the same reason. By the way, can this validation be moved to Dune_file? We should do it as early as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a lot of consistency, there are cases without quotes, with single quotes and with double quotes.
Happy to unify them in another PR.
For now, removed the quotes in this case and moved to dune_file
in 4a7e8b5.
src/dune_rules/simple_rules.ml
Outdated
let copy_files sctx ~dir ~expander ~src_dir (def : Copy_files.t) = | ||
Expander.eval_blang expander def.enabled_if >>= function | ||
| true -> copy_files sctx ~dir ~expander ~src_dir def | ||
| false -> Memo.return Path.Set.empty | ||
|
||
let melange_runtime_deps sctx ~dir ~expander ~src_dir files = | ||
copy_files' sctx ~dir ~expander ~src_dir ~add_line_directive:false ~alias:None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the glob here? I don't see the glob functionality being tested anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the glob will be very useful to have, yes. I will add some tests to exercise the functionality.
While checking this, I realized a couple of things:
- we want to allow multiple globs per field, e.g.
(melange.runtime_deps assets/*.png fonts/file.ttf)
- the current implementation is broken, the tests were only working by chance
I will update the PR with some improvements and fixes.
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
@rgrinberg I tried to start adapting implementation to Melange specific case, which differs from original
For now I am hard-coding the target value, just to be able to test a simple case. But I am not able to make it work, as I get the following error: dune/test/blackbox-tests/test-cases/melange/runtime-deps.t Lines 38 to 43 in afcca3c
The issue seems to happen in this line: dune/src/dune_rules/simple_rules.ml Lines 274 to 275 in afcca3c
I took a look at the Also, I think #6541 will heavily affect this PR, so if @anmonteiro is ok, I will probably switch focus to that PR to get it merged before continuing the work here. |
Another realization is that |
* main: (148 commits) refactor(rpc): remove mutable callback (ocaml#6786) refactor(stdune): make [Id.t] immediate (ocaml#6795) refactor(melange): share mode handling (ocaml#6799) refactor(scheduler): remove duplicate types (ocaml#6785) refactor: move cram stanza definition (ocaml#6800) fix: correctly validate argument to top-module (ocaml#6796) refactor: move generate_sites_module to own module (ocaml#6798) fix(melange): check rules (ocaml#6789) refactor(rpc): make [Call.to_dyn] public (ocaml#6797) refactor(rpc): invalid session errors (ocaml#6787) refactor(melange): remove js globs (ocaml#6782) doc: fix version indication for "dune ocaml top-module" (ocaml#6792) refactor: print shutdown exception (ocaml#6784) refactor(rpc): add [Call.to_dyn] (ocaml#6790) fix: do not impose no_sandboxing on ocamldep (ocaml#6749) refactor(melange): move stanza definition (ocaml#6775) fix: handle missing CLICOLOR_FORCE correctly (ocaml#6781) Revert --display tui (ocaml#6780) fix: render pending messages refactor(coq): inline coqc_rule ...
Signed-off-by: Javier Chávarri <[email protected]>
Signed-off-by: Javier Chávarri <[email protected]>
Signed-off-by: Javier Chávarri <[email protected]>
Error: Dependency cycle between: | ||
Computing directory contents of _build/default | ||
-> Evaluating predicate in directory _build/default/output/assets | ||
-> Computing directory contents of _build/default | ||
[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgrinberg do you have any ideas how to fix this dep cycle? It seems it is problematic to use globs with melange runtime_deps, should I just skip glob functionality for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to get over this error by removing glob functionality in d330036. It is less convenient to not have globs, but if it is going to lead to confusing rule cycles errors, better to leave them out.
However, runtime_deps are still not copied, I believe because the copy rules are there, but nothing depends on the asset files. I wonder though, what exactly should depend on these files? Should these asset paths be passed down and added as dep of the cmj
creation rules for each module? Otherwise I am not sure where else they could be added, as there is no such thing as "library-level target" in melange, like cma
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The targets should be added to the alias in the melange.emit stanza I'm thinking
You can use globs as long as you factor things into directories properly. You can also support globs and explicit files with constructors. E.g. (foo.txt (glob_files %{project_root}/*.txt))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The targets should be added to the alias in the melange.emit stanza I'm thinking
Is there a possibility to group all these copy rules under some "internal" alias that melange.emit
can use? Duplicating the targets in melange.emit stanzas kind of defeats the point of having runtime_deps
field, as it would roughly be the same as using copy_files
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thought about this coupling between library assets and emit stanza. In a future, there will be authors that publish Melange libraries. These libraries might need some assets to work properly. The problem as we are discussing is that the copying rules + alias deps are only known at melange.emit stanza time. But this is outside the control of the library author.
I am not sure how to represent this in Dune, but it seems we need some kind of "lazy rule", that contains all the information about the assets copying rules, except the prefix path which is the emit target. Then, at emission time, the rules would be "applied" with this prefix.
cc @anmonteiro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to "standardize" the output folders as we have discussed at some point in the past, always choosing either es6
or commonjs
target folders, depending on module_system
. Or just remove Edit: removing target
, as was implemented by Antonio in #6541.target
wouldn't solve the problem either, as the paths can differ based on where the melange.emit
stanza is found.
Signed-off-by: Javier Chávarri <[email protected]>
Signed-off-by: Javier Chávarri <[email protected]>
Superseded by #7234. |
Reuses the rules creation function from
copy_rules
.One remaining question is about merlin integration. Dirs from
copy_files
stanzas are added tosrc_dirs
here:dune/src/dune_rules/gen_rules.ml
Lines 123 to 133 in 670b7fb
However, in Melange case, these dirs will contain mostly assets that are needed at runtime. I can't think of any situations where they'd be needed at build time so I did not add any merlin-related functionality for this
runtime_deps
case.