xmake

English | 中文

Why xmake instead of CMake?

  • I think it had something to do with how compile_commands.json is generated.
  • I like commands such as dart run hello_world. With xmake, I can use xmake run hello_world in much the same way.

Prerequisites

1. Install xmake

dart run native_toolchain_xmake:install

This command runs the following platform-specific installers:

  • Windows

    irm https://xmake.io/psget.text | iex
    
  • Linux

    curl -fsSL https://xmake.io/shget.text | bash
    

    Or:

    wget https://xmake.io/shget.text -O - | bash
    
  • macOS

    brew install xmake
    

    Note

    The official Bash installer can result in library lookup errors on macOS.

2. Install Zig for cross-compilation

This package uses Zig by default for cross-compilation. See the Zig installation guide.

  • Windows

    winget install -e --id zig.zig
    
  • macOS

    brew install zig
    

Agent skill

The bundled dart-xmake skill covers native project setup, Dart build hooks, and native tree shaking.

dart run skills@ get -p native_toolchain_xmake

Examples

// build.dart
void main(List<String> args) async {
  await build(args, (input, output) async {
    if (input.config.buildCodeAssets) {
      // Flutter requires this check.
      await XmakeLibrary(
        target: 'project_xmake',
        libHintName: 'project_xmake',
        assetName: 'src/native/project_xmake.g.dart',
      ).build(input: input, output: output);
    }
  });
}
// link.dart
void main(List<String> args) async {
  await link(args, (input, output) async {
    await XmakeLibrary(
      target: 'project_xmake',
      libHintName: 'project_xmake',
      assetName: 'src/native/project_xmake.g.dart',
    ).link(
      input: input,
      output: output,
      symbolsToKeep: input.recordedUses?.calls.keys.cast<Method>().map(
        (e) => recordUseMapping[e.name]!,
      ) ?? recordUseMapping.values,
    );
  });
}

xmake

Development

For coding agents:

  • Keep the English and Chinese READMEs in sync.

Rule development in this repository

The project_xmake and embed examples and their test fixtures use configs = {local_source = true} to read rules from the current checkout. Keep this setting in both the example project and its native package's source project. This is repository development configuration; users only need the published dart_native version. template_adapter keeps the default remote source to test the published version-to-commit mapping.

Issues

Known issue

If the network connection drops while xmake is downloading a tool during debugging, a child process such as curl may keep running and hold files open.

Use the following command to investigate, then stop the affected processes:

xmake -vD