ocaml / dune

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

melange: crash when using ppx in melange library #7020

Closed eWert-Online closed 1 year ago

eWert-Online commented 1 year ago

Expected Behavior

I would like to use a ppx like ppx_deriving or ppx_yojson_conv in a melange library or be notified, that using ppx's is currently not possible.

Actual Behavior

dune crashes with the "I must not crash. Uncertainty is the mind-killer ..." message

Reproduction

A repository with an opam setup to reproduce the issue can be found here: https://github.com/ewert-online/melange-dune-test

  1. Add a dune library with the following contents:
    (library
    (name shared)
    (modes melange)
    (preprocess
     (pps ppx_deriving.make)))
  2. Use this library in a melange.emit stanza
    (melange.emit
    (target es6)
    (alias melange)
    (libraries shared)
    (module_system es6))
  3. Run dune build @melange

Specifications

Additional information

output of dune build @melange --verbose:

Click to expand... ``` Shared cache: disabled Workspace root: /Users/ewert/Documents/Projekte/melange-dune-test Auto-detected concurrency: 8 Running[0]: /Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin/ocamlc.opt -config > /var/folders/2p/nbzvd_q158gc1f9t74cpg79w0000gn/T/dune_ece0a0_output Dune context: { name = "default" ; kind = "default" ; profile = Dev ; merlin = true ; for_host = None ; fdo_target_exe = None ; build_dir = In_build_dir "default" ; toplevel_path = Some External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/lib/toplevel" ; ocaml_bin = External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin" ; ocaml = Ok External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin/ocaml" ; ocamlc = External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin/ocamlc.opt" ; ocamlopt = Ok External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin/ocamlopt.opt" ; ocamldep = Ok External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin/ocamldep.opt" ; ocamlmklib = Ok External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/bin/ocamlmklib.opt" ; env = map { "DUNE_OCAML_HARDCODED" : "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/lib" ; "DUNE_OCAML_STDLIB" : "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/lib/ocaml" ; "DUNE_SOURCEROOT" : "/Users/ewert/Documents/Projekte/melange-dune-test" ; "INSIDE_DUNE" : "/Users/ewert/Documents/Projekte/melange-dune-test/_build/default" ; "MANPATH" : "/Users/ewert/Documents/Projekte/melange-dune-test/_build/install/default/bin" ; "OCAMLFIND_IGNORE_DUPS_IN" : "/Users/ewert/Documents/Projekte/melange-dune-test/_build/install/default/lib" ; "OCAMLPATH" : "/Users/ewert/Documents/Projekte/melange-dune-test/_build/install/default/lib" ; "OCAMLTOP_INCLUDE_PATH" : "/Users/ewert/Documents/Projekte/melange-dune-test/_build/install/default/lib/toplevel" ; "OCAML_COLOR" : "always" ; "OPAMCOLOR" : "always" } ; findlib_paths = [ External "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/lib" ] ; arch_sixtyfour = true ; natdynlink_supported = true ; supports_shared_libraries = true ; ocaml_config = { version = "4.14.1" ; standard_library_default = "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/lib/ocaml" ; standard_library = "/Users/ewert/Documents/Projekte/melange-dune-test/_opam/lib/ocaml" ; standard_runtime = "the_standard_runtime_variable_was_deleted" ; ccomp_type = "cc" ; c_compiler = "cc" ; ocamlc_cflags = [ "-O2"; "-fno-strict-aliasing"; "-fwrapv"; "-pthread" ] ; ocamlc_cppflags = [ "-D_FILE_OFFSET_BITS=64" ] ; ocamlopt_cflags = [ "-O2"; "-fno-strict-aliasing"; "-fwrapv"; "-pthread" ] ; ocamlopt_cppflags = [ "-D_FILE_OFFSET_BITS=64" ] ; bytecomp_c_compiler = [ "cc" ; "-O2" ; "-fno-strict-aliasing" ; "-fwrapv" ; "-pthread" ; "-D_FILE_OFFSET_BITS=64" ] ; bytecomp_c_libraries = [ "-lm"; "-lpthread" ] ; native_c_compiler = [ "cc" ; "-O2" ; "-fno-strict-aliasing" ; "-fwrapv" ; "-pthread" ; "-D_FILE_OFFSET_BITS=64" ] ; native_c_libraries = [ "-lm" ] ; native_pack_linker = [ "ld"; "-r"; "-o" ] ; cc_profile = [] ; architecture = "amd64" ; model = "default" ; int_size = 63 ; word_size = 64 ; system = "macosx" ; asm = [ "cc"; "-c"; "-Wno-trigraphs" ] ; asm_cfi_supported = true ; with_frame_pointers = false ; ext_exe = "" ; ext_obj = ".o" ; ext_asm = ".s" ; ext_lib = ".a" ; ext_dll = ".so" ; os_type = "Unix" ; default_executable_name = "a.out" ; systhread_supported = true ; host = "x86_64-apple-darwin22.1.0" ; target = "x86_64-apple-darwin22.1.0" ; profiling = false ; flambda = false ; spacetime = false ; safe_string = true ; exec_magic_number = "Caml1999X031" ; cmi_magic_number = "Caml1999I031" ; cmo_magic_number = "Caml1999O031" ; cma_magic_number = "Caml1999A031" ; cmx_magic_number = "Caml1999Y031" ; cmxa_magic_number = "Caml1999Z031" ; ast_impl_magic_number = "Caml1999M031" ; ast_intf_magic_number = "Caml1999N031" ; cmxs_magic_number = "Caml1999D031" ; cmt_magic_number = "Caml1999T031" ; natdynlink_supported = true ; supports_shared_libraries = true ; windows_unicode = false } } Actual targets: - recursive alias @melange Internal error, please report upstream including the contents of _build/log. Description: ("Option.value_exn", {}) Raised at Stdune__code_error.raise in file "otherlibs/stdune/src/code_error.ml", line 11, characters 30-62 Called from Fiber__core.O.(>>|).(fun) in file "otherlibs/fiber/src/core.ml", line 250, characters 36-41 Called from Fiber__scheduler.exec in file "otherlibs/fiber/src/scheduler.ml", line 73, characters 8-11 -> required by ("", ()) -> required by ("build-alias", { dir = In_build_dir "default/src"; name = "melange" }) -> required by ("toplevel", ()) I must not crash. Uncertainty is the mind-killer. Exceptions are the little-death that brings total obliteration. I will fully express my cases. Execution will pass over me and through me. And when it has gone past, I will unwind the stack along its path. Where the cases are handled there will be nothing. Only I will remain. ```
rgrinberg commented 1 year ago

Thanks for reporting. The issue is caused by the fact that ppx_deriving is using a template for the META file instead of using dune's metadata. All we can in this case is improve the error message.

If you want to actually use ppx_deriving, you need to do two things:

  1. remove the META file template
  2. add (modes melange) to its runtime.