Library for compiling C/C++ source files from Dart scripts. The main purpose of compiling native extensions from Dart source files. It is also possible to use this to compile any other small projects.


License
Other

Documentation

CCompile is a Tools for compiling C/C++ Dart language native extensions.

This tools is a library written in Dart programming language. It based on ccompilers package and intended to compile C/C++ source files from Dart scripts.

To test how it works run example_build.dart. This will compile simple project called sample_extension.yaml.

This project is a dart native C/C++ extension project.

After compile run example_use_sample_extension.dart. This is a script that import sample_extension.dart that have a native function calls to Dart VM. And sample_extension.dart uses compiled by ccompile binary libraries to work.

If it works then your project will be succesful compiled.

You can compile projects stored in json and yaml formats. Also you can create project via dart language class and compile it.

Here is an example of sample_extension.yaml.

bits: 0 # 0 means the bits of Dart SDK
compiler:
  includes: ['{DART_SDK}/bin', '{DART_SDK}/include']
  input_files:
  - 'sample_extension.cc'
clean: [ '*.exp', '*.lib', '*.o', '*.obj']
linker:
  input_files:
  - 'sample_extension'
platforms:
  linux:
    compiler:
      arguments: ['-fPIC', '-Wall']
    linker:
      arguments: ['-shared']
      output_file: 'libsample_extension.so'
  macos:
    compiler:
      arguments: ['-fPIC', '-Wall']
    linker:
      arguments: ['-dynamiclib', '-undefined', 'dynamic_lookup']
      output_file: 'libsample_extension.dylib'
  windows:
    compiler:
      defines: {'DART_SHARED_LIB':}
      input_files:
      - 'sample_extension_dllmain_win.cc'
    linker:
      arguments: ['/DLL']
      input_files:
      - 'dart.lib'
      - 'sample_extension_dllmain_win'
      libpaths: ['{DART_SDK}/bin']
      output_file: 'sample_extension.dll'

If you want to be more powerful then I can recommend you trying to use ccompilers instead of this.

Example of building a native extension with build_tools.