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

Disable various parts of -thread handling for 5.x #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Mar 28, 2024

Implements a fix for an issue reported in Discuss.

The original example, given a.ml:

let x = Thread.self ()

is that this command (despite being incorrect) works in 3.x/4.x:

$ ocamlfind ocamlopt -I +unix -I +threads -package threads -linkpkg unix.cmxa threads.cmxa a.ml
ocamlfind: [WARNING] Package `threads': Linking problems may arise because of the missing -thread or -vmthread switch

but in 5.x:

$ ocamlfind ocamlopt -I +unix -I +threads -package threads -linkpkg unix.cmxa threads.cmxa a.ml
File "a.ml", line 1:
Error: Cannot find file /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/threads.cmxa

This command isn't directly fixable, as the fix to ensure that threads.cmxa is linked from /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/threads/threads.cmxa will then result in double-linking.

However, if we consider the correct invocation, which for ocamlfind should always involve -thread to set ocamlfind's machinery into the correct mode:

$ ocamlfind ocamlopt -package threads -linkpkg -thread a.ml -verbose
Effective set of compiler predicates: pkg_unix,pkg_threads,autolink,mt,mt_posix,native
+ ocamlopt.opt -verbose -thread -I /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/unix /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/unix/unix.cmxa /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/threads/threads.cmxa a.ml

In 5.x, this is linking without warning, but the invocation is incorrect as it's relying on the deprecated in ocamlopt -thread option and effectively ignoring the META file for threads shipped with OCaml 5.

With this PR, that then becomes:

Effective set of compiler predicates: pkg_unix,pkg_threads,autolink,mt,mt_posix,native
+ ocamlopt.opt -verbose -I /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/unix -I /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/threads /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/unix/unix.cmxa /home/dra/.opam/fix-threads-5.1.1/lib/ocaml/threads/threads.cmxa a.ml

and we can see the correct set of predicates, combined with standard -I and .cmxa parameters for packages. The command works with or without the -thread argument to ocamlfind, the flag now controls whether the mt and mt_posix predicates are true. My recollection when preparing ocaml/ocaml#11007 was that the mt and mt_posix predicates were not used outside of findlib itself (i.e. that there are not (m)any third-party META files which uses these two predciates)

OCaml 5.x installs its own META files, requiring no special support from
ocamlfind itself.
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.

None yet

1 participant