Skip to content

chore: Use Dune package management #3132

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

chore: Use Dune package management #3132

wants to merge 20 commits into from

Conversation

sabine
Copy link
Collaborator

@sabine sabine commented May 26, 2025

This patch changes the build configuration to use Dune Package Management.

Done / To do:

  • we are waiting on a stable installation path for standalone Dune so that we can tell contributors to install via that way (instead of pulling a pinned version of the nightly "developer preview" build)
  • update dune-workspace to pin opam-repository just as we currently do (moved the pins from dune-project there / removed river pin, as it's no longer necessary / pin opam-repository inside dune-workspace)
  • update Dockerfile
  • remove .opam files
  • update Makefiles to reflect using only Dune, and no longer using opam
  • update CONTRIBUTING.md and HACKING.md
  • update playground/ to build with Dune Developer Preview
  • update the CI to use Dune developer preview (thanks Sudha for pointing this out and giving a pointer to a GH action script for Dune Developer Preview)
  • update the scraper to use Dune developer preview
  • Use a pinned version of dune dev preview so the ocaml.org build does not break unexpectedly. Rationale: we sometimes needs to update on short notice and can't afford to have a broken build
  • How do we do power clean? That is getting back to point were dune pkg needs to be initialised. Rationale: this is needed to measure first build time without using docker
  • ocaml.org build is using ~/.cache/ocamlorg is dune pkg also using ~/.cache/dune. What's the impact of deleting it?
  • Create a GitHub action that uses daily dune preview and current version of ocaml.org build as a regression/blackbox test. But let's not do that with the production version
  • Try to merge unrelated changes as much as possible from the patch into main to reduce PR size [on @cuihtlauac]
  • Update contributor documentation to make it clear that removing dune.lock directory is enough to go back to the old build -- relevant only for open PRs / current work in progress, we should encourage people to rebase on main and use Dune package management after the merge of this patch
  • Rebase tested. It should be done to minimize diff surface. Also it needs to be done again when PRs Do not use Anton's river fork #3178 Call make instead of dune build #3179 Only use Alpine 3.21 #3180 and No code blocks w/o language #3181 are merged

To test this

$ make start

$ make playground

$ make scrape

Current status

I believe this is ready to merge.

@gridbugs
Copy link
Contributor

gridbugs commented Jun 5, 2025

I've been using dune package management to build this project whenever I've needed to contribute to it over the past year and it's worked fine until recently. Here are some PRs/issues relating to fixing the problems I've encountered recently:

@gridbugs
Copy link
Contributor

gridbugs commented Jun 5, 2025

There's also currently an issue with the ocamlnet package source being missing. I've added it to the opam-source-archives repo and I have a PR to point the ocamlnet package at the archived source. Once the latter PR is merged, updating the opam-repository revision in this project's dune-workspace to the current tip of opam-repository will fix the problem with ocamlnet.

@Sudha247
Copy link
Contributor

Sudha247 commented Jun 5, 2025

This is great! Thanks for the work, @sabine and @gridbugs. Upon offline discussion with Sabine, we wanted to test this on MacOS and Windows to ensure the workflow remains unaffected for contributors on those platforms. I tested with WSL2 (which is the recommended way to develop ocaml.org on Windows), and the ocaml.org project (with make start), builds and runs locally on WSL2, in this branch with dune pkg. Moreover, the testsuite passes too.

The ocaml.org playground doesn't build, as expected - as it seems to have some dependency issues. I'll try to investigate what's happening there!

@sabine
Copy link
Collaborator Author

sabine commented Jun 6, 2025

Sounds great! Looks like we'll be migrating fully to dune pkg as soon as the playground builds.

@sabine sabine force-pushed the dune_pkg branch 3 times, most recently from a279318 to d48543c Compare June 16, 2025 07:37
@sabine
Copy link
Collaborator Author

sabine commented Jun 16, 2025

Thanks @Sudha247 for sabine#53. This makes the playground dune build succeed.

One thing I observe on my machine:

Both on the main branch, and on this branch, running the playground build just deletes the .cmi files in the asset/ folder of the playground. It should be copying the .cmi files from somewhere. The script gen_stdlib.sh performs this part by looking up via opam the location of these .cmi files, so we need to either find where they reside with a dune build, or find another way to regenerate these files. 🤔

@sabine sabine mentioned this pull request Jun 17, 2025
@sabine sabine marked this pull request as ready for review June 17, 2025 09:49
@sabine sabine changed the title chore: migrate to using dune package management chore: Use Dune package management Jun 20, 2025
HACKING.md Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace all ````` by ````bash` in this file

dune-project Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could the removal of the dependency on Anton's river fork be merged ahead in a separate PR?

Dockerfile Outdated
RUN opam install . --deps-only
# Install Dune Developer Preview
RUN curl -fsSL https://get.dune.build/install | sh
RUN /bin/bash -c 'source "/root/.local/share/dune/env/env.bash"'
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this have any effect? The environment disappears after this call.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We must not download a dev preview on each build, that's brittle and wasteful.

Dockerfile Outdated
RUN sudo apk -U upgrade --no-cache && sudo apk add --no-cache \
RUN apk -U upgrade --no-cache && apk add --no-cache \
# to download and install Dune Developer Preview with alpine:3.21
build-base patch tar ca-certificates git rsync curl sudo bash \
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need for sudo, rsync, bash or nano?

Copy link
Contributor

Choose a reason for hiding this comment

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

You also probably don't need curl. Docker can itself download remote files. See https://docs.docker.com/reference/dockerfile/#adding-files-from-a-url

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, but dune uses curl internally for (url ..) fields, so we still need it.

rpclib-lwt))
(astring (= 0.8.5))
(base-bigarray (= base))
(base-bytes (= base))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is customary to depend on all these base-* packages. After all, they're just transitive dependencies of the compiler selected.

