diff --git a/src/dune_rules/melange/melange_rules.ml b/src/dune_rules/melange/melange_rules.ml index 0e2411dddb3..2812ddad4f1 100644 --- a/src/dune_rules/melange/melange_rules.ml +++ b/src/dune_rules/melange/melange_rules.ml @@ -194,6 +194,7 @@ let build_js ~obj_dir ~sctx ~includes + ~(compile_flags : Ocaml_flags.t) ~local_modules_and_obj_dir m = @@ -218,6 +219,7 @@ let build_js compiler [ Command.Args.S obj_dir ; Command.Args.as_any includes + ; Command.Args.dyn (Ocaml_flags.get compile_flags Melange) ; As melange_package_args ; A "-o" ; Target output @@ -259,6 +261,13 @@ let add_deps_to_aliases ?(alias = Melange_stanzas.Emit.implicit_alias) ~dir deps Memo.parallel_iter ~f:attach [ alias; dune_default_alias ] ;; +let melange_compile_flags ~sctx ~dir (mel : Melange_stanzas.Emit.t) = + let specific = Lib_mode.Map.make_all mel.compile_flags in + Ocaml_flags.Spec.make ~common:Ordered_set_lang.Unexpanded.standard ~specific + |> Ocaml_flags_db.ocaml_flags sctx ~dir + >>| Ocaml_flags.allow_only_melange +;; + let setup_emit_cmj_rules ~sctx ~dir @@ -297,12 +306,7 @@ let setup_emit_cmj_rules Modules.With_vlib.modules modules, pp in let requires_link = Lib.Compile.requires_link compile_info in - let* flags = - let specific = Lib_mode.Map.make_all mel.compile_flags in - Ocaml_flags.Spec.make ~common:Ordered_set_lang.Unexpanded.standard ~specific - |> Ocaml_flags_db.ocaml_flags sctx ~dir - >>| Ocaml_flags.allow_only_melange - in + let* flags = melange_compile_flags ~sctx ~dir mel in let* cctx = let direct_requires = Lib.Compile.direct_requires compile_info in Compilation_context.create @@ -473,7 +477,7 @@ let setup_entries_js in let requires_link = Resolve.return requires_link in cmj_includes ~requires_link ~scope lib_config - in + and* compile_flags = melange_compile_flags ~sctx ~dir mel in let output = `Private_library_or_emit target_dir in let obj_dir = Obj_dir.of_local local_obj_dir in let* () = @@ -493,6 +497,7 @@ let setup_entries_js ~obj_dir ~sctx ~includes + ~compile_flags ~local_modules_and_obj_dir m) ;; @@ -556,7 +561,7 @@ let setup_js_rules_libraries = |> Resolve.Memo.map ~f:(with_vlib_implementations lib) in cmj_includes ~requires_link ~scope lib_config - in + and* compile_flags = melange_compile_flags ~sctx ~dir mel in let+ () = setup_runtime_assets_rules sctx @@ -602,13 +607,13 @@ let setup_js_rules_libraries = ~sctx ~scope vlib - ~f:(build_js ~dir ~output ~includes) + ~f:(build_js ~dir ~output ~includes ~compile_flags) and+ () = parallel_build_source_modules ~sctx ~scope lib - ~f:(build_js ~dir ~output ~includes) + ~f:(build_js ~dir ~output ~includes ~compile_flags) in ()) ;; diff --git a/test/blackbox-tests/test-cases/melange/flags-for-emission.t b/test/blackbox-tests/test-cases/melange/flags-for-emission.t index cc89ce11cd4..cfb40a084d7 100644 --- a/test/blackbox-tests/test-cases/melange/flags-for-emission.t +++ b/test/blackbox-tests/test-cases/melange/flags-for-emission.t @@ -23,7 +23,6 @@ File is generated with the "Generated by Melange" header even though we specified the opposite in flags $ cat _build/default/output/main.js - // Generated by Melange 'use strict';