Search code examples
configurationshake-build-system

How to specify non-trivial metadata to drive a shake build system?


Given a non-homogeneously structured mixed-language code base, what is the recommended way to specify metadata to drive a Shake build system?

In particular, the metadata should describe source language (C++, C#, Fortran), source files, result type (static/dynamic lib, executable), compiler switches (potentially different for each artifact), etc.

Preferably, the metadata should be simply structured and stored in one separate file per artifact.

Is there a smart way to generalize the approach suggested in Defining your own build system with Shake?


Solution

  • The approach from the presentation scales quite far - I've used it for huge multilanguage projects. I've used three tweaks beyond the talk:

    Add file extensions

    Typically file extensions give you the source language and result type. For example:

    mycsharp.dll = foo.cs bar.cs
    myfortran.exe = main.f90 util.f90
    docs.pdf = docs.tex references.bib
    

    Now you can have entirely different rules to interpret Fortran executables, C# executables (or dlls) and PDF documents.

    Add some 'leading' characters

    Often you want data about flags, or other command-line relevant data. For example:

    mycsharp.dll = foo.cs bar.cs -define:DEBUG -optimize +mono
    

    I tend to use special leading characters. In the above example I've used - to denote flags (which are usually passed on verbatim), and + to denote a selection from an enumeration which contains useful special cases (e.g. use the mono compiler).

    One word of caution, don't use too many weird leading special characters, or you end up inventing your own language - keep it simple.

    Use a C pre processor (CPP)

    The C pre processor gives you #include, #define and #ifdef, all of which can be used in more complex structured metadata. You can use this with Shake by invoking cpphs on the metadata file first.

    While the two previous tweaks are recommended, the use of CPP was originally for #include. Now the built-in Shake metadata has an include mechanism I'm not sure I'd bother with CPP, which keeps things simpler.