github.com/gotranspile/cxgo@v0.3.7/docs/config.md (about)

     1  # Config file reference
     2  
     3  `cxgo` uses a YAML config file called `cxgo.yml`. For a usage example, see [this section](../examples/README.md#using-a-config-file).
     4  
     5  ## `root`
     6  
     7  Specifies the root directory of C source that will be transpiled. All file names in [`files`](#files) are relative to this directory.
     8  
     9  Directory can be specified as a relative path, in which case it will be resolved based on the config file path.
    10  
    11  In case [`vcs`](#vcs) is specified, relative path will be resolved relative to a VCS root (e.g. Git repository root).
    12  
    13  ## `vcs`
    14  
    15  Instead of specifying a local directory with C files, it's also possible to add a Git repository URL.
    16  `cxgo` will automatically clone the project before transpiling.
    17  
    18  See also: [`branch`](#branch), [`root`](#root).
    19  
    20  ## `branch`
    21  
    22  If [`vcs`](#vcs) key is used, specifies the branch which will be cloned.
    23  
    24  ## `out`
    25  
    26  Specifies the output path for Go source files.
    27  
    28  ## `package`
    29  
    30  Specifies the Go package name to use in generated files.
    31  
    32  ## `include`
    33  
    34  A list of include paths used for local header lookups (as in `#include "file.h"`).
    35  
    36  Example:
    37  
    38  ```yaml
    39  include:
    40    - /custom/include/path
    41  ```
    42  
    43  ## `sys_include`
    44  
    45  A list of include paths used for system header lookups (as in `#include <file.h>`).
    46  
    47  Example:
    48  
    49  ```yaml
    50  sys_include:
    51    - /custom/include/path
    52  ```
    53  
    54  ## `define`
    55  
    56  A list of `#define` directives added to all transpiled C files.
    57  
    58  Example:
    59  
    60  ```yaml
    61  define:
    62    - name: CXGO
    63    - name: CXGO_USED
    64      value: 1
    65    - name: VERSION
    66      value: '"dev"'
    67    - name: MYFUNC(x)
    68      value: my_func(&x)
    69  ```
    70  
    71  ## `int_size`
    72  
    73  A size of the C `int` type in bytes. Defaults to a corresponding value for the current `GOARCH` value.
    74  
    75  ## `ptr_size`
    76  
    77  A size of C pointer types in bytes. Defaults to a corresponding value for the current `GOARCH` value.
    78  
    79  ## `wchar_size`
    80  
    81  A size of the `wchar_t` type in bytes. Defaults to `2`.
    82  
    83  ## `use_go_int`
    84  
    85  Use Go `int` and `uint` in place of C `int` and `unsigned int`.
    86  
    87  Defaults to explicit int sizes set by [`int_size`](#int_size) (`int32`, `uint32`).
    88  
    89  ## `skip`
    90  
    91  Specifies a list of names of declarations to skip in all files. It allows removing specific functions/types/variables
    92  from all generated Go files.
    93  
    94  Example:
    95  
    96  ```yaml
    97  skip:
    98    - some_func
    99    - some_type
   100    - some_var
   101  ```
   102  
   103  See also: [`files.skip`](#filesskip).
   104  
   105  ## `replace`
   106  
   107  Specifies a list of replacements applied to all files. See [`files.replace`](#filesreplace).
   108  
   109  ## `implicit_returns`
   110  
   111  Automatically generates implicit returns, which are valid in C.
   112  
   113  Defaults to `false`. This is done to cause a compilation error in Go to let the user decide if he wants to fix C code,
   114  or add this workaround.
   115  
   116  ## `files`
   117  
   118  A list of files to be processed by `cxgo`.
   119  
   120  ### `files.disabled`
   121  
   122  Allows to disable this file, even though it's present in the config.
   123  
   124  ### `files.name`
   125  
   126  Specifies a name of C file to be processed. 
   127  
   128  If `.c` extension is specified, a corresponding `.h` file is also considered.
   129  
   130  Can contain wildcards: `*.c`, `**/*.c`.
   131  
   132  When [`files.content`](#filescontent) is specified, a file will be created in [`out`](#out) instead.
   133  In this case it can have any extension.
   134  
   135  ### `files.go`
   136  
   137  Specifies a corresponding Go file name for this C file. Defaults to `file.go`.
   138  
   139  Example:
   140  
   141  ```yaml
   142  files:
   143    - name: some_file.c
   144      go: custom.go
   145  ```
   146  
   147  ### `files.content`
   148  
   149  If this key is specified, the files is not read from [`root`](#root) and instead is created with a given content in [`out`](#out).
   150  
   151  Useful to automatically create Go files complementary to the generated code.
   152  
   153  Example:
   154  
   155  ```yaml
   156  files:
   157    - name: methods.go
   158      content: |
   159        package lib
   160        
   161        func (c *SomeCType) GetX() int {
   162          // ...
   163        }
   164  ```
   165  
   166  ### `files.max_decl`
   167  
   168  Specifies a maximal number of declarations in a generated Go file. If there are more declarations, Go file will be split
   169  to multiple files (`file_1.go`, `file_2.go`, etc).
   170  
   171  Useful when converting giant C files.
   172  
   173  ### `files.skip`
   174  
   175  Specifies a list of names of declarations to skip in a particular file. It allows removing specific functions/types/variables
   176  from a specific Go file.
   177  
   178  Example:
   179  
   180  ```yaml
   181  files:
   182    - name: file.c
   183      skip:
   184        - some_func
   185        - some_type
   186        - some_var
   187  ```
   188  
   189  See also: [`skip`](#skip).
   190  
   191  ### `files.replace`
   192  
   193  Specifies a list of replacements applied to a particular file. Replacements are done after Go file is generated and formatted.
   194  
   195  Example:
   196  
   197  ```yaml
   198  files:
   199    - name: file.c
   200      replace:
   201        - old: 'asm("x")'
   202          new: 'panic("asm")'
   203        - regexp: 'a\s*b'
   204          new: 'a b'
   205        - old: |
   206            const FOO int32 = 1
   207          new: |
   208            const FOO = 1
   209  ```
   210  
   211  See also [`replace`](#replace).
   212  
   213  ### `files.idents`
   214  
   215  A list of configurations for translating identifiers (functions/types/variables) for a particular file.
   216  See [`idents`](#idents).
   217  
   218  ## `idents`
   219  
   220  A list of configurations for translating identifiers (functions/types/variables), applied to all files.
   221  
   222  ### `idents.name`
   223  
   224  A name of the identifier in C.
   225  
   226  ### `idents.index`
   227  
   228  An index of the identifier in the arguments list. Used only in [`idents.fields`](#identsfields).
   229  
   230  ### `idents.rename`
   231  
   232  Sets a name for this identifier in Go
   233  
   234  Example:
   235  
   236  ```yaml
   237  idents:
   238    - name: some_func
   239      rename: SomeFunc
   240  ```
   241  
   242  ### `idents.alias`
   243  
   244  Use the underlying type in place of this named type. Useful to remove unnecessary types generated from `typedef`.
   245  
   246  It's not the same as Go alias types (`type A = B`). It will not generate the Go alias declaration and will just use
   247  underlying type in all places.
   248  
   249  Example:
   250  
   251  ```yaml
   252  idents:
   253    - name: mytype_t
   254      alias: true
   255  ```
   256  
   257  ### `idents.type`
   258  
   259  Allows overriding Go type for this identifier.
   260  
   261  Valid values are:
   262  - `bool` - uses Go `bool` instead of C `int`
   263  - `string` - uses Go `string` instead of C `char*`
   264  - `slice` - uses Go `[]T` instead of C `T*`
   265  - `iface` - uses Go `interface{}`
   266  
   267  Example:
   268  
   269  ```yaml
   270  idents:
   271    - name: mytype_t
   272      fields:
   273        - name: ptr
   274          type: slice
   275    - name: myfunc
   276      fields:
   277        - name: arg1
   278          type: slice
   279  ```
   280  
   281  ### `idents.flatten`
   282  
   283  Flattens function control flow to workaround invalid gotos.
   284  
   285  Example:
   286  
   287  ```yaml
   288  idents:
   289    - name: myfunc
   290      flatten: true
   291  ```
   292  
   293  ### `idents.fields`
   294  
   295  Allows controlling transpilation of struct fields or function arguments.
   296  
   297  Example:
   298  
   299  ```yaml
   300  idents:
   301    - name: mytype_t
   302      fields:
   303        - name: ptr
   304          type: slice
   305    - name: myfunc
   306      fields:
   307        - name: arg1
   308          type: slice
   309  ```
   310  
   311  ## `exec_before`
   312  
   313  A command to execute before transpiling. Executed in [`root`](#root).
   314  
   315  Example:
   316  
   317  ```yaml
   318  exec_before: ['./configure']
   319  ```
   320  
   321  ## `exec_after`
   322  
   323  A command to execute after transpiling. Executed in [`out`](#out).
   324  
   325  Example:
   326  
   327  ```yaml
   328  exec_after: ['go', 'generate']
   329  ```