Skip to content

Dune should warn about dependencies on unused libraries #650

Closed
ocaml/opam-repository
#29216

Description

@dra27

It's still quite commonplace to end up with (libraries (... bytes ...)) even though using Dune implies OCaml >= 4.02.3.

It would be better if Dune dropped the dependency and issued a warning (especially now that we don't depend on findlib, requiring a dependency on base-bytes in opam-repsository).

EDIT: It would be better if we had such a warning for all libraries in fact. This should be possible via ocamlobjinfo.

Activity

  1. dra27 commented on Mar 23, 2018

    @dra27
    MemberAuthor

    @diml - do we, or are we, ever intending to support OCaml < 4.02.3 in build contexts?

  2. rgrinberg commented on Mar 23, 2018

    @rgrinberg
    Member

    I'm also -1 for supporting older OCaml's. It's a feature that gets more and more irrelevant by the day. I'd rather we spend the time supporting new OCaml features ;)

  3. pbiggar commented on Sep 11, 2018

    @pbiggar

    I had a recent issue where we depended on a lot of libraries we didn't need, and it led to output-size and compilation-time problems. It would certainly be wonderful for dune to have a warning for unused dependencies!

  4. rgrinberg commented on Sep 11, 2018

    @rgrinberg
    Member

    I'm surprised that it made a difference to output sizes, as ocaml should have not linked in any unused libraries (unless you passed in -linkall).

    As for compilation speed, we're working on it #430

  5. pbiggar commented on Sep 11, 2018

    @pbiggar

    I definitely observed the change in the output binaries in native mode. However, the major change was js_of_ocaml output size. Here's the discussion where I discovered it, including the jbuild files: https://discuss.ocaml.org/t/reducing-the-size-of-js-of-ocaml-output/2538. (Let me know if I should move this to a different issue; didnt intend to hijack).

  6. rgrinberg commented on Sep 11, 2018

    @rgrinberg
    Member

    Which unused libraries did you remove that decreased the output size? From what I can tell you simply switches to smaller libs and got rid of code generators that whose generated code you weren't actually using.

  7. pbiggar commented on Sep 11, 2018

    @pbiggar

    While I did remove some derivers whose output I wasn't using, the big change I got was when I was told that ppx_deriving_yojson should not go in the library section. Apparently, it was compiling it, and also all it's dependencies. I continued to use ppx_deriving_yojson generated code, but I stopped compiling it into the binary. For my jsoo output, it reduced it by about 1.7MB, with no change in functionality.

    So the warning I would hope for is to say "you are naming ppx_deriving_yojson in your library stanza, but you are not using it`.

  8. rgrinberg commented on Sep 12, 2018

    @rgrinberg
    Member

    Ah, that's because ppx_deriving_yojson probably forces -linkall. Anyway, dune doesn't have a way of detecting such cases unfortunately. We might gain this ability once we improve the description of libraries. So that we'd be able to tell that we're using a ppx_rewriter in libraries position.

  9. changed the title [-]Dune should warn about dependency on bytes when not needed[/-] [+]Dune should warn about dependencies on libraries when not needed[/+] on Dec 11, 2018
  10. changed the title [-]Dune should warn about dependencies on libraries when not needed[/-] [+]Dune should warn about dependencies on unused libraries[/+] on Dec 11, 2018
  11. added
    build
    and removed on Jan 28, 2025
  12. dra27 commented on Nov 16, 2025

    @dra27
    MemberAuthor

    Thanks, @rgrinberg!

  13. added a commit that references this issue on Dec 15, 2025
    7d6af52
  14. added 2 commits that reference this issue on Jan 5, 2026
    6caba29
    001b427
  15. added a commit that references this issue on Feb 11, 2026
    92f9a68
  16. added theissue type on Jun 5, 2026
  17. added this to the 3.21.0 milestone on Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    build

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions