diff --git a/src/dune/dune_file.ml b/src/dune/dune_file.ml index efd6f673d603..fc98d1d75665 100644 --- a/src/dune/dune_file.ml +++ b/src/dune/dune_file.ml @@ -958,33 +958,22 @@ module Library = struct List.is_non_empty t.buildable.foreign_stubs || List.is_non_empty t.buildable.foreign_archives - let default_archive_name t = Lib_name.Local.to_string (snd t.name) ^ "_stubs" - - let default_lib_file t ~dir ~ext_lib = - Path.Build.relative dir - (sprintf "lib%s%s" (default_archive_name t) ext_lib) - - let default_dll_file t ~dir ~ext_dll = - Path.Build.relative dir - (sprintf "dll%s%s" (default_archive_name t) ext_dll) + let stubs_archive_name t = Lib_name.Local.to_string (snd t.name) ^ "_stubs" let archive_names t = ( if List.is_empty t.buildable.foreign_stubs then [] else - [ default_archive_name t ] ) + [ stubs_archive_name t ] ) @ List.map ~f:snd t.buildable.foreign_archives - (* TODO_AM: Code duplication. *) let lib_files t ~dir ~ext_lib = - List.map (archive_names t) ~f:(fun name -> - Path.Build.relative dir (sprintf "lib%s%s" name ext_lib)) + List.map (archive_names t) ~f:(fun archive_name -> + Foreign.lib_file ~archive_name ~dir ~ext_lib) let dll_files t ~dir ~ext_dll = - List.map (archive_names t) ~f:(fun name -> - Path.Build.relative dir (sprintf "dll%s%s" name ext_dll)) - - let stubs_path t ~dir = Path.Build.relative dir (default_archive_name t) + List.map (archive_names t) ~f:(fun archive_name -> + Foreign.dll_file ~archive_name ~dir ~ext_dll) let archive t ~dir ~ext = Path.Build.relative dir (Lib_name.Local.to_string (snd t.name) ^ ext) diff --git a/src/dune/dune_file.mli b/src/dune/dune_file.mli index 40e81854e153..b036010b6575 100644 --- a/src/dune/dune_file.mli +++ b/src/dune/dune_file.mli @@ -202,13 +202,7 @@ module Library : sig val has_stubs : t -> bool - val default_archive_name : t -> string - - val default_lib_file : - t -> dir:Path.Build.t -> ext_lib:string -> Path.Build.t - - val default_dll_file : - t -> dir:Path.Build.t -> ext_dll:string -> Path.Build.t + val stubs_archive_name : t -> string val archive_names : t -> string list @@ -216,8 +210,6 @@ module Library : sig val dll_files : t -> dir:Path.Build.t -> ext_dll:string -> Path.Build.t list - val stubs_path : t -> dir:Path.Build.t -> Path.Build.t - val archive : t -> dir:Path.Build.t -> ext:string -> Path.Build.t val best_name : t -> Lib_name.t diff --git a/src/dune/lib_rules.ml b/src/dune/lib_rules.ml index 7814722d8721..c497660e0f91 100644 --- a/src/dune/lib_rules.ml +++ b/src/dune/lib_rules.ml @@ -136,10 +136,11 @@ let ocamlmklib ~path ~loc ~c_library_flags ~sctx ~dir ~expander ~o_files (* Add a rule calling [ocamlmklib] to build an OCaml library. *) let ocamlmklib_ocaml (lib : Library.t) ~sctx ~dir ~expander ~o_files ~sandbox ~custom ~targets = - ocamlmklib - ~path:(Path.build (Library.stubs_path lib ~dir)) - ~loc:lib.buildable.loc ~c_library_flags:lib.c_library_flags ~sctx ~dir - ~expander ~o_files ~sandbox ~custom ~targets + let path = + Path.build (Path.Build.relative dir (Library.stubs_archive_name lib)) + in + ocamlmklib ~path ~loc:lib.buildable.loc ~c_library_flags:lib.c_library_flags + ~sctx ~dir ~expander ~o_files ~sandbox ~custom ~targets (* Build a static and a dynamic archive for a foreign library. *) let build_foreign_library (library : Foreign.Library.t) ~sctx ~expander ~dir @@ -226,8 +227,9 @@ let build_self_stubs lib ~cctx ~expander ~dir ~o_files = let sctx = Compilation_context.super_context cctx in let ctx = Super_context.context sctx in let { Lib_config.ext_lib; ext_dll; _ } = ctx.lib_config in - let static = Library.default_lib_file lib ~dir ~ext_lib in - let dynamic = Library.default_dll_file lib ~dir ~ext_dll in + let archive_name = Library.stubs_archive_name lib in + let static = Foreign.lib_file ~archive_name ~dir ~ext_lib in + let dynamic = Foreign.dll_file ~archive_name ~dir ~ext_dll in let modes = Compilation_context.modes cctx in let ocamlmklib = ocamlmklib_ocaml lib ~sctx ~expander ~dir ~o_files in if