Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable use of stublibs of _installed_ libraries #7151

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/dune_rules/dune_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Lib = struct
let _, components = Lib_name.split name in
Path.Local.L.relative Path.Local.root components

let encode ~package_root { info; main_module_name } =
let encode ~package_root ~stublibs { info; main_module_name } =
let open Dune_lang.Encoder in
let no_loc f (_loc, x) = f x in
let path = Dpath.Local.encode ~dir:package_root in
Expand Down Expand Up @@ -71,6 +71,14 @@ module Lib = struct
| Needs_module_info _ ->
Code_error.raise "caller must set native archives to known value" []
in
let foreign_dll_files =
match stublibs with
| None -> []
| Some stublibs ->
List.map
~f:(fun file -> Path.relative stublibs (Path.basename file))
(Lib_info.foreign_dll_files info)
in
record_fields
@@ [ field "name" Lib_name.encode name
; field "kind" Lib_kind.encode kind
Expand All @@ -82,6 +90,7 @@ module Lib = struct
; paths "foreign_objects" foreign_objects
; field_i "foreign_archives" (Mode.Map.encode path)
(Lib_info.foreign_archives info)
; paths "foreign_dll_files" foreign_dll_files
; paths "native_archives" native_archives
; paths "jsoo_runtime" jsoo_runtime
; Lib_dep.L.field_encode requires ~name:"requires"
Expand Down Expand Up @@ -148,6 +157,7 @@ module Lib = struct
else
let+ m = mode_paths "foreign_archives" in
Mode.Map.Multi.create_for_all_modes m.byte
and+ foreign_dll_files = paths "foreign_dll_files"
and+ native_archives = paths "native_archives"
and+ jsoo_runtime = paths "jsoo_runtime"
and+ requires = field_l "requires" (Lib_dep.decode ~allow_re_export:true)
Expand Down Expand Up @@ -195,7 +205,7 @@ module Lib = struct
~orig_src_dir ~obj_dir ~version ~synopsis ~main_module_name
~sub_systems ~requires ~foreign_objects ~plugins ~archives
~ppx_runtime_deps ~foreign_archives
~native_archives:(Files native_archives) ~foreign_dll_files:[]
~native_archives:(Files native_archives) ~foreign_dll_files
~jsoo_runtime ~preprocess ~enabled ~virtual_deps ~dune_version
~virtual_ ~entry_modules ~implements ~default_implementation ~modes
~modules ~wrapped ~special_builtin_support ~exit_module:None
Expand Down Expand Up @@ -376,10 +386,13 @@ let encode ~dune_version { entries; name; version; dir; sections; sites; files }
in
let list s = Dune_lang.List s in
let entries =
let stublibs = Section.Map.find sections Stublibs in
Lib_name.Map.to_list_map entries ~f:(fun _name e ->
match e with
| Entry.Library lib ->
list (Dune_lang.atom "library" :: Lib.encode lib ~package_root:dir)
list
(Dune_lang.atom "library"
:: Lib.encode lib ~package_root:dir ~stublibs)
| Deprecated_library_name d ->
list
(Dune_lang.atom "deprecated_library_name"
Expand Down
88 changes: 88 additions & 0 deletions test/blackbox-tests/test-cases/install-stublibs.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Begin by installing a library with C stubs.

$ cat >dune-project <<EOF
> (lang dune 3.7)
> (package (name libA))
> EOF
$ cat >dune <<EOF
> (library
> (name libA)
> (public_name libA)
> (foreign_stubs
> (language c)
> (names stubs)))
> EOF
$ touch stubs.c
$ dune build
$ dune install --prefix ./install
Installing install/lib/libA/META
Installing install/lib/libA/dune-package
Installing install/lib/libA/libA.a
Installing install/lib/libA/libA.cma
Installing install/lib/libA/libA.cmi
Installing install/lib/libA/libA.cmt
Installing install/lib/libA/libA.cmx
Installing install/lib/libA/libA.cmxa
Installing install/lib/libA/libA.ml
Installing install/lib/libA/liblibA_stubs.a
Installing install/lib/libA/libA.cmxs
Installing install/lib/stublibs/dlllibA_stubs.so
$ cat ./install/lib/libA/dune-package
(lang dune 3.8)
(name libA)
(sections
(lib
$TESTCASE_ROOT/install/lib/libA)
(libexec
$TESTCASE_ROOT/install/lib/libA)
(stublibs
$TESTCASE_ROOT/install/lib/stublibs))
(files
(lib
(META
dune-package
libA.a
libA.cma
libA.cmi
libA.cmt
libA.cmx
libA.cmxa
libA.ml
liblibA_stubs.a))
(libexec (libA.cmxs))
(stublibs (dlllibA_stubs.so)))
(library
(name libA)
(kind normal)
(archives (byte libA.cma) (native libA.cmxa))
(plugins (byte libA.cma) (native libA.cmxs))
(foreign_objects stubs.o)
(foreign_archives (archives (for all) (files liblibA_stubs.a)))
(foreign_dll_files ../stublibs/dlllibA_stubs.so)
(native_archives libA.a)
(main_module_name LibA)
(modes byte native)
(modules
(wrapped
(group
(alias
(obj_name libA)
(visibility public)
(kind alias)
(source (path LibA) (impl (path libA.ml-gen))))
(name LibA))
(wrapped true))))

Now let us define an executable using that installed library.

$ cat >dune-project <<EOF
> (lang dune 3.7)
> EOF
$ cat >dune <<EOF
> (executable
> (name exeA)
> (libraries libA)
> (modes byte))
> EOF
$ touch exeA.ml
$ OCAMLPATH=./install/lib dune build