Skip to content

Commit

Permalink
[native_assets_cli] BuildOutput dependencies per asset and asset type
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes committed Jul 23, 2024
1 parent 4423654 commit 8d453f2
Show file tree
Hide file tree
Showing 44 changed files with 737 additions and 200 deletions.
2 changes: 2 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
`LinkConfig.dependencies` no longer have to specify Dart sources.
- `DataAsset` test projects report all assets from `assets/` dir and default the
asset names to the path inside the package.
- Test projects now report their dependencies per asset. And added one test
project with the old protocol still reporting flat dependencies.

## 0.8.1

Expand Down
34 changes: 0 additions & 34 deletions pkgs/native_assets_builder/test/build_runner/v1_0_0_test.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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 'package:test/test.dart';

import '../helpers.dart';
import 'helpers.dart';

const Timeout longTimeout = Timeout(Duration(minutes: 5));

void main() async {
for (final version in ['v1_0_0', 'v1_5_0']) {
test('native_add build $version', timeout: longTimeout, () async {
await inTempDir((tempUri) async {
await copyTestProjects(targetUri: tempUri);
final packageUri = tempUri.resolve('native_add_$version/');

// First, run `pub get`, we need pub to resolve our dependencies.
await runPubGet(
workingDirectory: packageUri,
logger: logger,
);

{
final result = await build(
packageUri,
logger,
dartExecutable,
);
expect(result.assets.length, 1);
}
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void main(List<String> arguments) async {
architecture: builtDylib.architecture,
file: builtDylib.file,
),
)
..addDependency(config.packageRoot.resolve('hook/link.dart'));
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main(List<String> args) async {
final assetDirectory =
Directory.fromUri(config.packageRoot.resolve('assets/'));
// If assets are added, rerun hook.
output.addDependency(assetDirectory.uri);
output.addAssetTypeDependency(DataAsset.type, assetDirectory.uri);

await for (final dataAsset in assetDirectory.list()) {
if (dataAsset is! File) {
Expand All @@ -31,10 +31,8 @@ void main(List<String> args) async {
file: dataAsset.uri,
),
linkInPackage: config.linkingEnabled ? packageName : null,
dependencies: [dataAsset.uri],
);
// TODO(https://github.com/dart-lang/native/issues/1208): Report
// dependency on asset.
output.addDependency(dataAsset.uri);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main(List<String> args) async {
final assetDirectory =
Directory.fromUri(config.packageRoot.resolve('assets/'));
// If assets are added, rerun hook.
output.addDependency(assetDirectory.uri);
output.addAssetTypeDependency(DataAsset.type, assetDirectory.uri);

await for (final dataAsset in assetDirectory.list()) {
if (dataAsset is! File) {
Expand All @@ -33,10 +33,8 @@ void main(List<String> args) async {
),
linkInPackage:
forLinking && config.linkingEnabled ? 'complex_link' : null,
dependencies: [dataAsset.uri],
);
// TODO(https://github.com/dart-lang/native/issues/1208): Report
// dependency on asset.
output.addDependency(dataAsset.uri);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ Received ${config.assets.length} assets: ${config.assets.map((e) => e.id)}.
print('''
Keeping only ${output.assets.map((e) => e.id)}.
''');
output.addDependency(config.packageRoot.resolve('hook/link.dart'));
});
}
8 changes: 8 additions & 0 deletions pkgs/native_assets_builder/test_data/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
- native_add_v1_0_0/pubspec.yaml
- native_add_v1_0_0/src/native_add.c
- native_add_v1_0_0/src/native_add.h
- native_add_v1_5_0/ffigen.yaml
- native_add_v1_5_0/hook/build.dart
- native_add_v1_5_0/lib/native_add.dart
- native_add_v1_5_0/lib/src/native_add_bindings_generated.dart
- native_add_v1_5_0/lib/src/native_add.dart
- native_add_v1_5_0/pubspec.yaml
- native_add_v1_5_0/src/native_add.c
- native_add_v1_5_0/src/native_add.h
- native_add/ffigen.yaml
- native_add/hook/build.dart
- native_add/lib/native_add.dart
Expand Down
20 changes: 20 additions & 0 deletions pkgs/native_assets_builder/test_data/native_add_v1_5_0/ffigen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Run with `flutter pub run ffigen --config ffigen.yaml`.
name: NativeAddBindings
description: |
Bindings for `src/native_add.h`.
Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
output: "lib/src/native_add_bindings_generated.dart"
headers:
entry-points:
- "src/native_add.h"
include-directives:
- "src/native_add.h"
preamble: |
// Copyright (c) 2023, 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.
comments:
style: any
length: full
ffi-native:
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023, 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 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';

void main(List<String> arguments) async {
await build(arguments, (config, output) async {
final packageName = config.packageName;
final cbuilder = CBuilder.library(
name: packageName,
assetName: 'src/${packageName}_bindings_generated.dart',
sources: [
'src/$packageName.c',
],
);
await cbuilder.run(
config: config,
output: output,
logger: Logger('')
..level = Level.ALL
..onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
}),
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2023, 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.

export 'src/native_add.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2023, 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 'native_add_bindings_generated.dart' as bindings;

int add(int a, int b) => bindings.add(a, b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2023, 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.

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
import 'dart:ffi' as ffi;

@ffi.Native<ffi.Int32 Function(ffi.Int32, ffi.Int32)>(symbol: 'add')
external int add(
int a,
int b,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- ffigen.yaml
- hook/build.dart
- lib/native_add.dart
- lib/src/native_add_bindings_generated.dart
- lib/src/native_add.dart
- pubspec.yaml
- src/native_add.c
- src/native_add.h
- test/native_add_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: native_add
description: Sums two numbers with native code.
version: 0.1.0

publish_to: none

environment:
sdk: '>=3.3.0 <4.0.0'

dependencies:
logging: ^1.1.1
native_assets_cli: ^0.7.1
native_toolchain_c: ^0.5.2

dev_dependencies:
ffigen: ^8.0.2
lints: ^3.0.0
some_dev_dep:
path: ../some_dev_dep/
test: ^1.23.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2023, 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.

#include "native_add.h"

int32_t add(int32_t a, int32_t b) {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2023, 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.

#include <stdint.h>

#if _WIN32
#define MYLIB_EXPORT __declspec(dllexport)
#else
#define MYLIB_EXPORT
#endif

MYLIB_EXPORT int32_t add(int32_t a, int32_t b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2023, 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 'package:native_add/native_add.dart';
import 'package:test/test.dart';

void main() {
test('native add test', () {
final result = add(4, 6);
expect(result, equals(10));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ void main(List<String> arguments) async {
output.addAssets(
config.assets,
);
output.addDependency(
config.packageRoot.resolve('hook/link.dart'),
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main(List<String> args) async {
final assetDirectory =
Directory.fromUri(config.packageRoot.resolve('assets/'));
// If assets are added, rerun hook.
output.addDependency(assetDirectory.uri);
output.addAssetTypeDependency(DataAsset.type, assetDirectory.uri);

await for (final dataAsset in assetDirectory.list()) {
if (dataAsset is! File) {
Expand All @@ -30,10 +30,8 @@ void main(List<String> args) async {
name: name,
file: dataAsset.uri,
),
dependencies: [dataAsset.uri],
);
// TODO(https://github.com/dart-lang/native/issues/1208): Report
// dependency on asset.
output.addDependency(dataAsset.uri);
}
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main(List<String> args) async {
final assetDirectory =
Directory.fromUri(config.packageRoot.resolve('assets/'));
// If assets are added, rerun hook.
output.addDependency(assetDirectory.uri);
output.addAssetTypeDependency(DataAsset.type, assetDirectory.uri);

await for (final dataAsset in assetDirectory.list()) {
if (dataAsset is! File) {
Expand All @@ -31,10 +31,8 @@ void main(List<String> args) async {
file: dataAsset.uri,
),
linkInPackage: config.linkingEnabled ? packageName : null,
dependencies: [dataAsset.uri],
);
// TODO(https://github.com/dart-lang/native/issues/1208): Report
// dependency on asset.
output.addDependency(dataAsset.uri);
}
});
}
5 changes: 4 additions & 1 deletion pkgs/native_assets_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## 0.7.3-wip
## 0.8.0-wip

- **Breaking change** `BuildConfig.dependencies` is now per asset and asset
type instead of a flat list.
- Fix some more cases of: `BuildConfig.dependencies` and
`LinkConfig.dependencies` no longer have to specify Dart sources.
- `DataAsset` examples report all assets from `assets/` dir and default the
asset names to the path inside the package.


## 0.7.2

- Deprecate metadata concept.
Expand Down
Loading

0 comments on commit 8d453f2

Please sign in to comment.