Skip to content

Commit 64e0f53

Browse files
committed
[hooks] [code_assets] Library dartdoc comments
1 parent c76ea57 commit 64e0f53

File tree

3 files changed

+98
-12
lines changed

3 files changed

+98
-12
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// ignore_for_file: unused_local_variable
6+
7+
// snippet-start
8+
import 'package:code_assets/code_assets.dart';
9+
import 'package:hooks/hooks.dart';
10+
11+
void main(List<String> args) async {
12+
await build(args, (input, output) async {
13+
if (input.config.buildCodeAssets) {
14+
final codeConfig = input.config.code;
15+
final targetOS = codeConfig.targetOS;
16+
final targetArchitecture = codeConfig.targetArchitecture;
17+
18+
// Add some code assets.
19+
}
20+
});
21+
}
22+
23+
// snippet-end

pkgs/code_assets/lib/code_assets.dart

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
/// @docImport 'package:hooks/hooks.dart';
56
/// @docImport 'src/code_assets/code_asset.dart';
67
/// @docImport 'src/code_assets/config.dart';
78
8-
/// Code asset support for hook authors.
9+
/// This package provides the API for code assets to be used with
10+
/// [`package:hooks`](https://pub.dev/packages/hooks).
11+
///
12+
/// A [CodeAsset] is an asset containing executable code which respects the
13+
/// native application binary interface (ABI). These assets are bundled with a
14+
/// Dart or Flutter application. They can be produced by compiling C, C++,
15+
/// Objective-C, Rust, or Go code for example.
916
///
10-
/// A code asset is an asset containing executable code which respects the
11-
/// native application binary interface (ABI).
17+
/// This package is used in a build hook (`hook/build.dart`) to inform the Dart
18+
/// and Flutter SDKs about the code assets that need to be bundled with an
19+
/// application.
1220
///
13-
/// Code assets can be added in a build hook as follows:
21+
/// [CodeAsset] can be added to the [BuildOutputBuilder] a build hook as
22+
/// follows:
1423
///
1524
/// <!-- file://./../example/api/code_assets_snippet.dart -->
1625
/// ```dart
@@ -34,13 +43,31 @@
3443
/// }
3544
/// ```
3645
///
37-
/// See [CodeAsset] and [BuildOutputCodeAssetBuilder.add] for more details.
46+
/// The [CodeConfig] nested in the [HookInput] gives access to configuration
47+
/// specifically for compiling code assets. For example [CodeConfig.targetOS]
48+
/// and [CodeConfig.targetArchitecture] give access to the target OS and
49+
/// architecture that the code assets are compiled for:
3850
///
39-
/// For more documentation of hooks, refer to the API docs of
40-
/// [`package:hooks`](https://pub.dev/packages/hooks).
51+
/// <!-- file://./../example/api/code_config_snippet.dart -->
52+
/// ```dart
53+
/// import 'package:code_assets/code_assets.dart';
54+
/// import 'package:hooks/hooks.dart';
55+
///
56+
/// void main(List<String> args) async {
57+
/// await build(args, (input, output) async {
58+
/// if (input.config.buildCodeAssets) {
59+
/// final codeConfig = input.config.code;
60+
/// final targetOS = codeConfig.targetOS;
61+
/// final targetArchitecture = codeConfig.targetArchitecture;
62+
///
63+
/// // Add some code assets.
64+
/// }
65+
/// });
66+
/// }
67+
/// ```
4168
///
42-
/// When compiling C, C++ or Objective-C code from source, consider using
43-
/// [`package:native_toolchain_c`](https://pub.dev/packages/native_toolchain_c).
69+
/// For more information about build hooks see
70+
/// [dart.dev/tools/hooks](https://dart.dev/tools/hooks).
4471
library;
4572

4673
export 'src/code_assets/architecture.dart' show Architecture;

pkgs/hooks/lib/hooks.dart

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,46 @@
44

55
/// @docImport 'src/api/build_and_link.dart';
66
7-
/// A library that contains the protocol for implementing hooks.
7+
/// This package provides the API for hooks in Dart. Hooks are Dart scripts
8+
/// placed in the `hook/` directory of a Dart package, designed to automate
9+
/// tasks for a Dart package.
810
///
9-
/// The main entrypoint for build hooks (`hook/build.dart`) is [build]. The main
10-
/// entrypoint for link hooks (`hook/link.dart`) is [link].
11+
/// Currently, the main supported hook is the build hook (`hook/build.dart`).
12+
/// The build hook is executed during a Dart build and enables you to bundle
13+
/// assets with a Dart package. The main entrypoint for build hooks is [build].
14+
///
15+
/// The second hook available in this API is the link hook (`hook/link.dart`).
16+
/// The main entrypoint for link hooks is [link].
17+
///
18+
/// Hooks can for example be used to bundle native code with a Dart package:
19+
///
20+
/// <!-- file://./../../code_assets/example/sqlite/hook/build.dart -->
21+
/// ```dart
22+
/// import 'package:code_assets/code_assets.dart';
23+
/// import 'package:hooks/hooks.dart';
24+
/// import 'package:native_toolchain_c/native_toolchain_c.dart';
25+
///
26+
/// void main(List<String> args) async {
27+
/// await build(args, (input, output) async {
28+
/// if (input.config.buildCodeAssets) {
29+
/// final builder = CBuilder.library(
30+
/// name: 'sqlite3',
31+
/// assetName: 'src/third_party/sqlite3.g.dart',
32+
/// sources: ['third_party/sqlite/sqlite3.c'],
33+
/// defines: {
34+
/// if (input.config.code.targetOS == OS.windows)
35+
/// // Ensure symbols are exported in dll.
36+
/// 'SQLITE_API': '__declspec(dllexport)',
37+
/// },
38+
/// );
39+
/// await builder.run(input: input, output: output);
40+
/// }
41+
/// });
42+
/// }
43+
/// ```
44+
///
45+
/// For more information see
46+
/// [dart.dev/tools/hooks](https://dart.dev/tools/hooks).
1147
library;
1248

1349
export 'src/api/build_and_link.dart' show build, link;

0 commit comments

Comments
 (0)