diff --git a/CHANGES.md b/CHANGES.md index cb523a29d80..ef0d8059f7c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,6 +34,9 @@ Unreleased - Added a new user action `(concurrent )` which is like `(progn )` but runs the actions concurrently. (#6933, @Alizter) +- Allow `(stdlib ...)` to be used with `(wrapped false)` in library stanzas + (#7139, @anmonteiro). + 3.7.0 (2023-02-17) ------------------ diff --git a/src/dune_rules/dune_file.ml b/src/dune_rules/dune_file.ml index 33c961ee62e..b9a57e7a4c3 100644 --- a/src/dune_rules/dune_file.ml +++ b/src/dune_rules/dune_file.ml @@ -907,7 +907,10 @@ module Library = struct | Some x, From _ -> From x | Some _, This _ (* cannot specify for wrapped for implements *) | None, From _ -> assert false (* cannot inherit for normal libs *) - | None, This (Simple false) -> This None + | None, This (Simple false) -> ( + match t.stdlib with + | None -> This None + | Some _ -> This (Some (Module_name.of_local_lib_name t.name))) | None, This (Simple true | Yes_with_transition _) -> This (Some (Module_name.of_local_lib_name t.name)) diff --git a/src/dune_rules/modules.ml b/src/dune_rules/modules.ml index 6561c2c28e7..b7980569c60 100644 --- a/src/dune_rules/modules.ml +++ b/src/dune_rules/modules.ml @@ -94,16 +94,20 @@ module Stdlib = struct | None -> false | Some n -> n = name - let make ~(stdlib : Ocaml_stdlib.t) ~modules ~main_module_name = + let make ~(stdlib : Ocaml_stdlib.t) ~modules ~wrapped ~main_module_name = let modules = - Module_name.Map.map modules ~f:(fun m -> - if - Module.name m = main_module_name || special_compiler_module stdlib m - then m - else - let path = [ main_module_name; Module.name m ] in - let m = Module.set_path m path in - Module.set_obj_name m (Module_name.Path.wrap path)) + match wrapped with + | Wrapped.Simple true | Yes_with_transition _ -> + Module_name.Map.map modules ~f:(fun m -> + if + Module.name m = main_module_name + || special_compiler_module stdlib m + then m + else + let path = [ main_module_name; Module.name m ] in + let m = Module.set_path m path in + Module.set_obj_name m (Module_name.Path.wrap path)) + | Simple false -> modules in let unwrapped = stdlib.modules_before_stdlib in let exit_module = stdlib.exit_module in @@ -805,7 +809,7 @@ let lib ~obj_dir ~main_module_name ~wrapped ~stdlib ~lib_name ~implements | Some stdlib -> let main_module_name = Option.value_exn main_module_name in let modules = Module_trie.to_map modules in - Stdlib (Stdlib.make ~stdlib ~modules ~main_module_name) + Stdlib (Stdlib.make ~stdlib ~modules ~wrapped ~main_module_name) | None -> ( match (wrapped, main_module_name, Module_trie.as_singleton modules) with | Simple false, _, Some m -> Singleton m diff --git a/test/blackbox-tests/test-cases/stdlib-compilation-depend-on-library.t b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation-depend-on-library.t similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation-depend-on-library.t rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation-depend-on-library.t diff --git a/test/blackbox-tests/test-cases/stdlib/stdlib-compilation-wrapping.t b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation-wrapping.t new file mode 100644 index 00000000000..aa255832112 --- /dev/null +++ b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation-wrapping.t @@ -0,0 +1,45 @@ +Compile a library with `(stdlib ..)` and wrapped settings + + $ cat > dune-project < (lang dune 3.7) + > (using experimental_building_ocaml_compiler_with_dune 0.1) + > EOF + + $ mkdir stdlib + $ runtest() { + > cat >stdlib/dune < (library + > (name mystdlib) + > (wrapped $1) + > (stdlib + > (internal_modules Camlinternal*))) + > EOF + > dune build + > find _build/default/stdlib -iname '*.cmi' | sort; + > } + + $ cat > stdlib/other.ml < let other () = Mystdlib.defined_in_stdlib + > EOF + $ cat > stdlib/one_module.ml < let foo = "foo" + > EOF + $ cat > stdlib/mystdlib.ml < let defined_in_stdlib = "defined" + > module One_module = One_module + > module Other = Other + > EOF + +First we test wrapped: + + $ runtest "true" + _build/default/stdlib/.mystdlib.objs/byte/mystdlib.cmi + _build/default/stdlib/.mystdlib.objs/byte/mystdlib__One_module.cmi + _build/default/stdlib/.mystdlib.objs/byte/mystdlib__Other.cmi + +And now unwrapped: + + $ runtest "false" + _build/default/stdlib/.mystdlib.objs/byte/mystdlib.cmi + _build/default/stdlib/.mystdlib.objs/byte/one_module.cmi + _build/default/stdlib/.mystdlib.objs/byte/other.cmi diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/dune-project b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/dune-project similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/dune-project rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/dune-project diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/run.t b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/run.t similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/run.t rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/run.t diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/src/camlinternalFormatBasics.ml b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/camlinternalFormatBasics.ml similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/src/camlinternalFormatBasics.ml rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/camlinternalFormatBasics.ml diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/src/dune b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/dune similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/src/dune rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/dune diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/src/list.ml b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/list.ml similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/src/list.ml rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/list.ml diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/src/std_exit.ml b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/std_exit.ml similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/src/std_exit.ml rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/std_exit.ml diff --git a/test/blackbox-tests/test-cases/stdlib-compilation.t/src/stdlib.ml b/test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/stdlib.ml similarity index 100% rename from test/blackbox-tests/test-cases/stdlib-compilation.t/src/stdlib.ml rename to test/blackbox-tests/test-cases/stdlib/stdlib-compilation.t/src/stdlib.ml