build_native 0.0.1

  • Example
  • Installing
  • Versions
  • 50


Pub License

Compile native extensions with package:build.

This is a 2-step build process:

  1. Build *.{c,cc,cpp} files to .o.
  2. Link files into a shared library.

Ultimately, to build everything, you will just need to run pub run build_runner build.

The goal of this package is to use existing infrastructure to build native extensions. Eventually, though, it might be nicer to perform builds in an after_install script in a pubspec.yaml.

I've actually submitted at PR to Pub for such functionality, so instant, portable builds of native extensions might be on their way soon.

NOTE: Windows will soon be supported. But not yet. Beware.


build_native requires only very little configuration. However, this means that it can only serve one purpose: invoking the compiler on the user's system.

Source Files

Also, because of the nature of package:build, each input can only create one output. For *.c, *.cc, and *.cpp, files, the system compiler is invoked to create a .o file. To override this, set the CC environment variable when compiling C, or the CXX environment variable when compiling C++.

Files named *.macos.{c,cc,cpp} will only build on Mac. The same applies to linux and windows. This can be used to apply platform-specific settings in your build.

Master Build File

To perform linking, include an <extension_name>.build_native.yaml file in the directory where the extension should be built.

It should contain a list of source files to link together.

The character ! in a path in sources will be replaced with .obj on Windows, and .o everywhere else.

The simplest example:

  - sample_extension!

See example/ for more.

All supported options:

  - "-O2"
  - sample_extension.o
  foo: bar

Platform-Specific Options

To specify options that should only apply to a given platform, add a <extension_name>.<platform_name>.macos.build_native.yaml file, for example, foo_bar.macos.build_native.yaml. This will be merged into the main options.

Platforms available: macos, windows, linux.

By providing this as the PLATFORM environment variable, you can override this.


Save yourself a hassle by running the build within the Visual Studio Developer Command Prompt.

Regardless, executables like cl.exe and link.exe should be available. Otherwise:

To enable a 64-bit toolset:

vcvarsall might be contained in: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build


On Unix, if you some error like this:

fatal error: bits/c++config.h: No such file or directory

Then run:

sudo apt-get install -y gcc-multilib g++-multilib


  • Build individual object files separately.
  • Use a config-based approach to link libraries.
  • Windows support is now broken, but will be added again soon.


// See the contents of `lib/`!!!

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  build_native: "^0.0.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:build_native/build_native.dart';
Version Uploaded Documentation Archive
0.0.1 May 26, 2018 Go to the documentation of build_native 0.0.1 Download build_native 0.0.1 archive
0.0.0 Mar 9, 2017 Go to the documentation of build_native 0.0.0 Download build_native 0.0.0 archive


We analyzed this package on Jun 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.60.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
99 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, other

Primary library: package:build_native/build_native.dart with components: io, isolate, build.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 hints.

    Run dartfmt to format lib/build_native.dart.

    Run dartfmt to format lib/src/models/models.dart.

    Similar analysis of the following files failed:

    • lib/src/models/models.g.dart (hint)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
angel_serialize ^2.0.0 2.0.2
build ^0.12.0 0.12.6
build_config ^0.2.0 0.2.6+2 0.3.0
cli_util ^0.1.3 0.1.3
collection ^1.0.0 1.14.10
package_resolver ^1.0.0 1.0.3
path ^1.0.0 1.6.0
system_info ^0.0.6 0.0.16
yaml ^2.0.0 2.1.14
Transitive dependencies
analyzer 0.32.1
args 1.4.3
async 2.0.7
charcode 1.1.1
convert 2.0.1
crypto 2.0.3
csslib 0.14.4
file_utils 0.0.23
front_end 0.1.1
glob 1.1.5
globbing 0.1.20
html 0.13.3+1
http 0.11.3+16
http_parser 3.1.2
kernel 0.3.1
logging 0.11.3+1
meta 1.1.5
package_config 1.0.3
plugin 0.2.0+2
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+8
Dev dependencies
angel_serialize_generator ^2.0.0
build_runner ^0.8.0