diff --git a/CHANGES.md b/CHANGES.md index be30318b82fd..3a6f204e164b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ - Fix segfault on MacOS when dune was being shutdown while in watch mode. (#7312, fixes #6151, @gridbugs, @emillon) +- Pass correct flags when compiling `stdlib.ml`. (#7241, @emillon) + 3.7.0.post1 (2023-02-21) ------------------------ diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 045a12b83e1b..ea39a0fe8170 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -204,11 +204,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 diff --git a/test/blackbox-tests/test-cases/stdlib-flags.t b/test/blackbox-tests/test-cases/stdlib-flags.t new file mode 100644 index 000000000000..68a39ac8b614 --- /dev/null +++ b/test/blackbox-tests/test-cases/stdlib-flags.t @@ -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