From 61eda4f2454af80ed965d871c515d90dd657d988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Wed, 4 Dec 2024 07:55:49 +0100 Subject: [PATCH 1/2] `(no_dynlink)`: do not build `.cmxs` (#11176) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Do not build .cmxs when library is (no_dynlink) Signed-off-by: Nicolás Ojeda Bär * Add test Signed-off-by: Nicolás Ojeda Bär * Changes Signed-off-by: Nicolás Ojeda Bär * Improve test Signed-off-by: Nicolás Ojeda Bär * Add test Signed-off-by: Nicolás Ojeda Bär --------- Signed-off-by: Nicolás Ojeda Bär (cherry picked from commit 41212a5ce955ed477690a4145c1bc43c90d29f21) --- doc/changes/11176.md | 2 + src/dune_rules/lib_info.ml | 1 + src/dune_rules/lib_info.mli | 1 + src/dune_rules/lib_rules.ml | 4 +- test/blackbox-tests/test-cases/no_dynlink.t | 62 +++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 doc/changes/11176.md create mode 100644 test/blackbox-tests/test-cases/no_dynlink.t diff --git a/doc/changes/11176.md b/doc/changes/11176.md new file mode 100644 index 00000000000..be4fe1f57ad --- /dev/null +++ b/doc/changes/11176.md @@ -0,0 +1,2 @@ +- #11176: when a library declares `(no_dynlink)`, then the `.cmxs` file for it + is no longer built. (@nojb) diff --git a/src/dune_rules/lib_info.ml b/src/dune_rules/lib_info.ml index ca5d45f6536..6744ee0a70c 100644 --- a/src/dune_rules/lib_info.ml +++ b/src/dune_rules/lib_info.ml @@ -378,6 +378,7 @@ let orig_src_dir t = t.orig_src_dir let best_src_dir t = Option.value ~default:t.src_dir t.orig_src_dir let set_version t version = { t with version } let entry_modules t = t.entry_modules +let dynlink_supported t = Mode.Dict.get t.plugins Native <> [] let eval_native_archives_exn (type path) (t : path t) ~modules = match t.native_archives, modules with diff --git a/src/dune_rules/lib_info.mli b/src/dune_rules/lib_info.mli index 0fe1fa5868c..0b14b22e3ad 100644 --- a/src/dune_rules/lib_info.mli +++ b/src/dune_rules/lib_info.mli @@ -155,6 +155,7 @@ val enabled : _ t -> Enabled_status.t Memo.t val orig_src_dir : 'path t -> 'path option val version : _ t -> Package_version.t option val dune_version : _ t -> Dune_lang.Syntax.Version.t option +val dynlink_supported : _ t -> bool (** Directory where the source files for the library are located. Returns the original src dir when it exists *) diff --git a/src/dune_rules/lib_rules.ml b/src/dune_rules/lib_rules.ml index 5919ad64359..6cbc49b8053 100644 --- a/src/dune_rules/lib_rules.ml +++ b/src/dune_rules/lib_rules.ml @@ -490,7 +490,9 @@ let setup_build_archives (lib : Library.t) ~top_sorted_modules ~cctx ~expander ~ Super_context.add_rule sctx ~dir ~loc:lib.buildable.loc rule))) in Memo.when_ - (Dynlink_supported.By_the_os.get natdynlink_supported && modes.ocaml.native) + (Lib_info.dynlink_supported lib_info + && Dynlink_supported.By_the_os.get natdynlink_supported + && modes.ocaml.native) (fun () -> build_shared ~native_archives ~sctx lib ~dir ~flags) ;; diff --git a/test/blackbox-tests/test-cases/no_dynlink.t b/test/blackbox-tests/test-cases/no_dynlink.t new file mode 100644 index 00000000000..8cd0a904af7 --- /dev/null +++ b/test/blackbox-tests/test-cases/no_dynlink.t @@ -0,0 +1,62 @@ +This test checks that if a library is declared with `(no_dynlink)`, then the +corresponding `.cmxs` file is *not* built. + + $ cat >dune-project < (lang dune 3.17) + > EOF + +First we check the behaviour when `(no_dynlink)` is not present. + + $ cat >dune < (library + > (name mylib)) + > EOF + + $ touch a.ml + + $ dune build _build/default/mylib.cmxs + +Now with `(no_dynlink)`. + + $ cat >dune < (library + > (name mylib) + > (no_dynlink)) + > EOF + + $ dune clean + + $ dune build _build/default/mylib.cmxs + Error: Don't know how to build _build/default/mylib.cmxs + Hint: did you mean _build/default/mylib.cma or _build/default/mylib.cmxa? + [1] + +Next, we check that the .cmxs is installed without `(no_dynlink)`: + + $ cat >dune-project < (lang dune 3.17) + > (package (name mylib)) + > EOF + + $ cat >dune < (library + > (public_name mylib)) + > EOF + + $ dune build _build/default/mylib.install + + $ grep cmxs _build/default/mylib.install + "_build/install/default/lib/mylib/mylib.cmxs" + +And *not* installed with `(no_dynlink)`: + + $ cat >dune < (library + > (public_name mylib) + > (no_dynlink)) + > EOF + + $ dune build _build/default/mylib.install + + $ grep cmxs _build/default/mylib.install + [1] From e263635642b8a792c9b1a207626622362e27dea8 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Tue, 3 Dec 2024 21:13:22 +1100 Subject: [PATCH 2/2] Fix ignored-dune-lock test on macos (#11179) The macos patch utility doesn't like it when a patch contains no hunks, so this change adds a hunk to the patch used in the ignored-dune-lock test. Signed-off-by: Stephen Sherratt --- test/blackbox-tests/test-cases/pkg/ignored-dune-lock.t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/blackbox-tests/test-cases/pkg/ignored-dune-lock.t b/test/blackbox-tests/test-cases/pkg/ignored-dune-lock.t index 70bc5bbad7a..b5a04143d54 100644 --- a/test/blackbox-tests/test-cases/pkg/ignored-dune-lock.t +++ b/test/blackbox-tests/test-cases/pkg/ignored-dune-lock.t @@ -16,6 +16,8 @@ Test that shows what happens when dune.lock is ignored. > index b69a69a5a..ea988f6bd 100644 > --- a/foo.ml > +++ b/foo.ml + > @@ -0,0 +1 @@ + > +let () = print_endline "Hello, World!" > EOF $ mkdir src