Skip to content

Commit

Permalink
Add link.dart hook (#827)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mosuem authored May 8, 2024
1 parent a152cfa commit 1a6faf5
Show file tree
Hide file tree
Showing 177 changed files with 4,258 additions and 1,559 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,34 @@ jobs:
- run: dart pub get -C test_data/package_with_metadata/
if: ${{ matrix.package == 'native_assets_builder' }}

- run: dart pub get -C example/native_add_app/
- run: dart pub get -C test_data/simple_link/
if: ${{ matrix.package == 'native_assets_builder' }}

- run: dart pub get -C test_data/complex_link/
if: ${{ matrix.package == 'native_assets_builder' }}

- run: dart pub get -C test_data/complex_link_helper/
if: ${{ matrix.package == 'native_assets_builder' }}

- run: dart pub get -C test_data/drop_dylib_link/
if: ${{ matrix.package == 'native_assets_builder' }}

- run: dart pub get -C test_data/add_asset_link/
if: ${{ matrix.package == 'native_assets_builder' }}

- run: dart pub get -C example/build/native_add_app/
if: ${{ matrix.package == 'native_assets_cli' }}

- run: dart pub get -C example/build/native_add_library/
if: ${{ matrix.package == 'native_assets_cli' }}

- run: dart pub get -C example/build/use_dart_api/
if: ${{ matrix.package == 'native_assets_cli' }}

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

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

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

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

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

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

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

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

- name: Install coverage
Expand Down
3 changes: 2 additions & 1 deletion pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.6.1
## 0.7.0-wip

- Fix test.
- Add support for `hook/link.dart`.

## 0.6.0

Expand Down
3 changes: 3 additions & 0 deletions pkgs/native_assets_builder/lib/native_assets_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

export 'package:native_assets_builder/src/build_runner/build_runner.dart';
export 'package:native_assets_builder/src/model/build_result.dart';
export 'package:native_assets_builder/src/model/dry_run_result.dart';
export 'package:native_assets_builder/src/model/kernel_assets.dart';
export 'package:native_assets_builder/src/model/link_result.dart';
export 'package:native_assets_builder/src/package_layout/package_layout.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class NativeAssetsBuildPlanner {
}
}

/// A graph of package dependencies.
///
/// This is encoded as a mapping from package name to list of package
/// dependencies.
class PackageGraph {
final Map<String, List<String>> map;

Expand Down
Loading

0 comments on commit 1a6faf5

Please sign in to comment.