# Working on a local project with opam

**URL:** https://discuss.ocaml.org/t/working-on-a-local-project-with-opam/10071
**Category:** Learning
**Tags:** opam, dune
**Created:** [June 24, 2022, 4:00pm UTC](https://discuss.ocaml.org/t/working-on-a-local-project-with-opam/10071 "2022-06-24T16:00:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![eWert-Online](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ewert-online/32/4130_2.png) [@eWert-Online](https://discuss.ocaml.org/u/eWert-Online)
#### Post date: [June 24, 2022, 4:00pm UTC](https://discuss.ocaml.org/t/working-on-a-local-project-with-opam/10071/1 "2022-06-24T16:00:25Z")

</div>

Hello 🙂

**Disclaimer:**  
I am a total beginner with opam as I am normally using esy as my package manager. But I wanted to try out opam just as a learning experience.

I did setup a local development environment as follows:

1. I downloaded and installed opam 2.1.2 on my mac
2. I am installing my projects dependencies with the following makefile command:

```auto
if ! [-e _opam]; then \
  opam switch create . --empty --yes &&
  opam install --yes ocaml.4.14.0 ;
fi
opam install ./*.opam --deps-only --locked --with-test --yes

```

3. I want to build my project with the following command:

```auto
opam exec --working-dir -- dune build --root . --profile=release @all

```

This works for all files, which are already checked in to the git repository.  
If I however want to add new files and build the project locally, dune doesn’t seem to know of the new files:  
(creating a new file `test.ml`)

```auto
34 | open Test
            ^^^^
Error: Unbound module Test

```

I thought the `--working-dir` flag is used to tell opam to look into the source files for changes as opposed to looking into the git repository, but this doesn’t seem to be the case.

So my question(s) would be:  
How do I test the changes I made to my library locally (before committing them into git)?  
And more generally, why does opam even care about the current state of my git repository?

Thank you for your help!  
- Torben

---

<div class="post-metadata">

### Author: ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)
#### Post date: [June 24, 2022, 8:52pm UTC](https://discuss.ocaml.org/t/working-on-a-local-project-with-opam/10071/2 "2022-06-24T20:52:20Z")

</div>

I’ve tried somewhat similar things in the past. It appears that opam copies your build-tree over into its build-tree storage, and builds there. And (at least from my experience) it isn’t accurate at knowing when the recopy. So if you turn on logging, you should be able to learn the build-directory, go over there, and see that your new files aren’t present.

I _think_ it’s not a question of git, but rather that opam isn’t synchronizing the build-dir with your source-dir.

I _do_ build/install using “opam install --working-dir .” when I want to install a local working version. But I never do that except when I’ve check-into git, and I don’t use that workflow for development – I just invoke make (in your case, dune) the usualy way.

After all, OPAM is a package-manager, not a build-system. Or at least, that’s my view.

---

<div class="post-metadata">

### Author: ![otini](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/otini/32/3533_2.png) [@otini](https://discuss.ocaml.org/u/otini)
#### Post date: [June 24, 2022, 10:13pm UTC](https://discuss.ocaml.org/t/working-on-a-local-project-with-opam/10071/3 "2022-06-24T22:13:10Z")

</div>

> [@eWert-Online](#):
>
> I want to build my project with the following command:
> 
> ```auto
> opam exec --working-dir -- dune build --root . --profile=release @all
> 
> ```

This can be simplified into

```sh
dune build --profile=release

```

> [@eWert-Online](#):
>
> If I however want to add new files and build the project locally, dune doesn’t seem to know of the new files:

You need to let Dune know about the file you just added by modifying the relevant `dune` file. I don’t know what’s the precise structure of your project, but for instance if a library is declared in `lib/dune` as follows:

```auto
(library
  (name mylib)
  (modules a b c))

```

you can decide to add the `Test` module to that library like so:

```auto
(library
  (name mylib)
  (modules a b c test))

```

then all executables using `mylib` will know where to find `Test`. The [Dune documentation](https://dune.readthedocs.io/en/stable/quick-start.html) is available, but in my opinion it can be a lot to take in at once.
