ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 401 forks source link

Cannot pass compilation flags to `jbuilder utop` #210

Closed jvillard closed 7 years ago

jvillard commented 7 years ago

I need to at least be able to pass flags to disable some fatal warnings 31, otherwise the compilation fails for my project:

      ocamlc infer/.utop/utop.bc (exit 2)
(cd _build/default && /home/jul/.opam/infer-4.04.2/bin/ocamlc.opt -w -40 -g -o infer/.utop/utop.bc -linkall -I /home/jul/.opam/infer-4.04.2/lib/ANSITerminal -I /home/jul/.opam/infer-4.04.2/lib/atd -I /home/jul/.opam/infer-4.04.2/lib/atdgen -I /home/jul/.opam/infer-4.04.2/lib/base -I /home/jul/.opam/infer-4.04.2/lib/base/caml -I /home/jul/.opam/infer-4.04.2/lib/base/shadow_stdlib -I /home/jul/.opam/infer-4.04.2/lib/bin_prot -I /home/jul/.opam/infer-4.04.2/lib/bin_prot/shape -I /home/jul/.opam/infer-4.04.2/lib/biniou -I /home/jul/.opam/infer-4.04.2/lib/bytes -I /home/jul/.opam/infer-4.04.2/lib/camlzip/../zip -I /home/jul/.opam/infer-4.04.2/lib/camomile -I /home/jul/.opam/infer-4.04.2/lib/cmdliner -I /home/jul/.opam/infer-4.04.2/lib/core -I /home/jul/.opam/infer-4.04.2/lib/core_kernel -I /home/jul/.opam/infer-4.04.2/lib/core_kernel/base_for_tests -I /home/jul/.opam/infer-4.04.2/lib/easy-format -I /home/jul/.opam/infer-4.04.2/lib/extlib -I /home/jul/.opam/infer-4.04.2/lib/fieldslib -I /home/jul/.opam/infer-4.04.2/lib/findlib -I /home/jul/.opam/infer-4.04.2/lib/jane-street-headers -I /home/jul/.opam/infer-4.04.2/lib/javalib -I /home/jul/.opam/infer-4.04.2/lib/lambda-term -I /home/jul/.opam/infer-4.04.2/lib/lwt -I /home/jul/.opam/infer-4.04.2/lib/lwt_react -I /home/jul/.opam/infer-4.04.2/lib/num -I /home/jul/.opam/infer-4.04.2/lib/oUnit -I /home/jul/.opam/infer-4.04.2/lib/ocaml -I /home/jul/.opam/infer-4.04.2/lib/ocaml/compiler-libs -I /home/jul/.opam/infer-4.04.2/lib/ocaml/threads -I /home/jul/.opam/infer-4.04.2/lib/parmap -I /home/jul/.opam/infer-4.04.2/lib/ppx_assert/runtime-lib -I /home/jul/.opam/infer-4.04.2/lib/ppx_bench/runtime-lib -I /home/jul/.opam/infer-4.04.2/lib/ppx_compare/runtime-lib -I /home/jul/.opam/infer-4.04.2/lib/ppx_expect/collector -I /home/jul/.opam/infer-4.04.2/lib/ppx_expect/common -I /home/jul/.opam/infer-4.04.2/lib/ppx_expect/config -I /home/jul/.opam/infer-4.04.2/lib/ppx_hash/runtime-lib -I /home/jul/.opam/infer-4.04.2/lib/ppx_inline_test/config -I /home/jul/.opam/infer-4.04.2/lib/ppx_inline_test/runtime-lib -I /home/jul/.opam/infer-4.04.2/lib/ptrees -I /home/jul/.opam/infer-4.04.2/lib/react -I /home/jul/.opam/infer-4.04.2/lib/result -I /home/jul/.opam/infer-4.04.2/lib/sawja -I /home/jul/.opam/infer-4.04.2/lib/sexplib -I /home/jul/.opam/infer-4.04.2/lib/sexplib/0 -I /home/jul/.opam/infer-4.04.2/lib/sexplib/unix -I /home/jul/.opam/infer-4.04.2/lib/spawn -I /home/jul/.opam/infer-4.04.2/lib/stdio -I /home/jul/.opam/infer-4.04.2/lib/typerep -I /home/jul/.opam/infer-4.04.2/lib/utop -I /home/jul/.opam/infer-4.04.2/lib/variantslib -I /home/jul/.opam/infer-4.04.2/lib/xmlm -I /home/jul/.opam/infer-4.04.2/lib/yojson -I /home/jul/.opam/infer-4.04.2/lib/zed -I /home/jul/.opam/infer-4.04.2/lib/zip -I infer /home/jul/.opam/infer-4.04.2/lib/ocaml/unix.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/bigarray.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/compiler-libs/ocamlcommon.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/compiler-libs/ocamlbytecomp.cma /home/jul/.opam/infer-4.04.2/lib/findlib/findlib.cma /home/jul/.opam/infer-4.04.2/lib/result/result.cma /home/jul/.opam/infer-4.04.2/lib/lwt/lwt.cma /home/jul/.opam/infer-4.04.2/lib/lwt/lwt-log.cma /home/jul/.opam/infer-4.04.2/lib/react/react.cma /home/jul/.opam/infer-4.04.2/lib/camomile/camomile.cma /home/jul/.opam/infer-4.04.2/lib/lwt/lwt-unix.cma /home/jul/.opam/infer-4.04.2/lib/lwt_react/lwt_react.cma /home/jul/.opam/infer-4.04.2/lib/zed/zed.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/threads/threads.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/compiler-libs/ocamltoplevel.cma /home/jul/.opam/infer-4.04.2/lib/findlib/findlib_top.cma /home/jul/.opam/infer-4.04.2/lib/lambda-term/lambda_term.cma /home/jul/.opam/infer-4.04.2/lib/utop/uTop.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/str.cma /home/jul/.opam/infer-4.04.2/lib/extlib/extLib.cma /home/jul/.opam/infer-4.04.2/lib/camlzip/../zip/zip.cma /home/jul/.opam/infer-4.04.2/lib/ptrees/ptrees.cma /home/jul/.opam/infer-4.04.2/lib/zip/zip.cma /home/jul/.opam/infer-4.04.2/lib/javalib/javalib.cma /home/jul/.opam/infer-4.04.2/lib/easy-format/easy_format.cmo /home/jul/.opam/infer-4.04.2/lib/biniou/biniou.cma /home/jul/.opam/infer-4.04.2/lib/atd/atd.cma /home/jul/.opam/infer-4.04.2/lib/yojson/yojson.cmo /home/jul/.opam/infer-4.04.2/lib/base/caml/caml.cma /home/jul/.opam/infer-4.04.2/lib/base/shadow_stdlib/shadow_stdlib.cma /home/jul/.opam/infer-4.04.2/lib/sexplib/0/sexplib0.cma /home/jul/.opam/infer-4.04.2/lib/base/base.cma /home/jul/.opam/infer-4.04.2/lib/fieldslib/fieldslib.cma /home/jul/.opam/infer-4.04.2/lib/ppx_compare/runtime-lib/ppx_compare_lib.cma /home/jul/.opam/infer-4.04.2/lib/sexplib/sexplib.cma /home/jul/.opam/infer-4.04.2/lib/variantslib/variantslib.cma /home/jul/.opam/infer-4.04.2/lib/bin_prot/shape/bin_shape_lib.cma /home/jul/.opam/infer-4.04.2/lib/ppx_inline_test/config/inline_test_config.cma /home/jul/.opam/infer-4.04.2/lib/ppx_hash/runtime-lib/ppx_hash_lib.cma /home/jul/.opam/infer-4.04.2/lib/ppx_inline_test/runtime-lib/ppx_inline_test_lib.cma /home/jul/.opam/infer-4.04.2/lib/ocaml/nums.cma /home/jul/.opam/infer-4.04.2/lib/ppx_expect/common/expect_test_common.cma /home/jul/.opam/infer-4.04.2/lib/ppx_expect/config/expect_test_config.cma /home/jul/.opam/infer-4.04.2/lib/bin_prot/bin_prot.cma /home/jul/.opam/infer-4.04.2/lib/core_kernel/base_for_tests/base_for_tests.cma /home/jul/.opam/infer-4.04.2/lib/jane-street-headers/jane_street_headers.cma /home/jul/.opam/infer-4.04.2/lib/ppx_assert/runtime-lib/ppx_assert_lib.cma /home/jul/.opam/infer-4.04.2/lib/ppx_bench/runtime-lib/ppx_bench_lib.cma /home/jul/.opam/infer-4.04.2/lib/ppx_expect/collector/expect_test_collector.cma /home/jul/.opam/infer-4.04.2/lib/stdio/stdio.cma /home/jul/.opam/infer-4.04.2/lib/typerep/typerep_lib.cma /home/jul/.opam/infer-4.04.2/lib/core_kernel/core_kernel.cma /home/jul/.opam/infer-4.04.2/lib/sexplib/unix/sexplib_unix.cma /home/jul/.opam/infer-4.04.2/lib/spawn/spawn.cma /home/jul/.opam/infer-4.04.2/lib/oUnit/oUnitAdvanced.cma /home/jul/.opam/infer-4.04.2/lib/sawja/sawja.cma /home/jul/.opam/infer-4.04.2/lib/ANSITerminal/ANSITerminal.cma /home/jul/.opam/infer-4.04.2/lib/atdgen/atdgen.cma /home/jul/.opam/infer-4.04.2/lib/cmdliner/cmdliner.cma /home/jul/.opam/infer-4.04.2/lib/core/core.cma /home/jul/.opam/infer-4.04.2/lib/oUnit/oUnit.cma /home/jul/.opam/infer-4.04.2/lib/parmap/parmap.cma /home/jul/.opam/infer-4.04.2/lib/xmlm/xmlm.cma infer/InferBaseStdlib.cma infer/InferGenerated.cma infer/InferModules.cma infer/.utop/utop.cmo)
File "/home/jul/.opam/infer-4.04.2/lib/extlib/extLib.cma(UChar)", line 1:
Warning 31: files /home/jul/.opam/infer-4.04.2/lib/extlib/extLib.cma(UChar) and /home/jul/.opam/infer-4.04.2/lib/camomile/camomile.cma(UChar) both define a module named UChar
File "/home/jul/.opam/infer-4.04.2/lib/extlib/extLib.cma(UTF8)", line 1:
Warning 31: files /home/jul/.opam/infer-4.04.2/lib/extlib/extLib.cma(UTF8) and /home/jul/.opam/infer-4.04.2/lib/camomile/camomile.cma(UTF8) both define a module named UTF8
File "/home/jul/.opam/infer-4.04.2/lib/zip/zip.cma(Zlib)", line 1:
Warning 31: files /home/jul/.opam/infer-4.04.2/lib/zip/zip.cma(Zlib) and /home/jul/.opam/infer-4.04.2/lib/camlzip/../zip/zip.cma(Zlib) both define a module named Zlib
File "/home/jul/.opam/infer-4.04.2/lib/zip/zip.cma(Zip)", line 1:
Warning 31: files /home/jul/.opam/infer-4.04.2/lib/zip/zip.cma(Zip) and /home/jul/.opam/infer-4.04.2/lib/camlzip/../zip/zip.cma(Zip) both define a module named Zip
File "/home/jul/.opam/infer-4.04.2/lib/zip/zip.cma(Gzip)", line 1:
Warning 31: files /home/jul/.opam/infer-4.04.2/lib/zip/zip.cma(Gzip) and /home/jul/.opam/infer-4.04.2/lib/camlzip/../zip/zip.cma(Gzip) both define a module named Gzip
File "_none_", line 1:
Error: Some fatal warnings were triggered (5 occurrences)
rgrinberg commented 7 years ago

