From 380fdd63008a2af164de61faaaf0b5de91e6ca6b Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Wed, 8 Mar 2023 15:30:44 +0100 Subject: [PATCH] fix(stdlib): pass flags when building stdlib.ml 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 --- CHANGES.md | 2 ++ src/dune_rules/compilation_context.ml | 13 +++++++++---- .../test-cases/stdlib/stdlib-flags.t | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/blackbox-tests/test-cases/stdlib/stdlib-flags.t diff --git a/CHANGES.md b/CHANGES.md index b3ad66516aa..7a9559af0fe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 465bfd43238..f400ed10b64 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -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 diff --git a/test/blackbox-tests/test-cases/stdlib/stdlib-flags.t b/test/blackbox-tests/test-cases/stdlib/stdlib-flags.t new file mode 100644 index 00000000000..68a39ac8b61 --- /dev/null +++ b/test/blackbox-tests/test-cases/stdlib/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