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 the build for 4.02-4.04 on macOS and for 4.02-4.10 with MSVC on Windows #8

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Jul 25, 2022

I recently discovered that one can correctly trick Dune into creating empty libraries for some versions of OCaml, which allows the removal of the dynamic dune file. This PR then changes the build to be an empty library for OCaml 4.13 and earlier. This was originally considered in #5, but it breaks the build on MSVC prior to 4.11, so instead an empty library was only built for OCaml 4.07 to limit the damage to 4.02-4.07 on MSVC. It turns out the damage included in 4.02-4.04 on macOS.

The solution proposed here is that for the offending versions of OCaml (that's 4.02-4.04 on macOS and 4.02-4.10 with MSVC on Windows), an empty module CamlinternalCamlp_streams is added to the library which works around the linker problems.

A solution such as this was considered for the same problem in stdlib-shims, however it was rejected there because this issue affects the current versions of OCaml (the solution adopted in stdlib-shims was to fix OCaml itself). I think it's OK to use this trick here because we know that there was no CamlinternalCamlp_streams module in 4.02-4.10 and programs and libraries are not supposed to use names beginning Camlinternal. Most importantly, the number of releases in which this trick is used is fixed, unlike in stdlib-shims.

Dune doesn't allow the modules list itself to be filtered, but it is
possible to control the meaning of :standard by using (enabled_if ..)
to assemble only the desired .ml and .mli in the build directory.
Code is now in src/ with nefarious trickery reserved for the dune file
only.
Since these are only passed to OCaml 4.14+, we can take advantage of the
clearer symbolic names.
ocamlopt on these versions of OCaml cannot create .cmxa files with no
modules. On these versions, create a dummy CamlinternalCamlp_streams
module whose name will be assumed never to clash as it uses the
compiler's reserved prefix.
@dra27
Copy link
Member Author

dra27 commented Jul 25, 2022

I can confirm that this is working on MSVC 4.06-4.14 with only 4.06-4.10 having the dummy module in camlp_streams.cmxa. I'll double-check the macOS ones tomorrow when I'm near my old Macbook. It's also tested on macOS for 4.02-4.04.

@tatchi
Copy link

tatchi commented Jul 28, 2022

Thanks for the fix @dra27, I confirm that it resolves the build failure on omd 😁

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.

Installation fails with ar: no archive members specifiedon MacOS with OCaml 4.04.2
2 participants