Allow optional libraries without explicit use
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 1.9k
- Forks
- 500
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 277
Description
Desired Behavior
In Liquidsoap, optional features are historically registered via a global hash, typically:
root.ml
let registered_features = Hashtbl.create 10
optional_feature.ml
let () =
Hashtbl.add Root.registered_features optional_feature
This means that, in order to compile optional features, we just need to pass the corresponding module to the linker.
In the process of migrating to dune, our approach so far has been to define a main library, an optional library and use them to build the final executable:
(library
(name root)
(modules root))
(library
(name optional_feature)
(libraries some-dependency)
(optional)
(modules optional_feature))
However, in order to make sure that the optional module is linked we have to do a couple of annoying tricks:
(executable
(name application)
(modules application)
(link_flags -linkall)
(libraries
root
(select
noop.ml
from
(optional_feature -> noop.dep.ml)
(-> noop.dep.ml))))
Here we:
- Force all modules to be linked
- Use an empty
noop.mlfile to take advantage of alternative dependencies.
Is there an existing better way to do this? Alternatively, could it be possible for dune to support linking an optional library without having to specify a file using it?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the issue's root.ml, optional_feature.ml, noop.ml, and executable Dune snippets to understand the current linking workaround. Then inspect how optional libraries and -linkall are handled in Dune. Done means establishing whether a supported configuration already exists or defining and validating the requested way to link an optional library without an explicit file dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100