Skip to content

Commit dd71690

Browse files
authored
Add Dune section in OCaml content (#473)
Add OCaml/Dune section
1 parent f8a5808 commit dd71690

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tech/languages/ocaml/dune.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Dune
3+
subsection: ocaml
4+
order: 2
5+
---
6+
7+
# Dune
8+
9+
Dune is a build system for OCaml. It provides a comprehensive and uniform interface for the building, testing, and intalling OCaml projects, making it incredibly easy for developers to manage dependencies between packages. Its primary focus is to offer simplicity, speed, and ease of use, making it a suitable solution for even the most complex and extensive OCaml projects. With Dune, you can enjoy the benefits of incremental builds, which result in faster build times by recompiling only the necessary files. Moreover, Dune makes it convenient to generate optimized native code and perform static analysis, contributing to the development of high-performance and reliable OCaml applications.
10+
11+
## Install
12+
13+
You can install Dune with OPAM that we installed in the enviroment setup.
14+
15+
To install Dune using OPAM run:
16+
17+
```console
18+
$ opam install dune
19+
```
20+
21+
## Starting a new Project
22+
23+
Create a new directory for your project.
24+
25+
```console
26+
$ mkdir yourprojectname
27+
```
28+
29+
To initialize a Dune project change into the new directory and run the following command:
30+
31+
```console
32+
$ cd yourprojectname
33+
$ dune init
34+
```
35+
36+
This will create the necessary files and directories for a basic Dune project, including a `dune` file and a `src` directory.
37+
38+
## Building the project
39+
40+
Change into the **root** directory of your project.
41+
Run the following command to build the project:
42+
43+
```console
44+
$ dune build
45+
```
46+
47+
Dune will compile the source files and generate the necessary executables.
48+
49+
## Running the project
50+
51+
Change into the **root** directory of your project.
52+
Run the following command to run the main executable:
53+
54+
```console
55+
$ dune exec ./bin/your-executable.exe
56+
```
57+
> Replace `your-executable.exe` with the actual name of your executable.
58+
59+
## Adding a library to project
60+
61+
First, make sure you have the required library installed. You can use the following command to install a library using Opam:
62+
63+
```console
64+
$ opam install library-name
65+
```
66+
67+
Open the `dune` file in your project's root directory.
68+
Add the following line to the `(library ...)` section to include the library:
69+
70+
```dune
71+
(libraries library-name)
72+
```
73+
74+
Replace `library-name` with the actual name of the library you want to add.
75+
Save and close the `dune` file.
76+
Rebuild the project using the following command:
77+
78+
```console
79+
$ dune build
80+
```
81+
82+
The added library should now be available for use in your project.

0 commit comments

Comments
 (0)