RC RANDOM CHAOS

Getting Started with Dune: An OCaml Build System Primer

· via Hacker News

Original source

OCaml Onboarding: Introduction to the Dune build system

Hacker News →

OCamlPro continues its onboarding series with a hands-on introduction to Dune, the dominant build system in the OCaml ecosystem. Using a minimal toy project called helloer, the walkthrough explains the two foundational files every Dune project needs: dune-project at the root for metadata like Dune version, package name, and opam integration, and dune files in each subdirectory that declare what to build.

The guide breaks down the three core stanzas developers will encounter daily. The library stanza groups modules into a reusable package with a defined public API. The executable stanza wires up a runnable binary, listing dependencies like cmdliner for CLI parsing and exposing it via public_name for opam installation. The test stanza registers a target under the runtest alias so dune test compiles and executes it automatically, typically paired with alcotest.

The post deliberately avoids dune init scaffolding so readers see what the tool generates under the hood. Running dune build @all produces compiled artifacts in a _build directory, and the article positions itself as a companion to the earlier Opam 103 piece, showing how opam project structure and Dune’s build configuration fit together for newcomers to the language.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.