Makefile Outdated
Comment on lines 43 to 44
watch: ## Watch for the filesystem and rebuild on every change
opam exec -- dune build @run -w --force --no-buffer
dune build @run -w --force --no-buffer
Copy link
Contributor

@v-gb v-gb Jun 20, 2025

Choose a reason for hiding this comment

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

I read the HACKING doc a bit quickly, and ran make watch instead of make start first:

$ make watch
dune build @run -w --force --no-buffer

File "src/ocamlorg_web/lib/dune", line 13, characters 2-15:
13 |   mirage-kv-mem))
       ^^^^^^^^^^^^^
Error: Library "mirage-kv-mem" not found.
-> required by library "ocamlorg_web" in _build/default/src/ocamlorg_web/lib
-> required by executable main in src/ocamlorg_web/bin/dune:2
-> required by _build/default/src/ocamlorg_web/bin/main.exe
-> required by alias src/ocamlorg_web/bin/run in src/ocamlorg_web/bin/dune:8
######################################################################## 100.0%                                              
Done: 95% (95/100, 5 left, 1 failed) (jobs: 1)Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme

Rebuilding...

Done in 1911ms.

Shouldn't every rule that does a build depend on dune.lock, instead of just a couple of them? (or taking a step back, I thought the usual thing to do is commit the dune.lock, so I'm a bit confused about why it's being generated on the fly).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks, you're right. need to update the Makefile

@Sudha247 Sudha247 mentioned this pull request Jul 17, 2025
4 tasks
@sabine sabine added the stalled Blocked waiting. Will not progress w/o external progress label Jul 23, 2025
@@ -0,0 +1,14 @@
(version
0.26.2+binary-ocaml-5.2.1-built-2024-12-04.0-x86_64-unknown-linux-musl)
Copy link
Contributor

@gridbugs gridbugs Jul 30, 2025

Choose a reason for hiding this comment

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

Be careful checking this file in as it's not portable. This version of ocamlformat will only work on linux. I'd recommend adding the dev-tools.locks directory to .gitignore so it doesn't get checked in and each user can install the version of the dev tools appropriate to their platform.

@shonfeder
Copy link
Contributor

The install script is ready here, thanks to @gridbugs' work: https://github.com/ocaml-dune/dune-bin-install

@Sudha247 is planning to add documentation here about how to use it.

It also sounds like we should take Steve's advice about ignoring the lock dir, and IIUC @cuihtlauac's review has been addressed and just needs to be re-requested to clear the change request?

Copy link
Collaborator

@cuihtlauac cuihtlauac left a comment

Choose a reason for hiding this comment

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

Small remarks:

  1. File .github/workflows/scrape_changelog.yml should be updated.
  2. There are a few remaining references to olinkcheck that should be removed, it is no longer used

Big question

Is this PR proposing to build ocaml.org with a version of Dune that changes daily? If that is the case, I must object. This is unwise. I support building ocaml.org as a regression test in Dune developer preview CI. However, using an unstable build tool in a production delivery chain is reckless.

Comment on lines +7 to +11
(pin
(name olinkcheck)
(url "git+https://github.com/tarides/olinkcheck")
(package
(name olinkcheck)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

PR #3144 Removed olinkcheck. I dont think this is needed any longer

Comment on lines +17 to +19
(pins olinkcheck)
(version_preference newest)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same remark w.r.t. PR#3144

Comment on lines +30 to +31
- name: Use Dune Developer Preview
uses: ocaml-dune/setup-dune@v0
Copy link
Collaborator

@cuihtlauac cuihtlauac Aug 1, 2025

Choose a reason for hiding this comment

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

I'm not sure I fully understand this.

Are we attempting to build ocaml.org with a build tool that changes daily?

@Sudha247
Copy link
Contributor

Sudha247 commented Aug 1, 2025

Is this PR proposing to build ocaml.org with a version of Dune that changes daily? If that is the case, I must object.

The PR in its current state proposes this approach. However, as @shonfeder noted above, we can use @gridbugs' installer to install the released Dune binary (currently version 3.19.1). I'll update the PR and documentation accordingly. The idea is to use dune pkg for building and deploying the website. Since dune pkg is available in the released version of Dune, we don’t need the developer preview as the experimental features it offers aren’t essential for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stalled Blocked waiting. Will not progress w/o external progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants