Skip to content

Commit 1a6faf5

Browse files
authored
Add link.dart hook (#827)
Support a `hook/link.dart` script, which executes after kernel compilation. The SDK changes to make this work are in https://dart-review.googlesource.com/c/sdk/+/338380. The link script receives as input a list of assets produced by `hook/build.dart` scripts. In a `hook/build.dart`, users can specify if an asset should be sent to a link script, and give the name of the package containing that script. All assets destined for a particular link script are collected and given as input. In #1117, the link scripts get as additional input tree shaking information collected during kernel compilation, to enable link scripts to remove or add assets based on usage of symbols in Dart code. --- <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Most changes should add an entry to the changelog and may need to [rev the pubspec package version](https://github.com/dart-lang/sdk/wiki/External-Package-Maintenance#making-a-change). - Changes to packages require [corresponding tests](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md#Testing). Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback. </details>
1 parent a152cfa commit 1a6faf5

File tree

177 files changed

+4258
-1559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+4258
-1559
lines changed

.github/workflows/native.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,34 @@ jobs:
8080
- run: dart pub get -C test_data/package_with_metadata/
8181
if: ${{ matrix.package == 'native_assets_builder' }}
8282

83-
- run: dart pub get -C example/native_add_app/
83+
- run: dart pub get -C test_data/simple_link/
84+
if: ${{ matrix.package == 'native_assets_builder' }}
85+
86+
- run: dart pub get -C test_data/complex_link/
87+
if: ${{ matrix.package == 'native_assets_builder' }}
88+
89+
- run: dart pub get -C test_data/complex_link_helper/
90+
if: ${{ matrix.package == 'native_assets_builder' }}
91+
92+
- run: dart pub get -C test_data/drop_dylib_link/
93+
if: ${{ matrix.package == 'native_assets_builder' }}
94+
95+
- run: dart pub get -C test_data/add_asset_link/
96+
if: ${{ matrix.package == 'native_assets_builder' }}
97+
98+
- run: dart pub get -C example/build/native_add_app/
99+
if: ${{ matrix.package == 'native_assets_cli' }}
100+
101+
- run: dart pub get -C example/build/native_add_library/
102+
if: ${{ matrix.package == 'native_assets_cli' }}
103+
104+
- run: dart pub get -C example/build/use_dart_api/
84105
if: ${{ matrix.package == 'native_assets_cli' }}
85106

86-
- run: dart pub get -C example/native_add_library/
107+
- run: dart pub get -C example/link/package_with_assets/
87108
if: ${{ matrix.package == 'native_assets_cli' }}
88109

89-
- run: dart pub get -C example/use_dart_api/
110+
- run: dart pub get -C example/link/app_with_asset_treeshaking/
90111
if: ${{ matrix.package == 'native_assets_cli' }}
91112

92113
- run: dart analyze --fatal-infos
@@ -103,23 +124,23 @@ jobs:
103124
if: ${{ matrix.sdk == 'stable' }}
104125

105126
- run: dart --enable-experiment=native-assets test
106-
working-directory: pkgs/${{ matrix.package }}/example/native_add_app/
127+
working-directory: pkgs/${{ matrix.package }}/example/build/native_add_app/
107128
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}
108129

109130
- run: dart --enable-experiment=native-assets run
110-
working-directory: pkgs/${{ matrix.package }}/example/native_add_app/
131+
working-directory: pkgs/${{ matrix.package }}/example/build/native_add_app/
111132
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}
112133

113134
- run: dart --enable-experiment=native-assets build bin/native_add_app.dart
114-
working-directory: pkgs/${{ matrix.package }}/example/native_add_app/
135+
working-directory: pkgs/${{ matrix.package }}/example/build/native_add_app/
115136
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}
116137

117138
- run: ./native_add_app.exe
118-
working-directory: pkgs/${{ matrix.package }}/example/native_add_app/bin/native_add_app/
139+
working-directory: pkgs/${{ matrix.package }}/example/build/native_add_app/bin/native_add_app/
119140
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}
120141

121142
- run: dart --enable-experiment=native-assets test
122-
working-directory: pkgs/${{ matrix.package }}/example/use_dart_api/
143+
working-directory: pkgs/${{ matrix.package }}/example/build/use_dart_api/
123144
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}
124145

125146
- name: Install coverage

pkgs/native_assets_builder/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 0.6.1
1+
## 0.7.0-wip
22

33
- Fix test.
4+
- Add support for `hook/link.dart`.
45

56
## 0.6.0
67

pkgs/native_assets_builder/lib/native_assets_builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
export 'package:native_assets_builder/src/build_runner/build_runner.dart';
6+
export 'package:native_assets_builder/src/model/build_result.dart';
7+
export 'package:native_assets_builder/src/model/dry_run_result.dart';
68
export 'package:native_assets_builder/src/model/kernel_assets.dart';
9+
export 'package:native_assets_builder/src/model/link_result.dart';
710
export 'package:native_assets_builder/src/package_layout/package_layout.dart';

pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class NativeAssetsBuildPlanner {
8383
}
8484
}
8585

86+
/// A graph of package dependencies.
87+
///
88+
/// This is encoded as a mapping from package name to list of package
89+
/// dependencies.
8690
class PackageGraph {
8791
final Map<String, List<String>> map;
8892

0 commit comments

Comments
 (0)