Skip to content

Commit 940b2a8

Browse files
authored
[hooks] [code_assets] [data_assets] Library documentation and readme (#2479)
This PR adds code snippets and cross links to the library documentation and readmes. (Once dart-lang/site-www#6759 is merged, we can also add links to the hooks page.)
1 parent b9614c3 commit 940b2a8

File tree

13 files changed

+158
-15
lines changed

13 files changed

+158
-15
lines changed

pkgs/code_assets/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.19.6-wip
2+
3+
- Added a library comment detailing how to use the package.
4+
15
## 0.19.5
26

37
- Bump `package:hooks` to 0.20.0.

pkgs/code_assets/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@
66
A library to use in build hooks (`hook/build.dart`) for building and bundling
77
code assets.
88

9+
A code asset is an asset containing executable code which respects the native
10+
application binary interface (ABI).
11+
12+
Code assets can be added in a build hook as follows:
13+
14+
```dart
15+
import 'package:code_assets/code_assets.dart';
16+
import 'package:hooks/hooks.dart';
17+
18+
void main(List<String> args) async {
19+
await build(args, (input, output) async {
20+
final packageName = input.packageName;
21+
final assetPath = input.outputDirectory.resolve('...');
22+
23+
output.assets.code.add(
24+
CodeAsset(
25+
package: packageName,
26+
name: '...',
27+
linkMode: DynamicLoadingBundled(),
28+
file: assetPath,
29+
),
30+
);
31+
});
32+
}
33+
```
34+
35+
For more documentation of hooks, refer to the API docs of
36+
[`package:hooks`](https://pub.dev/packages/hooks).
37+
38+
When compiling C, C++ or Objective-C code from source, consider using
39+
[`package:native_toolchain_c`](https://pub.dev/packages/native_toolchain_c).
40+
941
## Status: In Preview
1042

1143
**NOTE**: This package is currently in preview and published under the

pkgs/code_assets/lib/code_assets.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,44 @@
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 'src/code_assets/code_asset.dart';
6+
/// @docImport 'src/code_assets/config.dart';
7+
58
/// Code asset support for hook authors.
9+
///
10+
/// A code asset is an asset containing executable code which respects the
11+
/// native application binary interface (ABI).
12+
///
13+
/// Code assets can be added in a build hook as follows:
14+
///
15+
/// ```dart
16+
/// import 'package:code_assets/code_assets.dart';
17+
/// import 'package:hooks/hooks.dart';
18+
///
19+
/// void main(List<String> args) async {
20+
/// await build(args, (input, output) async {
21+
/// final packageName = input.packageName;
22+
/// final assetPath = input.outputDirectory.resolve('...');
23+
///
24+
/// output.assets.code.add(
25+
/// CodeAsset(
26+
/// package: packageName,
27+
/// name: '...',
28+
/// linkMode: DynamicLoadingBundled(),
29+
/// file: assetPath,
30+
/// ),
31+
/// );
32+
/// });
33+
/// }
34+
/// ```
35+
///
36+
/// See [CodeAsset] and [BuildOutputCodeAssetBuilder.add] for more details.
37+
///
38+
/// For more documentation of hooks, refer to the API docs of
39+
/// [`package:hooks`](https://pub.dev/packages/hooks).
40+
///
41+
/// When compiling C, C++ or Objective-C code from source, consider using
42+
/// [`package:native_toolchain_c`](https://pub.dev/packages/native_toolchain_c).
643
library;
744

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

pkgs/code_assets/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
This library contains the hook protocol specification for bundling native code
44
with Dart packages.
55
6-
version: 0.19.5
6+
version: 0.19.6-wip
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/code_assets
99

@@ -21,7 +21,7 @@ environment:
2121

2222
dependencies:
2323
collection: ^1.19.1
24-
hooks: ^0.20.0
24+
hooks: ^0.20.1-wip
2525

2626
dev_dependencies:
2727
custom_lint: ^0.7.5

pkgs/data_assets/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.19.3-wip
2+
3+
- Added a library comment detailing how to use the package.
4+
15
## 0.19.2
26

37
- Bump `package:hooks` to 0.20.0.

pkgs/data_assets/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@
66
A library to use in build hooks (`hook/build.dart`) for building and bundling
77
data assets.
88

9+
A data asset is an asset bundled as data (String or bytes) with a Dart or
10+
Flutter application.
11+
12+
Data assets can be added in a build hook as follows:
13+
14+
```dart
15+
import 'package:data_assets/data_assets.dart';
16+
import 'package:hooks/hooks.dart';
17+
///
18+
void main(List<String> args) async {
19+
await build(args, (input, output) async {
20+
final packageName = input.packageName;
21+
final assetPath = input.outputDirectory.resolve('...');
22+
23+
output.assets.data.add(
24+
DataAsset(
25+
package: packageName,
26+
name: '...',
27+
file: assetPath,
28+
),
29+
);
30+
});
31+
}
32+
```
33+
34+
For more documentation of hooks, refer to the API docs of
35+
[`package:hooks`](https://pub.dev/packages/hooks).
36+
937
## Status: Experimental
1038

1139
**NOTE**: This package is currently experimental and published under the

pkgs/data_assets/lib/data_assets.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,40 @@
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 'src/data_assets/config.dart';
6+
/// @docImport 'src/data_assets/data_asset.dart';
7+
58
/// Data asset support for hook authors.
9+
///
10+
/// A data asset is an asset bundled as data (String or bytes) with a Dart or
11+
/// Flutter application.
12+
///
13+
/// Data assets can be added in a build hook as follows:
14+
///
15+
/// ```dart
16+
/// import 'package:data_assets/data_assets.dart';
17+
/// import 'package:hooks/hooks.dart';
18+
///
19+
/// void main(List<String> args) async {
20+
/// await build(args, (input, output) async {
21+
/// final packageName = input.packageName;
22+
/// final assetPath = input.outputDirectory.resolve('...');
23+
///
24+
/// output.assets.data.add(
25+
/// DataAsset(
26+
/// package: packageName,
27+
/// name: '...',
28+
/// file: assetPath,
29+
/// ),
30+
/// );
31+
/// });
32+
/// }
33+
/// ```
34+
///
35+
/// See [DataAsset] and [BuildOutputDataAssetsBuilder.add] for more details.
36+
///
37+
/// For more documentation of hooks, refer to the API docs of
38+
/// [`package:hooks`](https://pub.dev/packages/hooks).
639
library;
740

841
export 'src/data_assets/config.dart'

pkgs/data_assets/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
This library contains the hook protocol specification for bundling data assets
44
with Dart packages.
55
6-
version: 0.19.2
6+
version: 0.19.3-wip
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/data_assets
99

@@ -17,7 +17,7 @@ environment:
1717
sdk: '>=3.9.0-21.0.dev <4.0.0'
1818

1919
dependencies:
20-
hooks: ^0.20.0
20+
hooks: ^0.20.1-wip
2121

2222
dev_dependencies:
2323
custom_lint: ^0.7.5

pkgs/hooks/CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
## 0.20.1-wip
2+
3+
- Update outdated documentation.
4+
15
## 0.20.0
26

3-
* **Breaking change** Rename `EncodedAsset.jsonPath` to
7+
- **Breaking change** Rename `EncodedAsset.jsonPath` to
48
`EncodedAsset.encodingJsonPath`. This field only governs the `EncodedAsset.encoding` field, not the whole object.
5-
* Enable passing metadata from link hooks of a package to the link hooks in
9+
- Enable passing metadata from link hooks of a package to the link hooks in
610
dependencies, by fixing the link hook execution order.
711

812
## 0.19.5
913

10-
* Stop leaking unexported symbols.
14+
- Stop leaking unexported symbols.
1115

1216
## 0.19.4
1317

14-
* Add doc comments to all public members.
18+
- Add doc comments to all public members.
1519

1620
## 0.19.3
1721

18-
* Mark this package as in preview.
22+
- Mark this package as in preview.
1923

2024
## 0.19.1
2125

pkgs/hooks/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
A library to use in build hooks (`hook/build.dart`).
77

8+
For more documentation on adding native code to your package, refer to the API
9+
docs of [`package:code_assets`](https://pub.dev/packages/code_assets).
10+
811
## Status: In Preview
912

1013
**NOTE**: This package is currently in preview and published under the

0 commit comments

Comments
 (0)