Note that this issue also possibly exposes a bug in jbuilder's handling of the directory option in findlib.

Those zip.cma's that jbuilder is complaining about are in fact equivalent. camlzip is aliases to zip as we can see in the META:

https://github.com/xavierleroy/camlzip/blob/master/META-camlzip https://github.com/xavierleroy/camlzip/blob/master/META-zip

Although this could also be a bug in camlzip as it installs all of its artifacts twice. Into lib/camlzip and lib/zip.

dra27 commented 7 years ago

The camlzip behaviour is because for a long time camlzip didn't build with findlib and so people (= individuals and OS packagers, I think) created META files and some people used zip for the package and some people used camlzip!

rgrinberg commented 7 years ago

@dra27 Ouch :) . findlib seems doesn't seem to handle this either btw.

This fails as well:

ocamlfind ocamlopt -package camlzip,zip -linkall -linkpkg x.ml -w +31 -o x.opt

Perhaps this means that we should just fix camlzip. It seems like camlzip (or zip) should really be just an alias using requires = "..." then

ghost commented 7 years ago

Seems like these zip packages should indeed be fixed. However there is also a conflict between extlib and camomile. This is a bit unfortunate since camomile doesn't install the cmi files for UTF8 or Uchar, so they are only accessible through CamomileLibrary....

I didn't know you could link a byte-code executable with two toplevel modules of the same name. In the short term, maybe we should just pass -w -31 when building custom utops.

rgrinberg commented 7 years ago

Disabling the warning seems like a good workaround.

Are there any negative consequences possible to disabling this warning?

ghost commented 7 years ago

I did some experiments and when a module is linked twice and the interfaces don't match, it is an error. So we can't get a segfault, but we might get weird behaviors (duplicated global states, etc...).

Additionally, it seems that we only get the warning if both modules are pulled. For toplevels this will always be the case as we link with -linkall. This might explain why these errors go unnoticed.

So turning warning 31 into a non-fatal warning seems OK.

rgrinberg commented 7 years ago

I've made a PR for camlzip and the warning is no longer fatal. So this is now fixed.