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

dune install wants opam or --prefix #5455

Closed
jamesjer opened this issue Feb 18, 2022 · 15 comments · Fixed by #5516
Closed

dune install wants opam or --prefix #5455

jamesjer opened this issue Feb 18, 2022 · 15 comments · Fixed by #5516
Assignees
Labels
Milestone

Comments

@jamesjer
Copy link
Contributor

Expected Behavior

With dune 2.x, we could run "dune install --destdir=" when building Fedora packages with dune, and that would populate our buildroot as expected.

Actual Behavior

With dune 3.0.2, the same dune invocation results in this error:

Error: Program opam not found in the tree or in PATH

That is not helpful when we are trying to build the dependencies of opam. I have found that if I add --prefix=/usr, then dune stops asking for opam ... but it installs the library files into the wrong directory. We configured dune with --libdir, but that setting is ignored if the prefix is given. So now I have to pass both --prefix and --libdir to dune install, even though dune should already know the correct libdir.

Reproduction

  1. Build any project with dune
  2. Ensure that opam is not in PATH
  3. Make an install directory, say /tmp/dune-root
  4. Run "dune install --destdir=/tmp/dune-root"

Specifications

  • Version of dune (output of dune --version): n/a <-- That is the actual output of dune --version. It is really 3.0.2.
  • Version of ocaml (output of ocamlc --version): 4.13.1
  • Operating system (distribution and version): Fedora Rawhide

Additional information

@rwmjones
Copy link

I'm not even sure why dune would run opam at all.

@bobot bobot self-assigned this Feb 21, 2022
@bobot
Copy link
Collaborator

bobot commented Feb 21, 2022

even though dune should already know the correct libdir.

Do you mean because it is given during the compilation of dune with ocaml configure --libdir <path> ?

I think the main problem is this configuration command doesn't allow to give a default --prefix so opam is used to get it, or we don't allow to give a default for all the path (e.g share). However if --prefixis set and not libdir, the configured libdir is not used. I think it is normal. When you change the prefix everything is changed.

Just to check before writing a fix do you prefer one option during the configuration of dune for each of the root directories? (e.g also one for libexec_root)? If they are all set prefix would not be needed .

(destdir in this code snippet is applied with prefix)

(* FIXME: we should handle all directories uniformly, instead of
special-casing etcdir, mandir, and docdir as of today [which was done for
convenience of backporting] *)
let make ~package ~destdir ?(libdir = Path.relative destdir "lib")
?(mandir = Path.relative destdir "man")
?(docdir = Path.relative destdir "doc")
?(etcdir = Path.relative destdir "etc") () =
let package = Package.Name.to_string package in
let lib_root = libdir in
let libexec_root = libdir in
let share_root = Path.relative destdir "share" in
let etc_root = etcdir in
let doc_root = docdir in
{ lib_root
; libexec_root
; share_root
; bin = Path.relative destdir "bin"
; sbin = Path.relative destdir "sbin"
; man = mandir
; toplevel = Path.relative libdir "toplevel"
; stublibs = Path.relative libdir "stublibs"
; lib = Path.relative lib_root package
; libexec = Path.relative libexec_root package
; share = Path.relative share_root package
; etc = Path.relative etc_root package
; doc = Path.relative doc_root package
}

CC @ejgallego

@jamesjer
Copy link
Contributor Author

Do you mean because it is given during the compilation of dune with ocaml configure --libdir <path> ?

Yes, that is what I mean.

I think the main problem is this configuration command doesn't allow to give a default --prefix so opam is used to get it, or we don't allow to give a default for all the path (e.g share). However if --prefixis set and not libdir, the configured libdir is not used. I think it is normal. When you change the prefix everything is changed.

Sure, that makes sense. In that case, we would like to set the default prefix along with the libdir.

Just to check before writing a fix do you prefer one option during the configuration of dune for each of the root directories? (e.g also one for libexec_root)? If they are all set prefix would not be needed .

Actually, the other defaults are all fine for us. We just need to special case libdir. We can work with setting a default prefix, or with setting all of the directories individually. Either is fine. Thank you for looking at this issue.

@kit-ty-kate
Copy link
Member

I’m not sure why the opam binary is used to get the prefix either. Why is the OPAM_SWITCH_PREFIX environment variable not used instead?

@bobot
Copy link
Collaborator

bobot commented Mar 7, 2022

Is there cases when one way will work and not the other? If OPAM_SWITCH_PREFIX is not present, opam binary could work. Is there symmetric cases?

@silene
Copy link

silene commented Mar 7, 2022

If OPAM_SWITCH_PREFIX is not present, opam binary could work.

But just because opam happens to be installed on the system does not mean that it should be used to decide on an installation location. If OPAM_SWITCH_PREFIX is not defined, calling opam looks like a bug to me.

