Skip to content

Add support for DUNE_ROOT environment variable #12399

@sir4ur0n

Description

@sir4ur0n

Desired Behavior

Please add support for a generic DUNE_ROOT env var, similar to passing --root in the command line.

Rationale

Sometimes Dune guesses wrong the root.
E.g.:

| a/
    |- dune-workspace
    |- b/
        |- dune-workspace

If I am in directory b/ and run dune build, it uses as root directory a/, and I have to instead use dune build --root . every time to work around that.

There are various reasons why one may not want to use the parent directory as root, like:

  • if a/dune (or another dune file in a/) is invalid/broken, running dune build in b/ will fail, while running dune build --root=. will succeed
  • evaluating all dune files in a/ might be slow, thus unnecessarily slowing building b/
  • it can mess paths, e.g. we have a Makefile in b/ which refers to _build/<whatever>. Running make foo in b/ will use different paths thus fail or have a wrong behavior

About supporting the env var in particular, it is because it is MUCH more convenient than passing a CLI parameter every time. Env vars can be set once and all subsequent commands will use it, and they interact nicely with many tools (e.g. nix-shell). Comparatively, it is rarely convenient or even possible to pass extra CLI parameters via other tools.

Note: my examples are about dune build but any dune command supporting --root should also support DUNE_ROOT env var.

Metadata

Metadata

Assignees

No one assigned

    Labels

    configEverything related to dune configuration (workspace, project, dune, env)feature-requestUser wanted features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions