Using Alire in a monorepo, and some other questions

Hi folks,

I have a monorepo at work, I’m only just getting up to speed with Ada and the tools. So far, I have some crates in my repo but the vscode tooling is having trouble with that as I work on things. The language server is throwing many errors on every save and so on.

I’ve briefly looked over gnatcoll_db and I see a root gpr file. But I don’t really catch what it does or why it works yet. I’m missing any docs about workspaces with multiple crates I think.

Does Alire have a similar concept to cargo workspaces? And is there some clear example for repos with multiple crates that target multiple platforms/architectures?

And what if I’m not using Github or even Git?

I’d love to hear about the experience of other folks if you’re able to share.

Thanks! :smiley:

Reading the documentation of gprbuild a bit, I see that there is a bit more flexibility than what Alire offers. Obviously the constraints with Alire are what open the doors to the various nice things it does otherwise.

Even though the Alire documentation doesn’t recommend it, I created an alire.toml at the root of the repo and added my current set of gpr projects to it.
This… sorta works. But honestly it doesn’t work well at all.

If you go into every subproject and run alr build it’ll create the various config files and so on. But without doing that, then you’ll fail to build anything.

Another approach I just tried was to use pins in the root alire.toml to the subdirectories with other projects, then the root project is just an aggregate.

This almost works, but it rebuilds things and doesn’t constrain things to their target and runtime correctly.

If I understand correctly, you have a bunch of projects with .gpr files in subdirectories and you want to build them all with a single alr build command?

I did something like that in pico_examples. You can supply a list of project files in alire.toml like this:


Ah ok, this is not far from what I initially tried. The difference seems to be that the subdirectories aren’t all their own alire projects.

When I followed along the blog post from AdaCore showing how to start a new micro controller project, it definitely builds the hal crate first, then pins it to the example.

It seems like quite a limitation with Alire that it can’t correctly build pinned crates like that from a fresh checkout then. You’d have to go into every sub-crate in a repo, run alr build in whatever order of dependency they have.

Am I missing something obvious? The reason none of them will build is because Alire creates the gpr file with an inclusion of it’s config project, which won’t exist in a clean checkout.

I’m still not sure I understand the problem you’re describing, can you link to an example repository?

Thanks for sticking with me here. :smiley:

I setup a hello world example, but it works as I’d expect. I think in my work repo, I’m reaching an inconsistent state while fiddling and experimenting with everything.

Essentially, if you haven’t run alire at all on a repo with two alire projects (for example, mylib and mybin), and mybin depends-on mylib and pins to the path ../mylib, then running alr build in mybin does correctly configure mylib, but I erroneously thought otherwise because if I remove the config directory from mylib and then try to build mybin again, you will get an error:

[chipc@sknkwrks mybin]$ alr build
ⓘ Building mybin/mybin.gpr...
mylib.gpr:1:06: imported project file "config/mylib_config.gpr" not found
mylib.gpr:1:06: imported by "/home/chipc/workspaces/alire-monorepo/mylib/mylib.gpr"
mylib.gpr:1:06: imported by "/home/chipc/workspaces/alire-monorepo/mybin/config/mybin_config.gpr"
mylib.gpr:1:06: imported by "/home/chipc/workspaces/alire-monorepo/mybin/mybin.gpr"
mylib.gpr:5:60: unknown package or project "Mylib_Config"
mylib.gpr:8:32: unknown package or project "Mylib_Config"
mylib.gpr:18:40: unknown package or project "Mylib_Config"
mylib.gpr:18:40: wrong expression kind for attribute "default_switches"
gprbuild: "/home/chipc/workspaces/alire-monorepo/mybin/mybin.gpr" processing failed
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/chipc/workspaces/alire-monorepo/mybin/mybin.gpr"] exited with code 4
error: Compilation failed.

You won’t even be able to run alr clean in mybin when this happens.

But if you remove the alire created folders from mybin, then it will work as expected again.

I had moved some things around in my repo, and removed alire generated configs, which then made me think that alire couldn’t correctly handle my intended use case.

Yeah, if you move things around it can get into a weird state. alr update sometimes helps.

I think some of the logic for managing the config directory has been improved in Alire 2.0, to be released soon. You can try the release candidate build.