Skip to content

Commit

Permalink
fix(stdlib): pass flags when building stdlib.ml (#7241)
Browse files Browse the repository at this point in the history
Reported by @gretay-js.

This ensures that when building `stdlib.ml` (the main module of a
library with `(stdlib)`), flags set in the corresponding stanza
`(library)` are correctly passed.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored Mar 14, 2023
1 parent 736279c commit 8621946
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Unreleased
- Bootstrap: correctly detect the number of processors by allowing `nproc` to be
looked up in `$PATH` (#7272, @Alizter)

- Pass correct flags when compiling `stdlib.ml`. (#7241, @emillon)

- Speed up file copying on macos by using `clonefile` when available
(@rgrinberg, #7210)

Expand Down
13 changes: 9 additions & 4 deletions src/dune_rules/compilation_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,16 @@ let create ~super_context ~scope ~expander ~obj_dir ~modules ~flags
}

let for_alias_module t alias_module =
let keep_flags = Modules.is_stdlib_alias (modules t) alias_module in
let flags =
let project = Scope.project t.scope in
let dune_version = Dune_project.dune_version project in
let profile = (Super_context.context t.super_context).profile in
Ocaml_flags.default ~dune_version ~profile
if keep_flags then
(* in the case of stdlib, these flags can be written by the user *)
t.flags
else
let project = Scope.project t.scope in
let dune_version = Dune_project.dune_version project in
let profile = (Super_context.context t.super_context).profile in
Ocaml_flags.default ~dune_version ~profile
in
let sandbox =
let ctx = Super_context.context t.super_context in
Expand Down
18 changes: 18 additions & 0 deletions test/blackbox-tests/test-cases/stdlib/stdlib-flags.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$ cat > dune-project << EOF
> (lang dune 3.7)
> (using experimental_building_ocaml_compiler_with_dune 0.1)
> EOF

$ cat > dune << EOF
> (library
> (name mystdlib)
> (stdlib)
> (flags :standard -w -8))
> EOF

$ cat > mystdlib.ml << EOF
> (* This triggers warning 8 *)
> let None = None
> EOF

$ dune build

0 comments on commit 8621946

Please sign in to comment.