@bobot
Copy link
Collaborator

bobot commented Mar 9, 2022

Ok OPAM_SWITH_PREFIX must be used (in fact it is already the case during build).

So the priority:

  • Use the command line options
  • Use information given during configuration of dune
  • Otherwise use OPAM_SWITCH_PREFIX to get the information.
  • Otherwise fails with an error

During build ocamlc -config is used for the configuration in particular OCAMLPATH, but I prefer not to use it for finding the prefix.

Still I don't understand why in mirage/ocaml-tar#85 and #5488 , opam var prefix fails inside opam execution but we will look at the problem in #5488.

@bobot
Copy link
Collaborator

bobot commented Mar 10, 2022

@jamesjer at the end, when everything is added and fixed in dune, it seems needed to give the full list of the directory to both the ./configure of dune and to dune install. Correct me if I'm wrong but:

  • The dune package must be usable by the users to install libraries in /usr/local, so we need at least ./configure --libdir /usr/local/lib/ocaml --libdir /usr/lib/ocaml --mandir /usr/local/share/man --docdir /usr/local/share/doc ... . The option --libdir appears twice in order to indicate the installation directory and another directory for the lookup.
  • Other packages compiled with dune must be installed in /usr, so we need dune install --destdir=.. --libdir /usr/lib/ocaml --mandir /usr/share/man --docdir /usr/share/doc ...

@jamesjer
Copy link
Contributor Author

My personal preference is to use the values passed to configure as defaults. That is, if I run ./configure --prefix=/usr, then dune defaults to installing into /usr; i.e., plain dune install can be invoked and do something useful. A user can still install elsewhere by passing --prefix, --libdir, etc. on the command line.

@phated
Copy link

phated commented Mar 11, 2022

fwiw, an esy sandbox also doesn't have the opam command and any dune install in a package fails on dune 3.

@bobot
Copy link
Collaborator

bobot commented Mar 11, 2022

The value given to configure will be used as default. I just though that you preferred that user can do simply sudo dune install and have the files installed in /usr/local and not in /usr/. But the choice of defaults is yours and will be used.

bobot added a commit to bobot/jbuilder that referenced this issue Mar 11, 2022
        - Fix ocaml#5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
@bobot
Copy link
Collaborator

bobot commented Mar 11, 2022

@phated thank you for the report, #5516 should also fix esy. But where does esy install files and how does it customize the directories?

bobot added a commit to bobot/jbuilder that referenced this issue Mar 11, 2022
        - Fix ocaml#5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
bobot added a commit to bobot/jbuilder that referenced this issue Mar 11, 2022
        - Fix ocaml#5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
@EduardoRFS
Copy link
Contributor

@bobot esy installs it at $cur__install on the environment, but normally we just use esy-installer something.install which will read the install file and put everything in the right place.

bobot added a commit to bobot/jbuilder that referenced this issue Apr 3, 2022
        - Fix ocaml#5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
vapourismo added a commit to vapourismo/dune that referenced this issue Apr 17, 2022
With `dune install` you must either provide the installation `--prefix`
or have `opam` installed. Unfortunately in some cases neither is an
option because we're in a non-Opam environment (e.g. Nix) and don't
control the invocation of Dune.

Providing an environment variable `DUNE_INSTALL_PREFIX` may alleviate
that pain.

Might help some suffering from ocaml#5455.

Signed-off-by: Ole Krüger <[email protected]>
rgrinberg pushed a commit that referenced this issue Apr 21, 2022
With `dune install` you must either provide the installation `--prefix`
or have `opam` installed. Unfortunately in some cases neither is an
option because we're in a non-Opam environment (e.g. Nix) and don't
control the invocation of Dune.

Providing an environment variable `DUNE_INSTALL_PREFIX` may alleviate
that pain.

Might help some suffering from #5455.

Signed-off-by: Ole Krüger <[email protected]>

ps-id: 2D3AA66B-4717-45EE-884B-F22F9D6008C8
@yawaramin
Copy link
Contributor

Shouldn't this be labelled bug? Dune should definitely not depend on opam, right?

@rgrinberg rgrinberg added the bug label May 2, 2022
@rgrinberg rgrinberg added this to the 3.2.0 milestone May 2, 2022
@rgrinberg
Copy link
Member

Indeed. It's properly labelled now.

bobot added a commit to bobot/jbuilder that referenced this issue May 2, 2022
        - Fix ocaml#5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
bobot added a commit to bobot/jbuilder that referenced this issue May 2, 2022
        - Fix ocaml#5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
bobot added a commit that referenced this issue May 3, 2022
        - Fix #5455
        - Installation can fail if OPAM_SWITCH_PREFIX is not present,
          ./configure has not been fully populated, and the missing directories
          are not given on the command line

