Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(no_dynlink): do not build .cmxs #11176

Merged
merged 5 commits into from
Dec 4, 2024
Merged

(no_dynlink): do not build .cmxs #11176

merged 5 commits into from
Dec 4, 2024

Conversation

nojb
Copy link
Collaborator

@nojb nojb commented Dec 2, 2024

What it says on the tin: when the library declares (no_dynlink), then the .cmxs should not be built. On large codebases, this can save considerable time (especially on Windows).

@nojb
Copy link
Collaborator Author

nojb commented Dec 2, 2024

@rgrinberg: do you think this change would need to be versioned?


$ touch a.ml

$ dune build --display short
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you replace the --display short with just an explicit target such as
mylib.cmxs?

This extra output makes the tests fragile and hard to understand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

@@ -0,0 +1,37 @@
$ cat >dune-project <<EOF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a few sentences here to describe the test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

@rgrinberg
Copy link
Member

It does sound fine to not version this. The old behavior was useless, so I
don't see much reason to preserve it.

Could you add a CHANGES entry?

@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

Could you add a CHANGES entry?

It already has one :)

@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

Thanks for the review @rgrinberg! I think all points are addressed.

@anmonteiro
Copy link
Collaborator

does this still build & install the .cmxs when building for -p .. and dune install?

@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

does this still build & install the .cmxs when building for -p .. and dune install?

No. The .cmxs is not installed (even before this PR) if the library is declared with (no_dynlink). After this PR, the .cmxs is not even built by Dune (if (no_dynlink) is used, of course).

@anmonteiro
Copy link
Collaborator

anmonteiro commented Dec 3, 2024

I disagree: before this PR, a (public_name my_library) installs a my_lybrary.cmxs.

after this PR, a (public_name my_library) (no_dynlink) doesn't install my_library.cmxs.

it's technically a breaking change if these 2 points are true at the same time:

  • a library adds (no_dynlink) and releases to opam
  • another library was using Dynlink.loadfile "that_cmxs_file.cmxs".

note: no strong opinions whether you want to support this (arguable) edge case. i realize that this will help your builds internally and is indeed an edge case (and a new field) so i'm not opposed to it.

@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

I disagree: before this PR, a (public_name my_library) installs a my_lybrary.cmxs.

I cannot reproduce this behaviour with Dune 3.16:

$ mkdir no_dynlink
$ cd no_dynlink
$ cat >dune-project <<EOF
> (lang dune 3.16)
> (package (name foo))
> EOF
$ cat >dune <<EOF
> (library (public_name foo) (no_dynlink))
> EOF
$ dune --version
3.16.0
$ dune build
$ find _build/install/default/
_build/install/default/
_build/install/default/lib
_build/install/default/lib/foo
_build/install/default/lib/foo/foo.cma
_build/install/default/lib/foo/META
_build/install/default/lib/foo/foo.cmt
_build/install/default/lib/foo/foo.a
_build/install/default/lib/foo/foo.cmi
_build/install/default/lib/foo/foo.ml
_build/install/default/lib/foo/dune-package
_build/install/default/lib/foo/foo.cmxa
_build/install/default/lib/foo/foo.cmx
$

@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

@anmonteiro can you confirm whether you are observing the installation of .cmxs of (no_dynlink) libraries or not? And, if yes, can you provide precise reproduction instructions, so that I can investigate the issue? Thanks!

nojb added 4 commits December 3, 2024 14:48
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
@Leonidas-from-XIV
Copy link
Collaborator

@nojb I can confirm that Dune 3.16 has the behavior you describe (also I rebased the branch to get the fix for macOS CI failures in).

@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

@nojb I can confirm that Dune 3.16 has the behavior you describe (also I rebased the branch to get the fix for macOS CI failures in).

Thanks!

@anmonteiro
Copy link
Collaborator

I understand now that dune 3.16 didn't install the cmxs in the first place. that means i'm wrong, please proceed.

@anmonteiro
Copy link
Collaborator

but something has changed between 3.16 and this PR where a .cmxs is installed with dune 3.17. I'm not sure if that's expected but i didn't find it in the changelog


$ dune clean

$ dune build _build/default/mylib.cmxs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests for the .install file as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Fixed, thanks.

@rgrinberg
Copy link
Member

I disagree: before this PR, a (public_name my_library) installs a my_lybrary.cmxs.

after this PR, a (public_name my_library) (no_dynlink) doesn't install my_library.cmxs.

it's technically a breaking change if these 2 points are true at the same time:

  • a library adds (no_dynlink) and releases to opam
  • another library was using Dynlink.loadfile "that_cmxs_file.cmxs".

note: no strong opinions whether you want to support this (arguable) edge case. i realize that this will help your builds internally and is indeed an edge case (and a new field) so i'm not opposed to it.

To re-iterate nojb, I don't see how this PR changes installation. However, this PR is indeed breaking users that relied on building a cmxs but not installing it. I think such an edge case is useless enough that we can let it slide.

@rgrinberg
Copy link
Member

I understand now that dune 3.16 didn't install the cmxs in the first place. that means i'm wrong, please proceed.

That is correct. With this PR, the cmxs won't even be built.

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
@nojb
Copy link
Collaborator Author

nojb commented Dec 4, 2024

All issues having been addressed, planning to merge once CI passes.

@nojb nojb merged commit 41212a5 into ocaml:main Dec 4, 2024
27 of 28 checks passed
@nojb nojb deleted the no_dynlink_cmxs branch December 4, 2024 06:55
nojb added a commit to nojb/dune that referenced this pull request Dec 9, 2024
* Do not build .cmxs when library is (no_dynlink)

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Add test

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Changes

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Improve test

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Add test

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

---------

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
(cherry picked from commit 41212a5)
nojb added a commit that referenced this pull request Dec 16, 2024
* `(no_dynlink)`: do not build `.cmxs` (#11176)

* Do not build .cmxs when library is (no_dynlink)

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Add test

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Changes

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Improve test

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

* Add test

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>

---------

Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
(cherry picked from commit 41212a5)

* 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 <stephen@sherra.tt>

---------

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Co-authored-by: Stephen Sherratt <stephen@sherra.tt>
@maiste maiste mentioned this pull request Dec 16, 2024
11 tasks
maiste added a commit to maiste/opam-repository that referenced this pull request Dec 17, 2024
CHANGES:

### Fixed

- When a library declares `(no_dynlink)`, then the `.cmxs` file for it
  is no longer built. (ocaml/dune#11176, @nojb)

- Fix bug that could result in corrupted file copies by Dune, for example when
  using the `copy_files#` stanza or the `copy#` action. (@nojb, ocaml/dune#11194, fixes
  ocaml/dune#11193)

- Remove useless error message when running `$ dune subst` in empty projects.
  (@rgrinberg, ocaml/dune#11204, fixes ocaml/dune#11200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants