github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/docs/compilers/README.md (about)

     1  **Compilers** conform to the interface:
     2  ```go
     3  type Compiler interface {
     4  	CompileRawImage(params types.CompileImageParams) (*types.RawImage, error)
     5  }
     6  ```
     7  
     8  Where `CompileImageParams` consists of the following:
     9  
    10  ```go
    11  type CompileImageParams struct {
    12  	SourcesDir string //path to directory containing application source code
    13  	Args string //arguments to pass to the kernel at runtime
    14  	MntPoints []string //mount points to expect at runtime
    15  	NoCleanup bool //indicates to the compiler not to clean up compilation artifacts after exiting
    16  }
    17  ```
    18  
    19  The job of a compiler is to compile a directory source files to a raw boot disk image. The behavior of compilers is meant to be independent of providers. Compilers can pass additional information required by providers in the `RawImage` return type, such as what Storage Driver or Network Adapter to use with unikernels created by this compiler. See the [types](../../pkg/types/) package for more about `RawImage`
    20   
    21  Providers must specify what compilers they are compatible with through their `GetConfig()` method. If you've added a compiler to UniK, you should add the compiler's name to the provider's `GetConfig()` method for each provider your compiler is intended to be used with.
    22  
    23  To add compiler support to UniK, you must add the compiler to the `_compilers` map in the Unik API Server constructor function `func NewUnikDaemon(config config.DaemonConfig) (*UnikDaemon, error)` in [`daemon.go`](../pkg/daemon/daemon.go)
    24  
    25  Your change should look something like this:
    26  ```go
    27  func NewUnikDaemon(config config.DaemonConfig) (*UnikDaemon, error) {
    28  	_compilers := make(map[string]compilers.Compiler)
    29    //...
    30    //Add your compiler here, like so:
    31  
    32    myCompiler, err := mycompiler.NewCompiler()
    33    if err != nil {
    34      //handle err
    35    }
    36    _compilers["my_compiler_name"] = myCompiler
    37  
    38    //...
    39    d := &UnikDaemon{
    40      server:    lxmartini.QuietMartini(),
    41      providers: _providers,
    42      compilers: _compilers,
    43    }
    44    return d, nil
    45  }
    46  ```