Signed-off-by: François Bobot <[email protected]>
rgrinberg added a commit to rgrinberg/opam-repository that referenced this issue May 17, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.2.0)

CHANGES:

- Fixed ``dune describe workspace --with-deps`` so that it correctly
  handles Reason files, as well as files any other dialect. (ocaml/dune#5701, @esope)

- Disable alerts when compiling code in vendored directories (ocaml/dune#5683,
  @NathanReb)

- Fixed ``dune describe --with-deps``, that crashed when some
  preprocessing was required in a dune file using ``per_module``.
  (ocaml/dune#5682, fixes ocaml/dune#5680, @esope)

- Add `$ dune describe pp` to print the preprocssed ast of sources. (ocaml/dune#5615,
  fixes ocaml/dune#4470, @cannorin)

- Report dune file evaluation errors concurrently. In the same way we report
  build errors. (ocaml/dune#5655, @rgrinberg)

- Watch mode now default to clearing the terminal on rebuild (ocaml/dune#5636, fixes,
  ocaml/dune#5216, @rgrinberg)

- The output of jobs that finished but were cancelled is now omitted. (ocaml/dune#5631,
  fixes ocaml/dune#5482, @rgrinberg)

- Allows to configure all the default destination directories with `./configure`
  (adds `bin`, `sbin`, `data`, `libexec`). Use `OPAM_SWITCH_PREFIX` instead of
  calling the `opam` binaries in `dune install`. Fix handling of multiple
  `libdir` in `./configure` for handling `/usr/lib/ocaml/` and
  `/usr/local/lib/ocaml`. In `dune install` forbid relative directories in
  `libdir`, `docdir` and others specific directory setting because their handling
  was inconsistent (ocaml/dune#5516, fixes ocaml/dune#3978 and ocaml/dune#5455, @bobot)

- `--terminal-persistence=clear-on-rebuild` will no longer destroy scrollback
  on some terminals (ocaml/dune#5646, @rgrinberg)

- Add a fmt command as a shortcut of `dune build @fmt --auto-promote` (ocaml/dune#5574,
  @tmattio)

- Watch mode now tracks copied external files, external directories for
  dependencies, dune files in OCaml syntax, files used by `include` stanzas,
  dune-project, opam files, libraries builtin with compiler, and foreign
  sources (ocaml/dune#5627, ocaml/dune#5645, ocaml/dune#5652, ocaml/dune#5656, ocaml/dune#5672, ocaml/dune#5691, ocaml/dune#5722, fixes ocaml/dune#5331,
  @rgrinberg)

- Improve metrics for cram tests. Include test names in the event and add a
  category for cram tests (ocaml/dune#5626, @rgrinberg)

- Allow specifying multiple licenses in project file (ocaml/dune#5579, fixes ocaml/dune#5574,
  @liyishuai)

- Match `glob_files` only against files in external directories (ocaml/dune#5614, fixes
  ocaml/dune#5540, @rgrinberg)

- Add pid's to chrome trace output (ocaml/dune#5617, @rgrinberg)

- Fix race when creating local cache directory (ocaml/dune#5613, fixes ocaml/dune#5461, @rgrinberg)

- Add `not` to boolean expressions (ocaml/dune#5610, fix ocaml/dune#5503, @rgrinberg)

- Fix relative dependencies outside the workspace (ocaml/dune#4035, fixes ocaml/dune#5572, @bobot)

- Allow to specify `--prefix` via the environment variable
  `DUNE_INSTALL_PREFIX` (ocaml/dune#5589, @vapourismo)

- Dune-site.plugin: add support for `archive(native|byte, plugin)` used in the
  wild before findlib documented `plugin(native|byte)` in 2015 (ocaml/dune#5518, @bobot)

- Fix a bug where Dune would not correctly interpret `META` files in alternative
  layout (ie when the META file is named `META.$pkg`). The `Llvm` bindings were
  affected by this issue. (ocaml/dune#5619, fixes ocaml/dune#5616, @nojb)

- Support `(binaries)` in `(env)` in dune-workspace files (ocaml/dune#5560, fix ocaml/dune#5555,
  @emillon)

- (mdx) stanza: add support for (locks). (ocaml/dune#5628, fixes ocaml/dune#5489, @emillon)

- (mdx) stanza: support including files in different directories using relative
  paths, and provide better error messages when paths are invalid (ocaml/dune#5703, ocaml/dune#5704,
  fixes ocaml/dune#5596, @emillon)

- Fix ctypes rules for external lib names which aren't valid ocaml names
  (ocaml/dune#5667, fixes ocaml/dune#5511, @Khady)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
9 participants