[Csnd] csound development workflow with ninja

Someone at the last conference asked about workflow to help with contributing to csound.
I just wanted to bring it to attention, perhaps c-developer wizards were already aware of this.
That instead of waiting 1-2 minutes to wait for csound to fully rebuild and then see if the changes made were correct. It’s possible to use cmake and ninja together in such a way that rebuilds take less than 3 seconds, and only the files which changed are rebuilt, or the files that changed and the dependencies of those files.

In this screenshot, I rebuilt a file with added printf statement, and ran a test csd file, all within 3 seconds.

I’ll explain how I did this with nix on osx, but nix is only a factor for the dependencies.

I enter a shell with the dependencies I need to build csound, these dependencies I don’t want globally installed so I just create a shell with them when needed (I’ve made a fish function that does this for me)

nix-shell -p cmake libsndfile flex bison boost portaudio gettext clang ninja

now to the magic

$ cmake -Bbuild -H. -GNinja

this will create a new directory “build” with Ninja generator set up correctly configured

$ cd build

now it’s possible to rebuild csound from scratch with

$ ninja

and from this moment on, every time you make a change in the csound c sources, you can, from that directory build, rebuild only the changed c source files by calling again ninja, and a new csound executeable binary will be made with those changes.

For me this is a dramatic save of time, and makes everything much more fun. I wish someone told me earlier about ninja :slight_smile:

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

This is super useful, thanks for sharing.

Yeah, I always use ninja for my CI builds. It’s so much faster.

I use make, I don’t mind slow. It gives me time to think (and get it wrong anyway).

I’ve used both for a long while. I typically run “make -j” for parallel make builds. Cmake tools in vscode get confused for me when I use ninja so my build folder in the repo is usually makefiles but I have a folder for ninja and xcode outside of the repo folder.

yes, with make -j 8 here I can build Csound very quickly.

Prof. Victor Lazzarini
Maynooth University
Ireland

Hlöðver, thanks for sharing. (first time I heard of this ninja approach). Alex