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

exposing the mt predicate to dune libraries #1724

Closed
avsm opened this issue Dec 31, 2018 · 9 comments
Closed

exposing the mt predicate to dune libraries #1724

avsm opened this issue Dec 31, 2018 · 9 comments

Comments

@avsm
Copy link
Member

avsm commented Dec 31, 2018

The ctypes port to dune (yallop/ocaml-ctypes#588) is almost working, except for the need to select which subpackage to link based on the -mt predicate in ocamlfind. #96 has some discussion of this, but the specific META file in ctypes is:

package "foreign" (
 version = "0.14.0"
 description = "Dynamic linking of C functions"
 requires(-mt) = "ctypes.foreign.unthreaded"
 requires(mt) = "ctypes.foreign.threaded"

Both the unthreaded and threaded variants have different c stubs, and cannot be linked simultaneously without a module clash. I'm not sure how to make this work without some support for mt in a dune file, as the right package is selected based on whether the executable uses the threads library or not.

Suggestions for workarounds welcome to unblock the ctypes port...

avsm added a commit to rgrinberg/ocaml-ctypes that referenced this issue Dec 31, 2018
until ocaml/dune#1724 is resolved

Signed-off-by: Anil Madhavapeddy <[email protected]>
avsm added a commit to rgrinberg/ocaml-ctypes that referenced this issue Dec 31, 2018
this lets an example build, but with an extra dependency
since dune cannot track the `mt` predicates and hence doesnt
know that the `date` example depends on ctypes-foreign-unthreaded

see ocaml/dune#1724 for discussion
@avsm
Copy link
Member Author

avsm commented Dec 31, 2018

I've pushed a workaround using META templates to yallop/ocaml-ctypes@a5a9655. The problem I'm finding is when linking an executable there are now missing dependencies, since Dune has no idea about the extra dependencies introduced by the manually written requires fields that use the -mt predicates.

This means that as a hack one of the choices is manually written in each executable at the moment; e.g.:

(executables
 (names date)
 (libraries ctypes-foreign ctypes-foreign.unthreaded))

instead of

(executables
 (names date)
 (libraries ctypes-foreign))

@bobot
Copy link
Collaborator

bobot commented Dec 31, 2018

Currently dune support the mt predicate by always supposing that the mt predicate is true. So currently the unthreaded version doesn't make sense with dune.

avsm added a commit to avsm/ocaml-ctypes that referenced this issue Jan 1, 2019
This is the default as supported by dune, so it's a sensible
hard-coded one until the conversation in ocaml/dune#1724
is resolved.
@avsm
Copy link
Member Author

avsm commented Jan 1, 2019

Thanks @bobot -- I've hardcoded the mt version in the ongoing port of ctypes for now.

@avsm
Copy link
Member Author

avsm commented Jan 1, 2019

One observation from yallop/ocaml-ctypes@25ec72a (which shifts the use of ctypes-foreign.threaded/unthreaded to use virtual modules) is that the mt predicate seems like another special case for link-time tag selection of virtual modules.

If we decide on a namespace for virtual modules that is consistent (e.g. foo.threaded, foo.unthreaded, foo.jsoo, foo.mirage-xen, foo.mirage-freestanding), then the relevant subpackages could all be selected by a link-time specification in dune rather than have to be manually specified. This is roughly what the predicate system in ocamlfind does currently.

@ghost
Copy link

ghost commented Jan 7, 2019

@avsm that's the idea of library variants, i.e. the part that comes after virtual library: adding a mechanism to automatically select an implementation when none is specified.

@avsm
Copy link
Member Author

avsm commented Jan 7, 2019

@diml indeed -- I just want to make sure that selecting a subpackage name in today's virtual libraries is sufficient for future compatibility with library variants. It would be quite a pain to rename releases that use virtual libraries with dune 1.7.0 otherwise

@rgrinberg
Copy link
Member

So would having a threads variant going to be sufficient for you here? Do you also need a "default" variant tag if none are specified? For example, the user is creating an executable that uses ctypes.foreign and hasn't specified in the library.

I think variants is a good solution for this as well, but it's a bit weird how we want the use of (one of) the threads to enable this tag.

@rgrinberg
Copy link
Member

@emillon Since you're driving the ctypes port, is this still relevant?

@emillon
Copy link
Collaborator

emillon commented May 16, 2022

The whole threaded/unthreaded distinction got removed upstream in yallop/ocaml-ctypes#651, so I don't think it's relevant anymore.

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

No branches or pull requests

4 participants