ocaml / Zarith

The Zarith library implements arithmetic and logical operations over arbitrary-precision integers and rational numbers. The implementation, based on GMP, is very efficient.
Other
231 stars 70 forks source link

Setting `OCAMLFIND_DESTDIR` can mess with opam installation #136

Open Alizter opened 1 year ago

Alizter commented 1 year ago

I'm not sure if this is the correct place to report this, but when installing zarith via opam and OCAMLFIND_DESTDIR has been set (i.e. because of a Nix shell) then opam will inherit the env var which causes the build to fail. This can obviously be worked around by unsetting the env var, but it might be worth reporting it here with the workaround in case anybody else comes across the issue.

xavierleroy commented 1 year ago

From your description, it sounds like a problem that can affect all packages that use ocamlfind for installation, not just Zarith. Yet, a Web search finds only this occurrence in 2012: https://github.com/ocaml/opam/issues/164 . They claimed they "fixed" the issue by displaying a warning. Did you see a warning?

avsm commented 1 year ago

@Alizter what's the actual build failure you're seeing under Nix? It'll help diagnose the issue.

Alizter commented 1 year ago

Here is what opam spits out:

[ERROR] The installation of zarith failed at "make install".

#=== ERROR while installing zarith.1.12 =======================================#
# context     2.1.4 | linux/x86_64 | conf-gmp.4 | https://opam.ocaml.org#dd770689
# path        ~/.opam/conf-gmp.4/.opam-switch/build/zarith.1.12
# command     ~/.opam/opam-init/hooks/sandbox.sh install make install
# exit-code   2
# env-file    ~/.opam/log/zarith-599688-80a46f.env
# output-file ~/.opam/log/zarith-599688-80a46f.out
### output ###
# ocamlfind install -destdir "/home/ali/outputs/out/lib/ocaml/4.14.1/site-lib/" zarith META zarith.cma libzarith.a z.cmi q.cmi big_int_Z.cmi zarith_top.cma z.mli zarith.cmxa z.cmx q.cmx big_int_Z.cmx zarith.cmxs zarith.h q.mli big_int_Z.mli zarith.a z.cmti q.cmti big_int_Z.cmti -optional dllzarith.so
# ocamlfind: Bad configuration: Cannot mkdir /home/ali/outputs/out/lib/ocaml/4.14.1/site-lib/zarith because a path component does not exist or is not a directory
# make: *** [project.mak:115: install] Error 2

Something in Nix set OCAMLFIND_DESTDIR probably the Coq derivation. I have this value:

/home/ali/outputs/out/lib/ocaml/4.14.1/site-lib/

unsetting this env var lets the opam command succeed.

Here is the out file for the opam build:

ocamlfind install -destdir "/home/ali/outputs/out/lib/ocaml/4.14.1/site-lib/" zarith META zarith.cma libzarith.a z.cmi q.cmi big_int_Z.cmi zarith_top.cma z.mli zarith.cmxa z.cmx q.cmx big_int_Z.cmx zarith.cmxs zarith.h q.mli big_int_Z.mli zarith.a z.cmti q.cmti big_int_Z.cmti -optional dllzarith.so
ocamlfind: Bad configuration: Cannot mkdir /home/ali/outputs/out/lib/ocaml/4.14.1/site-lib/zarith because a path component does not exist or is not a directory
make: *** [project.mak:115: install] Error 2
Alizter commented 1 year ago

This issue is not super cirtical for me since I am doing something very nonstandard. Normal users will never touch that env var. I was attempting to quickly set up some opam switches for testing the interaction of opam and Dune. When I actually need different versions of packages I just use Nix anyway.

rounakdatta commented 11 months ago

unsetting this env var lets the opam command succeed. Thank you!! I've been trying to install ppx_jane under a nix develop environment, and came across this thorny issue. Unsetting the variable indeed solved the issue for me.