ocamlfind
ocamlfind copied to clipboard
Disable various parts of -thread handling for 5.x
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 https://github.com/ocaml/ocaml/pull/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)