Open main menu

CDOT Wiki β

Adding Compilers to Distcc

Introduction

Distcc now has support for muliple compilers (not just gcc). Most of distcc is compiler agnostic, however certain parts obviously can't be.

distcc code standards

  • All distcc functions are prefixed with dcc_.
  • All words are seperated by underscores. notCamelCase.
  • All compiler specific functions are prefixed with dcc_<compilerName> (e.g. dcc_cl_, dcc_gcc_, etc.)

How a compiler is chosen

One of the first functions called is dcc_set_compiler(char**) - defined in compiler.c. This function is responsible for checking argv[1] and finding out which compiler is being used. Once a compiler is found, distcc must be configured to use that compiler specific code. This is done via a series of if else if statements. distcc defaults to gcc when a compiler is not recognized. When adding a new compiler you will have to add a new else if statement to assign values to the vtable.

The vtable is a struct consisting of a bunch of function pointers (and a char array). When distcc runs it uses an instance of this struct to call the compiler specific functions. The function pointers point to the various dcc_<compilerName> functions. The char array holds options that the compiler uses to run the preprocessor.

It is recommend that you initially use the provided dummy function to be able to test the code as you write it without waiting until everything is written.

Compiler specific functions

Here are the compiler specific functions:

  • dcc_<compilerName>_set_action_opt
    Make sure that argv has an “action option”. This is meant to be used on the client side to run the preprocessor.
  • dcc_<compilerName>_set_output
    Change the output filenames (e.g. the name of the objet files) in argv.
  • dcc_<compilerName>_scan_args
    Check the arguments and see if the job can be distributed.
  • dcc_<compilerName>_strip_local_args
    Strip all the local arguments out of argv. “local arguments” are usually arguments that get passed to the preprocessor.
  • dcc_<compilerName>_strip_dasho
    We don't want the preprocessor output going anywhere except stdout.
  • dcc_<compilerName>_is_source
    Check whether a given filename is a source filename. This is generally done via a filename extension.
  • dcc_<compilerName>_is_preprocessed
    check whether a file has been preprocessed. this is generally done via a filename extension
  • dcc_<compilerName>_is_object
    check whether a file is a compiled object file. this is generally done via a filename extension
  • dcc_<compilerName>_preproc_exten
    Return the extension of a preprocessed extension file.
  • dcc_<compilerName>_get_hostlist
    Return a list of hosts to which it is possible to distribute. This is usually gotten from an environment variable.

Notes for new compiler porters

Distcc assumes that you'll need to pass your code through a preprocessor. This may not be the case for all languages. You can probably get away with just returning 0 and basically leaving those functions empty. You will also want to hold your host list in a different environment variable.