Skip to content
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

Fix native code generation of empty libraries on MSVC #2693

Closed
wants to merge 6 commits into from

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Oct 3, 2019

Fixes #2687 (hopefully)

Discovered in the wild in ocaml/stdlib-shims#11 - the fact it affects stdlib-shims means the fix should probably go in 1.11 as well, and I've prepared a branch for that already (assuming this code is OK...)

This fixes the Dune side - in order to use these libraries, it's necessary to have ocaml/ocaml#9011, so empty libraries will be non-portable for OCaml < 4.10.

Given that this has only so far been seen with stdlib-shims (which is a special case), I'd go with Dune not trying to workaround this problem further.

@ghost
Copy link

ghost commented Oct 3, 2019

Thanks! Looks good but we also need to modify Dune_file.Library.to_lib_info, in particular the foreign_archives field. We should probably factorise the logic for deciding about whether the library has an archive in one place.

@dra27
Copy link
Member Author

dra27 commented Oct 6, 2019

Hmm - I can see the problem, but I'm not sure how to proceed. The list of modules in the library isn't determined at the point the Lib_info.t is assembled? It sounds as though the decision on whether there's going to be a .a or .lib file needs to be deferred, right?

@rgrinberg
Copy link
Member

This also needs a CHANGES entry

@ghost ghost force-pushed the empty-cmxa branch from 1ee5539 to ee3d324 Compare October 7, 2019 10:53
@ghost
Copy link

ghost commented Oct 7, 2019

We can always use Dir_contents.modules_of_library to determine that. We probably can't do it inside dune_file.ml, but we can do it from lib.ml where to_lib_info is called

@rgrinberg rgrinberg added this to the 1.11.4 milestone Oct 8, 2019
dra27 added 3 commits October 8, 2019 13:14
MSVC doesn't support empty .lib files, so various places which depend on
the .lib file for a .cmxa or which expect to generate altered to
understand the difference.

Signed-off-by: David Allsopp <[email protected]>
This only activates if the modules stanza is explicitly empty.

Signed-off-by: David Allsopp <[email protected]>
@dra27 dra27 removed this from the 1.11.4 milestone Oct 8, 2019
@dra27
Copy link
Member Author

dra27 commented Oct 8, 2019

This has been worked around in stdlib-shims, so it's no longer a blocker for Dune 1.11.4.

The full solution will require refactoring the use of the foreign_archives field to be a function - at the moment there's a circular dependency because you can't determine the foreign_archives without scanning the directory and you can't scan the directory until you've built the super-context which involves calculating the foreign_archives field!

The workaround for now is to remove the .lib file from foreign_archives if the modules stanza is explicitly empty. This is obviously not ideal (although it does fix the stdlib-shims use case). To this end, I've added a note to implement a warning in the install rule if the library is found to have no modules but the modules stanza was not explicitly empty - the idea is that Dune will either warn that the rule is not portable or, for MSVC, fail with an error (because dune-package will contain incorrect information).

Note that the fix in stdlib-shims is constrained to < 4.10.0, so either this has to be fixed before OCaml 4.10 comes out, or the shim needs updating again.

@rgrinberg
Copy link
Member

Re-created in #2829

@rgrinberg rgrinberg closed this Oct 31, 2019
@dra27 dra27 deleted the empty-cmxa branch June 23, 2020 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dune fails to create an empty .cmxa library under Windows
2 participants