native_toolchain_xmake 0.1.0
native_toolchain_xmake: ^0.1.0 copied to clipboard
A library to invoke and build Xmake projects for Dart Native Assets.
xmake #
English | 中文
Why xmake instead of CMake? #
- I think it had something to do with how
compile_commands.jsonis generated. - I like commands such as
dart run hello_world. With xmake, I can usexmake run hello_worldin much the same way.
Prerequisites #
1. Install xmake #
dart run native_toolchain_xmake:install
You can also install xmake manually:
-
Windows
irm https://xmake.io/psget.text | iex -
Linux
curl -fsSL https://xmake.io/shget.text | bashOr:
wget https://xmake.io/shget.text -O - | bash -
macOS
brew install xmakeNote
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 #
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',
assetName: 'src/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',
assetName: 'src/project_xmake.g.dart',
).link(
input: input,
output: output,
linkerOptions: .treeshake(
symbolsToKeep: input.recordedUses?.calls.keys.cast<Method>().map(
(e) => recordUseMapping[e.name]!,
),
),
);
});
}
xmake notes #
The xmake workflow is configure → build → install.
Configuration #
Android:
xmake f --plat=android --arch=x86_64 --toolchain=ndk --ndk="C:/Users/<you>/AppData/Local/Android/Sdk/ndk/<version>" --mode=release --kind=shared -y
Windows:
xmake f --plat=windows --arch=x64 --mode=release --kind=shared -y
Development #
For coding agents:
- Keep the English and Chinese READMEs in sync.
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