Skip to content

Commit

Permalink
Remove BuildState
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes committed Jan 23, 2024
1 parent 499feae commit 027fece
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 109 deletions.
2 changes: 1 addition & 1 deletion pkgs/native_assets_cli/lib/native_assets_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
library native_assets_cli;

export 'src/api/asset.dart';
export 'src/api/build.dart';
export 'src/api/build_config.dart';
export 'src/api/build_mode.dart';
export 'src/api/build_output.dart';
export 'src/api/build_state.dart';
export 'src/api/dependencies.dart';
export 'src/api/ios_sdk.dart';
export 'src/api/link_mode.dart';
Expand Down
80 changes: 80 additions & 0 deletions pkgs/native_assets_cli/lib/src/api/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2024, 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 'build_config.dart';
import 'build_output.dart';

/// Run a native assets build.
///
/// Example using `package:native_toolchain_c`:
///
/// ```dart
/// void main(List<String> args) =>
/// build(args, (buildConfig, buildOutput) async {
/// final cbuilder = CBuilder.library(
/// name: packageName,
/// assetId: 'package:$packageName/$packageName.dart',
/// sources: [
/// 'src/$packageName.c',
/// ],
/// );
/// await cbuilder.run(
/// buildConfig: buildConfig,
/// buildOutput: buildOutput,
/// logger: Logger('')
/// ..level = Level.ALL
/// ..onRecord.listen((record) => print(record.message)),
/// );
/// });
/// ```
///
/// Example outputting assets manually:
///
/// ```dart
/// void main(List<String> args) =>
/// build(args, (config, output) async {
/// if (config.linkModePreference == LinkModePreference.static) {
/// // Simulate that this script only supports dynamic libraries.
/// throw UnsupportedError(
/// 'LinkModePreference.static is not supported.',
/// );
/// }
///
/// final Iterable<Target> targets;
/// final packageName = config.packageName;
/// final assetPath = config.outDir.resolve(
/// config.targetOs.dylibFileName(packageName),
/// );
/// if (config.dryRun) {
/// // Dry run invocations report assets for all architectures for that OS.
/// targets = Target.values.where(
/// (element) => element.os == config.targetOs,
/// );
/// } else {
/// targets = [config.target];
///
/// // Insert code that downloads or builds the asset to `assetPath`.
/// }
///
/// for (final target in targets) {
/// output.addAssets([
/// Asset(
/// id: 'library:${packageName}/src/some_file.dart',
/// linkMode: LinkMode.dynamic,
/// target: target,
/// path: AssetAbsolutePath(assetPath),
/// )
/// ]);
/// }
/// });
/// ```
Future<void> build(
List<String> commandlineArguments,
Future<void> Function(BuildConfig, BuildOutput) builder,
) async {
final config = await BuildConfig.fromArgs(commandlineArguments);
final output = BuildOutput();
await builder(config, output);
await output.writeToFile(outDir: config.outDir);
}
108 changes: 0 additions & 108 deletions pkgs/native_assets_cli/lib/src/api/build_state.dart

This file was deleted.

0 comments on commit 027fece

Please sign in to comment.