Overview

Configuration scripts enable the compiler to find code files across multiple directories and software repositories. In brief, configuration scripts provide the compiler with two specific sets of information:

  • Where to find code imported (load-ed) by the code inside the current directory
  • Which code files in the current directory to export to the outside world

When MUFL source code loads an application or library (using the loads keyword), the MUFL compiler first builds a configuration structure that lists the MUFL applications and libraries that the compiler needs to import and export for successful compilation. The compiler then looks for the source file and dependencies based on the contents of the configuration structure. The compiler builds that structure either by running the configuration script located in the directory where the source file resides or by using the default configuration.

Configuration scripts are always named config.mufl must reside in the directory to which they apply.

Default Configuration

When no configuration script exists in a directory, a default configuration structure is automatically generated by the compiler. The default configuration imports and exports every source file in the directory.

For most use cases, allowing the compiler to generate the configuration structure provides the information needed, as well as saves you time.

Custom Configuration

In situations where the default configuration is not sufficient, you need to create a configuration script that evaluates to the configuration structure containing <package_name> -> <file_absolute_path> key-value pairs of the files to import and export.

Consider a simple project containing two source files - an application (.mu) and a library (.mm).

Directory structure:

(dir) Project
    |-(file) MyApp.mu
    |-(file) config.mufl

    |-(dir) lib_A
        |-(file) A.mm

MyApp.mu:

application MyApp loads library A
{
    A::print_hello().
}

lib_A/A.mm:

library A
{
    fn print_hello (_)
    {
        _print "Hello from the library!\n".
    }
}

For the compiler to be aware of and access the files, we need a configuration script alongside the MyApp.mu file in our root directory.

config.mufl:

config script
{
    (
        $imports->(
            $libraries->(
                $A->#"lib_A/A.mm"
            ),
            $applications->(,)
        ),
        $exports->(
            $libraries->(,),
            $applications->(,)
        )
    ).
}

In our script, the library is listed for import. The main application does not need to be listed because there is no need to import or export it. At this point, the MyApp application can successfully access the library where the print_hello function prints:

Hello from the library!

For more information on the configuration structure, configuration script usage, technical details and specifications, and advanced examples, refer to Configuration Scripts (Advanced).