-
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
feat(melange): install melange libraries #6602
Conversation
Currently installing melange libraries in |
485665a
to
6c7babd
Compare
6c7babd
to
f3b69e5
Compare
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
…ame/*.js" Signed-off-by: Antonio Nuno Monteiro <[email protected]>
f3b69e5
to
7e0cb06
Compare
src/dune_rules/melange_rules.ml
Outdated
let lib_dir = | ||
match Lib.Local.of_lib lib with | ||
| None -> | ||
let package_name = Option.value_exn (Lib_info.package info) in |
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.
Why is value_exn
okay here?
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 know if it is. What would you suggest we do if it's None
?
This brings up another design question:
- I think I'd rather use the library
public_name
as the--bs-package-name ..
so that we could depend on multiple public libraries within the same package. The naming scheme for those isalphanumerical-maybe-dashes.sublibrary
, which I think can be a valid folder name for the node.js module resolution algorithm
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.
What would you suggest we do if it's None?
Work the way it worked before I guess? Right now this will not work for private libraries.
I think I'd rather use the library public_name as the --bs-package-name .. so that we could depend on multiple public libraries within the same package. The naming scheme for those is alphanumerical-maybe-dashes.sublibrary, which I think can be a valid folder name for the node.js module resolution algorithm
Better ask @jchavarri about that.
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.
Why not? The tests are passing. This is in the branch where Lib.Local.of_lib
is None
. I thought that'd be the branch for external libraries.
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 see. But then you're distinguishing between public libraries that are installed and ones that are in the workspace.
I think you should distinguish between public (external or in-workspace) and private libraries instead.
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.
We could also always use Lib.name
now that we have the node_modules
emission stuff.
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.
There's Lib_info.Status.t
. In particular, when it's Private (_, 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.
I think I'd rather use the library public_name as the --bs-package-name ..
Better ask @jchavarri about that.
I thought about this and I believe it should be fine. The only caveat is that in order to consume a public library from the same workspace, the library should be installed first, but I guess that's ok? Are workspace libraries "constantly installed" when running e.g. dune build -w
?
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.
In particular, when it's
Private (_, None)
I am taking a stab at fixing this, but I am confused about this comment. If we want to distinguish between public and private, why does the second part of the payload (None
, the package) matter?
I made all tests pass with something like this:
let lib_dir =
match Lib_info.status info with
| Installed | Installed_private | Private (_, Some _) ->
let package_name = Option.value_exn (Lib_info.package info) in
let bctx, _ = Path.Build.extract_build_context_dir_exn target_dir in
Path.Build.(
relative
((relative bctx) "node_modules")
(Package.Name.to_string package_name))
| Private (_, None) | Public _ ->
let lib = Lib.Local.of_lib_exn lib in
let info = Lib.Local.info lib in
Lib_info.src_dir info
but it does not make much sense to me.
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.
Public libraries have the following guarantee: their behavior is the same regardless of whether they're installed or are present in the current workspace.
The second part of the payload matters because there's also private libraries with the above guarantee. Those private libraries with the package
field set.
src/dune_rules/melange_rules.ml
Outdated
let bctx, _ = Path.Build.extract_build_context_dir_exn target_dir in | ||
Path.Build.( | ||
relative | ||
((relative bctx) "node_modules") |
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.
We have Path.Build.L.relative
to make this easier to read
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.
Added in anmonteiro@4224f26, can be merged separately or together with anmonteiro#3.
> EOF | ||
$ cat > a/dune <<EOF | ||
> (library | ||
> (modes melange) |
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.
Is there a test that has (modes melange byte)
? To make sure they don't step over each other.
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 I have one untracked in git that I can add
src/dune_rules/install_rules.ml
Outdated
, Obj_dir.Module.cmt_file obj_dir m ~ml_kind | ||
~cm_kind:(Melange Cmi) ) | ||
] | ||
|> List.concat) |
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.
Perhaps remove the duplication with:
List.concat_map [ (native || byte), Ocaml Cmi ; melange, Melange Cmi ] ~f:(...
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.
Done in anmonteiro@27905d1.
It would also be useful to add a test for private libraries that belong to package. For example:
The findlib name for these is mangled. |
Signed-off-by: Javier Chavarri <[email protected]>
The latest from |
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
I added a test for this in anmonteiro@21de584, where there is a But something fundamental seems to be broken in this case because dune can't find the rules for the cmjs (unless I am doing something wrong on the test setup itself). Still investigating. |
Signed-off-by: Javier Chavarri <[email protected]>
Well, this is embarrassing. I was missing the The private lib test seems to be passing (see anmonteiro@0e7225a), so the only 2 things remaining that I am aware of are:
|
Signed-off-by: Javier Chavarri <[email protected]>
Please do, I lost my untracked changes in my other computer. |
Signed-off-by: Javier Chavarri <[email protected]>
Done in anmonteiro#5. Added as separate test but can merge into the existing one if it's preferable. |
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
a8ab73d
to
73e66b3
Compare
@@ -1,5 +1,4 @@ | |||
(melange.emit | |||
(package pkg) |
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.
We discussed this privately, but leaving here a note for posterity:
The approach I ended up taking is to always put js artifacts of public libs in node_modules, regardless which package or dune project they belong to:
- If two public libraries belong to the same package, relative paths like
require('../foo/bar.js')
will work because the original source layout is honored under the node_modules folder- If two public libs belong to different packages, non-relative paths like
require('foo/bar.js')
will work because at the top level there will be a node_modules folder that includes foo.
This approach breaks only in one case: when the entries in melange.emit belong to the same package as some public library. I was able to fix this by removing the package entry from melange.emit, so the entries in emit become "private" (in dune's
Lib_info.Status.t
terms).
Rudi answered:
For executables, we have a
package
field. But this is mainly useful when you want to:
- Install the executable
- Include the executable as part of the test suite for the package. so that
dune build -p pkg @runtest
will see this executable
We probably want to fix this at some point in the future, either by removing package
field in melange.emit
(at least in the short term), or figuring out how to perform installation of emit entries.
let package_name = Option.value_exn (Lib_info.package info) in | ||
let bctx = (Super_context.context sctx).build_dir in | ||
Path.Build.L.relative bctx | ||
[ "node_modules"; Package.Name.to_string package_name ] |
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.
Public
is handled differently than | Installed | Installed_private
which means that installation is going to be broken. I think for Public
libraries you need to remove the src_dir
component. If a library is public, the user can't make assumptions as to where its located
Signed-off-by: Javier Chávarri <[email protected]>
…-libs melange: fix install for public libs in different dune projects Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chávarri <[email protected]>
e8814b4
to
ccf117a
Compare
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
7a4cd04
to
78dd6fa
Compare
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
First part of feature(melange): installation of libraries #6600:
$LIB_DIR/melange/*.cm{i,j,t}
modes melange
melange.emit
emits public library dependency JS to$emit_target/node_modules/lib_name/**/*.js
if refactor(melange): switch
--bs-package-name
to library name #6841 lands, we need to adapt this PR to installnode_modules/<lib_name>
rather thannode_modules/<pkg-name>
figure out a solution that doesn't use
Lib_info.src_dir
for public librariesSigned-off-by: Antonio Nuno Monteiro [email protected]