Skip to content

Commit

Permalink
Merge pull request #10975 from gridbugs/pkg-tutorial-rewording
Browse files Browse the repository at this point in the history
Minor changes to package management tutorial
  • Loading branch information
gridbugs authored Oct 3, 2024
2 parents 451e5b4 + 1dc160e commit 8ff0a89
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
10 changes: 5 additions & 5 deletions doc/tutorials/dune-package-management/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ First we update the `dune-project` file to add a dependeny on the opam package.
After this change to our project dependencies, we need to relock dependencies
to update our lock directory with the new packages.

```sh
```
$ dune pkg lock
Solution for dune.lock:
- base-unix.base
Expand All @@ -45,7 +45,7 @@ including transitive dependencies.
:::

This will take care of installing the dependencies, but we still need to add it to
our build as a library, as usual:
our build as a library as usual:

::::{dropdown} `dune`
:icon: file-code
Expand Down Expand Up @@ -76,7 +76,7 @@ and then use it to print the value.

To build it we just call `build` again.

```sh
```
$ dune build
```

Expand All @@ -85,7 +85,7 @@ before.

As we see, the code works and uses `fmt` to do the pretty-printing:

```sh
```
$ dune exec ./test.exe
Hello, OCaml, Rust!
```
Expand All @@ -110,7 +110,7 @@ This ensures the `fmt` package to install will be compatible with
our request. These constraints will be taken into account the next time the
package is locked:

```sh
```
$ dune pkg lock
Solution for dune.lock:
- base-unix.base
Expand Down
18 changes: 11 additions & 7 deletions doc/tutorials/dune-package-management/pinning.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

When Dune is looking up packages to lock, it uses the (pre)configured OCaml
package repositories. However it is also possible to manually specify the
sources for packages; for example, if the package is not released in a package
repository. This is called "pinning."
sources of packages; for example, if the package is not released in a package
repository. This is called "pinning".

## Installing Packages From a Pin

Expand All @@ -14,18 +14,21 @@ To pin a package, a new `pin` has to be declared in the `dune-project` file.

:::{literalinclude} pinning/dune-project
:language: dune
:emphasize-lines: 4-6
:emphasize-lines: 4-6,12
:::

This will create a pin on the `fmt` package and use the specified Git repository
URL to retrieve the sources.

Don't forget to remove the version constraints from `fmt` in the list of
dependencies.

::::

The next time the package is locked, Dune will use this repository instead of
the information from the selected package repositories.

```sh
```
$ dune pkg lock
Solution for dune.lock:
- base-unix.base
Expand All @@ -41,10 +44,11 @@ Solution for dune.lock:
Unlike previously, the version of the `fmt` library that is picked is `dev`, to
signify a development version.

The next build will check out the sources from that repository instead of
downloading the release tarball:
The next time the project is built, the `fmt` package will be built from the
source in the specified Git repository rather than from the source tarball
released in the `opam-repository`.

```sh
```
$ dune exec ./test.exe
Hello, OCaml, Rust!
```
4 changes: 2 additions & 2 deletions doc/tutorials/dune-package-management/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ if it didn't exist):
::::

In this case, we want to select a specific revision of the community repository
instead of always using the most recent one, as it would do by default. We
instead of always using the most recent one as it would do by default. We
define a new repository and configure the lock directory to use this
repository.

When relocking the dependencies, the list of packages that are found as
dependencies changes accordingly:

```sh
```
$ dune pkg lock
Solution for dune.lock:
- base-unix.base
Expand Down
8 changes: 4 additions & 4 deletions doc/tutorials/dune-package-management/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies in the `dune-project` file.
:emphasize-lines: 6-7
:::

We define a project called `test` and define that to build it we need an OCaml
We define a project called `test` and declare that to build it we need an OCaml
compiler that is at least version 4.14.

This is exactly the same information that is used to generate opam files using
Expand Down Expand Up @@ -61,7 +61,7 @@ After declaring the dependencies, you will need to tell Dune which package
versions to use for your project. This is done by creating a lock directory.
This is easily done with a new Dune command:

```sh
```
$ dune pkg lock
Solution for dune.lock:
- ocaml.5.2.0
Expand Down Expand Up @@ -95,15 +95,15 @@ before.

We can show that the package has been built successfully and works as expected:

```sh
```
$ dune exec ./test.exe
Hello, OCaml, Rust!
```

## Conclusion

In this section we learned how to set up a Dune project that picks a compiler
and installs it without need for any additional tooling.
and installs it without the need for any additional tooling.

In the next section {doc}`dependencies` we will look on how to add third party
dependencies.

0 comments on commit 8ff0a89

Please sign in to comment.