From 7524bfed7285afa2f60b3d09d7a9439ac39e5945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Mon, 2 Dec 2024 11:08:47 +0100 Subject: [PATCH 1/5] Do not build .cmxs when library is (no_dynlink) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- src/dune_rules/lib_info.ml | 1 + src/dune_rules/lib_info.mli | 1 + src/dune_rules/lib_rules.ml | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) 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) ;; From a16b767fc62ba5ee239d48c270627772e5e46dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Mon, 2 Dec 2024 11:14:37 +0100 Subject: [PATCH 2/5] Add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- test/blackbox-tests/test-cases/no_dynlink.t | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/blackbox-tests/test-cases/no_dynlink.t 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..b07be606dd1 --- /dev/null +++ b/test/blackbox-tests/test-cases/no_dynlink.t @@ -0,0 +1,37 @@ + $ cat >dune-project < (lang dune 3.17) + > EOF + + $ cat >dune < (library + > (name mylib)) + > EOF + + $ touch a.ml + + $ dune build --display short + ocamlc .mylib.objs/byte/mylib.{cmi,cmo,cmt} + ocamldep .mylib.objs/mylib__A.impl.d + ocamlopt .mylib.objs/native/mylib.{cmx,o} + ocamlc .mylib.objs/byte/mylib__A.{cmi,cmo,cmt} + ocamlopt .mylib.objs/native/mylib__A.{cmx,o} + ocamlc mylib.cma + ocamlopt mylib.{a,cmxa} + ocamlopt mylib.cmxs + + $ cat >dune < (library + > (name mylib) + > (no_dynlink)) + > EOF + + $ dune clean + + $ dune build --display short + ocamlc .mylib.objs/byte/mylib.{cmi,cmo,cmt} + ocamldep .mylib.objs/mylib__A.impl.d + ocamlopt .mylib.objs/native/mylib.{cmx,o} + ocamlc .mylib.objs/byte/mylib__A.{cmi,cmo,cmt} + ocamlopt .mylib.objs/native/mylib__A.{cmx,o} + ocamlc mylib.cma + ocamlopt mylib.{a,cmxa} From 769c00af15ecdd50b4f5f948c6b8b7f2727e8b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Mon, 2 Dec 2024 11:18:02 +0100 Subject: [PATCH 3/5] Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- doc/changes/11176.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 doc/changes/11176.md 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) From 2efeefc2ef12a477a16a68ee623c736419878a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Tue, 3 Dec 2024 09:16:45 +0100 Subject: [PATCH 4/5] Improve test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- test/blackbox-tests/test-cases/no_dynlink.t | 29 +++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/test/blackbox-tests/test-cases/no_dynlink.t b/test/blackbox-tests/test-cases/no_dynlink.t index b07be606dd1..a8fbd49fbae 100644 --- a/test/blackbox-tests/test-cases/no_dynlink.t +++ b/test/blackbox-tests/test-cases/no_dynlink.t @@ -1,7 +1,12 @@ +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)) @@ -9,15 +14,9 @@ $ touch a.ml - $ dune build --display short - ocamlc .mylib.objs/byte/mylib.{cmi,cmo,cmt} - ocamldep .mylib.objs/mylib__A.impl.d - ocamlopt .mylib.objs/native/mylib.{cmx,o} - ocamlc .mylib.objs/byte/mylib__A.{cmi,cmo,cmt} - ocamlopt .mylib.objs/native/mylib__A.{cmx,o} - ocamlc mylib.cma - ocamlopt mylib.{a,cmxa} - ocamlopt mylib.cmxs + $ dune build _build/default/mylib.cmxs + +Now with `(no_dynlink)`. $ cat >dune < (library @@ -27,11 +26,7 @@ $ dune clean - $ dune build --display short - ocamlc .mylib.objs/byte/mylib.{cmi,cmo,cmt} - ocamldep .mylib.objs/mylib__A.impl.d - ocamlopt .mylib.objs/native/mylib.{cmx,o} - ocamlc .mylib.objs/byte/mylib__A.{cmi,cmo,cmt} - ocamlopt .mylib.objs/native/mylib__A.{cmx,o} - ocamlc mylib.cma - ocamlopt mylib.{a,cmxa} + $ 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] From 62fbe0bf646bb4ec410102839bd12c9d995aacb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Wed, 4 Dec 2024 07:35:06 +0100 Subject: [PATCH 5/5] Add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- test/blackbox-tests/test-cases/no_dynlink.t | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/blackbox-tests/test-cases/no_dynlink.t b/test/blackbox-tests/test-cases/no_dynlink.t index a8fbd49fbae..8cd0a904af7 100644 --- a/test/blackbox-tests/test-cases/no_dynlink.t +++ b/test/blackbox-tests/test-cases/no_dynlink.t @@ -30,3 +30,33 @@ Now with `(no_dynlink)`. 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]