-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathbuild.dart
39 lines (34 loc) · 1.53 KB
/
build.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';
const packageName = 'native_add_library';
/// Implements the protocol from `package:native_assets_cli` by building
/// the C code in `src/` and reporting what native assets it built.
void main(List<String> args) async {
// Parse the build configuration passed to this CLI from Dart or Flutter.
final buildConfig = await BuildConfig.fromArgs(args);
final buildOutput = BuildOutput();
// Configure `package:native_toolchain_c` to build the C code for us.
final cbuilder = CBuilder.library(
name: packageName,
assetId: 'package:$packageName/${packageName}.dart',
sources: [
'src/$packageName.c',
],
);
await cbuilder.run(
buildConfig: buildConfig,
// `package:native_toolchain_c` will output the dynamic or static libraries it built,
// what files it accessed (for caching the build), etc.
buildOutput: buildOutput,
logger: Logger('')
..level = Level.ALL
..onRecord.listen((record) => print(record.message)),
);
// Write the output according to the native assets protocol so that Dart or
// Flutter can find the native assets produced by this script.
await buildOutput.writeToFile(outDir: buildConfig.outDir);
}