Skip to content

Commit

Permalink
fix: preserve directory hierarchy for installed headers
Browse files Browse the repository at this point in the history
If we have foo/bar.h, we'll preserve the hierarchy relative to the
library directory

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: cf542cda-1684-4719-bffd-fdb6a8bc2d63 -->
  • Loading branch information
rgrinberg committed Apr 7, 2023
1 parent 691d383 commit 1b630b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 16 additions & 3 deletions src/dune_rules/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,21 @@ end = struct
in
let+ execs = lib_ppxs ctx ~scope ~lib in
let install_c_headers =
List.map lib.install_c_headers ~f:(fun base ->
Path.Build.relative dir (base ^ Foreign_language.header_extension))
let f =
let path base =
Path.Build.relative dir (base ^ Foreign_language.header_extension)
in
let project = Scope.project scope in
if Dune_project.dune_version project < (3, 8) then fun base ->
make_entry Lib (path base)
else fun base ->
let sub_dir =
let dirname = Filename.dirname base in
if dirname = "." then None else in_sub_dir (Some dirname)
in
make_entry ?sub_dir Lib (path base)
in
List.map lib.install_c_headers ~f
in
List.concat
[ sources
Expand All @@ -292,7 +305,7 @@ end = struct
; List.map dll_files ~f:(fun a ->
let entry = Install.Entry.make ~kind:`File Stublibs a in
Install.Entry.Sourced.create ~loc entry)
; List.map ~f:(make_entry Lib) install_c_headers
; install_c_headers
]

let keep_if expander ~scope stanza =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ Headers with the same filename cannot be installed together:
$ touch foo.h inc/foo.h

$ dune build mypkg.install && cat _build/default/mypkg.install | grep ".h"
Error: Multiple rules generated for _build/install/default/lib/mypkg/foo.h:
- dune:1
- dune:1
-> required by _build/default/mypkg.install
[1]
"_build/install/default/lib/mypkg/foo.h"
"_build/install/default/lib/mypkg/inc/foo.h" {"inc/foo.h"}

Now we demonstrate that header paths get squashed when installed

Expand All @@ -32,5 +29,5 @@ Now we demonstrate that header paths get squashed when installed
> EOF

$ dune build mypkg.install && cat _build/default/mypkg.install | grep ".h"
"_build/install/default/lib/mypkg/bar.h"
"_build/install/default/lib/mypkg/foo.h"
"_build/install/default/lib/mypkg/inc/bar.h" {"inc/bar.h"}

0 comments on commit 1b630b2

Please sign in to comment.