Skip to content

Extensions

Tal Liron edited this page Jan 4, 2018 · 3 revisions

The most common way to create reusable code in Rōnin is via "extensions". Extensions are most commonly thought of as "libraries" when compiling/linking source code, but what they actually do is manipulate the phase and its executor. Extensions often add/remove command line arguments, change the inputs list, relate the phase to another phase, etc. But, really, the sky's the limit!

You attach extensions to the phase as a list. Let's add a Package extension:

Phase(project=project,
      name='build,
      executor=GccBuild(),
      inputs=glob('src/**.c'),
      extensions=[Package('gtk+-3.0')],
      output='myprog')

Extensions are smart enough to know the type of command, so that different arguments would be added whether the executor is a compiler, a linker, or both. Note that the extensions list can container either extension classes or extension instances. If it's a class, an instance will be constructed with no arguments. Just a little sugar to keep your code cleaner.

In Linux, you'll probably be using the pkg_config.Package extension class a lot, as in the example above. It runs the pkg-config tool, which in turn looks for a .pc descriptor file, and adds the appropriate command line arguments to your compiler and/or linker. By default the .pc file will be sought in a standard location in the operating system, but you can use path= to specify a custom path.

Also common is the ExplicitExtension class, where you can specify the command line values explicitly:

extensions = [ExplicitExtension(libraries=['OpenCL']),
              ExplicitExtension(libraries=['GL'])]

ExplicitExtension is useful if pkg-config or .pc files are not available, or if you have your own way of configuring library usage.

Clone this wiki locally