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

feat: allow multiple globs in library's (stdlib (internal_modules ...)) #7878

Merged
merged 3 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Unreleased
- Fix scanning of Coq installed files (@ejgallego, reported by
@palmskog, #7895 , fixes #7893)

- Allow multiple globs in library's `(stdlib (internal_modules ..))`
(@anmonteiro, #7878)

3.8.1 (2023-06-05)
------------------

Expand Down
4 changes: 3 additions & 1 deletion src/dune_rules/modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ module Stdlib = struct
compilation unit name of such modules, so they cannot be wrapped. *)
let special_compiler_module (stdlib : Ocaml_stdlib.t) m =
let name = Module.name m in
Glob.test stdlib.internal_modules (Module_name.to_string name)
let name_str = Module_name.to_string name in
Predicate_lang.Glob.test stdlib.internal_modules
~standard:Predicate_lang.false_ name_str
||
match stdlib.exit_module with
| None -> false
Expand Down
5 changes: 3 additions & 2 deletions src/dune_rules/ocaml_stdlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open! Import
type t =
{ modules_before_stdlib : Module_name.Set.t
; exit_module : Module_name.t option
; internal_modules : Glob.t
; internal_modules : Predicate_lang.Glob.t
; loc : Loc.t
}

Expand All @@ -24,7 +24,8 @@ let decode =
field "modules_before_stdlib" (repeat Module_name.decode) ~default:[]
and+ exit_module = field_o "exit_module" Module_name.decode
and+ internal_modules =
field "internal_modules" Glob.decode ~default:Dune_lang.Glob.empty
field "internal_modules" Predicate_lang.Glob.decode
~default:Predicate_lang.false_
and+ loc = loc in
{ modules_before_stdlib = Module_name.Set.of_list modules_before_stdlib
; exit_module
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/ocaml_stdlib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type t = private
; exit_module : Module_name.t option
(** Modules that are implicitly added by the compiler at the end when
linking an executable *)
; internal_modules : Glob.t
; internal_modules : Predicate_lang.Glob.t
(** Module names that are hardcoded in the compiler and so cannot be
wrapped *)
; loc : Loc.t
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Compile a library with `(stdlib ..)` and multiple globs for internal_modules

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using experimental_building_ocaml_compiler_with_dune 0.1)
> EOF

$ mkdir stdlib
$ cat > stdlib/other.ml <<EOF
> let other () = Mystdlib.defined_in_stdlib
> EOF
$ cat > stdlib/one_module.ml <<EOF
> let foo = "foo"
> EOF
$ cat > stdlib/mystdlib.ml <<EOF
> let defined_in_stdlib = "defined"
> module One_module = One_module
> module Other = Other
> EOF

$ cat >stdlib/dune <<EOF
> (library
> (name mystdlib)
> (stdlib
> (internal_modules one* other)))
> EOF

Works when setting the correct version

$ dune build
$ find _build/default/stdlib -iname '*.cmi' | sort;
_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