Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/code_assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
final cLibrary = CLibrary(
name: 'sqlite3',
assetName: 'src/third_party/sqlite3.g.dart',
sources: ['third_party/sqlite/sqlite3.c'],
sources: ['third_party/sqlite/sqlite3.c', 'third_party/sqlite/sqlite3.h'],
);
```

Expand Down
2 changes: 1 addition & 1 deletion pkgs/code_assets/example/mini_audio/lib/src/c_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
final cLibrary = CLibrary(
name: 'miniaudio',
assetName: 'src/third_party/miniaudio.g.dart',
sources: ['third_party/miniaudio.c'],
sources: ['third_party/miniaudio.c', 'third_party/miniaudio.h'],
);
2 changes: 1 addition & 1 deletion pkgs/code_assets/example/sqlite/lib/src/c_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
final cLibrary = CLibrary(
name: 'sqlite3',
assetName: 'src/third_party/sqlite3.g.dart',
sources: ['third_party/sqlite/sqlite3.c'],
sources: ['third_party/sqlite/sqlite3.c', 'third_party/sqlite/sqlite3.h'],
);
2 changes: 1 addition & 1 deletion pkgs/code_assets/example/sqlite_no_link/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
final builder = CBuilder.library(
name: 'sqlite3',
assetName: 'src/third_party/sqlite3.g.dart',
sources: ['third_party/sqlite/sqlite3.c'],
sources: ['third_party/sqlite/sqlite3.c', 'third_party/sqlite/sqlite3.h'],
);

void main(List<String> args) async {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/code_assets/example/stb_image/lib/src/c_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
final cLibrary = CLibrary(
name: 'stb_image',
assetName: 'src/third_party/stb_image.g.dart',
sources: ['third_party/stb_image.c'],
sources: ['third_party/stb_image.c', 'third_party/stb_image.h'],
);
2 changes: 1 addition & 1 deletion pkgs/code_assets/lib/code_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/// final cLibrary = CLibrary(
/// name: 'sqlite3',
/// assetName: 'src/third_party/sqlite3.g.dart',
/// sources: ['third_party/sqlite/sqlite3.c'],
/// sources: ['third_party/sqlite/sqlite3.c', 'third_party/sqlite/sqlite3.h'],
/// );
/// ```
///
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ app has been created via `dart create ffigen_example`.
final builder = CBuilder.library(
name: 'add',
assetName: 'add.g.dart',
sources: ['src/add.c'],
sources: ['src/add.c', 'src/add.h'],
);
await builder.run(input: input, output: output);
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/example/add/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main(List<String> args) async {
final builder = CBuilder.library(
name: 'add',
assetName: 'add.g.dart',
sources: ['src/add.c'],
sources: ['src/add.c', 'src/add.h'],
);
await builder.run(input: input, output: output);
}
Expand Down
17 changes: 9 additions & 8 deletions pkgs/ffigen/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ void main(List<String> args) async {

// Build all C++ test files. Works on all platforms.
final cppTestDir = input.packageRoot.resolve('test/native_cpp_test/');
final cppFiles = _findFiles(cppTestDir, '.cpp')
.map(
(uri) => p.relative(
uri.toFilePath(),
from: input.packageRoot.toFilePath(),
),
)
.toList();
final cppFiles =
[..._findFiles(cppTestDir, '.cpp'), ..._findFiles(cppTestDir, '.h')]
.map(
(uri) => p.relative(
uri.toFilePath(),
from: input.packageRoot.toFilePath(),
),
)
.toList();
await CBuilder.library(
name: 'cpp_test',
assetName: 'cpp_test',
Expand Down
3 changes: 2 additions & 1 deletion pkgs/hooks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.2.1-wip

- No user-visible changes yet.
- Track header dependencies in the C build examples so header changes trigger
recompilation.

## 2.2.0

Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
final cLibrary = CLibrary(
name: 'sqlite3',
assetName: 'src/third_party/sqlite3.g.dart',
sources: ['third_party/sqlite/sqlite3.c'],
sources: ['third_party/sqlite/sqlite3.c', 'third_party/sqlite/sqlite3.h'],
);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Future<void> runBuild(BuildInput input, BuildOutputBuilder output) async {
final cbuilder = CBuilder.library(
name: name,
assetName: 'native_add.dart',
sources: ['src/native_add.c'],
sources: ['src/native_add.c', 'src/native_add.h'],
);
await cbuilder.run(input: input, output: output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main(List<String> args) async {
final cbuilder = CBuilder.library(
name: packageName,
assetName: '$packageName.dart',
sources: ['src/$packageName.c'],
sources: ['src/$packageName.c', 'src/$packageName.h'],
);
await cbuilder.run(input: input, output: output);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ void main(List<String> args) async {
CBuilder.library(
name: 'debug',
assetName: 'debug',
sources: ['src/debug.c'],
sources: ['src/debug.c', 'src/debug.h'],
),
CBuilder.library(
name: 'math',
assetName: 'math',
sources: ['src/math.c'],
sources: ['src/math.c', 'src/math.h', 'src/debug.h'],
libraries: ['debug'],
),
CBuilder.library(
name: 'add',
assetName: 'add.dart',
sources: ['src/add.c'],
sources: ['src/add.c', 'src/add.h', 'src/math.h'],
libraries: ['math'],
),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Future<void> runBuild(BuildInput input, BuildOutputBuilder output) async {
final cbuilder = CBuilder.library(
name: name,
assetName: 'native_add.dart',
sources: ['src/native_add.c'],
sources: ['src/native_add.c', 'src/native_add.h'],
);
await cbuilder.run(input: input, output: output);
}
Expand Down
11 changes: 10 additions & 1 deletion pkgs/hooks/example/build/use_dart_api/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ void main(List<String> arguments) async {
final cbuilder = CBuilder.library(
name: packageName,
assetName: 'src/${packageName}_bindings_generated.dart',
sources: ['src/$packageName.c', 'src/dart_api_dl.c'],
sources: [
'src/$packageName.c',
'src/$packageName.h',
'src/dart_api_dl.c',
'src/dart_api_dl.h',
'src/dart_api.h',
'src/dart_native_api.h',
'src/dart_version.h',
'src/internal/dart_api_dl_impl.h',
],
);
await cbuilder.run(input: input, output: output);
});
Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks/lib/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/// final cLibrary = CLibrary(
/// name: 'sqlite3',
/// assetName: 'src/third_party/sqlite3.g.dart',
/// sources: ['third_party/sqlite/sqlite3.c'],
/// sources: ['third_party/sqlite/sqlite3.c', 'third_party/sqlite/sqlite3.h'],
/// );
/// ```
///
Expand Down
5 changes: 4 additions & 1 deletion pkgs/hooks/test/example/native_add_library_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void main() async {
final dependencies = buildOutput.dependencies;
expect(assets.length, 1);
expect(await assets.allExist(), true);
expect(dependencies, [testPackageUri.resolve('src/$name.c')]);
expect(dependencies, [
testPackageUri.resolve('src/$name.c'),
testPackageUri.resolve('src/$name.h'),
]);
});
}
5 changes: 5 additions & 0 deletions pkgs/hooks/test/example/native_dynamic_linking_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ void main() async {
expect(await assets.allExist(), true);
expect(dependencies, [
testPackageUri.resolve('src/debug.c'),
testPackageUri.resolve('src/debug.h'),
testPackageUri.resolve('src/math.c'),
testPackageUri.resolve('src/math.h'),
testPackageUri.resolve('src/debug.h'),
testPackageUri.resolve('src/add.c'),
testPackageUri.resolve('src/add.h'),
testPackageUri.resolve('src/math.h'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math .h twice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math.c and add.c both include it, and the dependencies builder doesn't dedupe.

]);
},
);
Expand Down
1 change: 1 addition & 0 deletions pkgs/hooks_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- **Breaking change**: Remove `KernelAssets` (and related `KernelAsset*`
classes) and `Target`.
- Drop regular dependency on `package:code_assets`.
- Track header dependencies in C build test projects.

## 1.6.4

Expand Down
28 changes: 28 additions & 0 deletions pkgs/hooks_runner/test/build_runner/build_runner_caching_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ void main() async {
result.dependencies,
contains(packageUri.resolve('src/native_add.c')),
);
expect(
result.dependencies,
contains(packageUri.resolve('src/native_add.h')),
);

final dependenciesAsPaths = result.dependencies
.map((uri) => uri.toFilePath(windows: false))
Expand Down Expand Up @@ -106,6 +110,30 @@ void main() async {
);
}

{
final headerUri = packageUri.resolve('src/native_add.h');
final headerFile = File.fromUri(headerUri);
await headerFile.writeAsString('${await headerFile.readAsString()}\n');

final logMessages = <String>[];
final result = (await build(
packageUri,
logger,
dartExecutable,
capturedLogs: logMessages,
buildAssetTypes: [.code],
userDefines: userDefines,
)).success;
expect(
logMessages.join('\n'),
stringContainsInOrder([
'Rerunning build for native_add in',
'File contents changed: ${headerUri.toFilePath()}.',
]),
);
expect(result.dependencies, contains(headerUri));
}

{
final pubspecFile = File.fromUri(pubspecUri);
final pubspec = PubspecYamlFileSyntax.fromJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ void main() async {
expect(await assets.allExist(), true);
expect(dependencies, [
testPackageUri.resolve('src/debug.c'),
testPackageUri.resolve('src/debug.h'),
testPackageUri.resolve('src/math.c'),
testPackageUri.resolve('src/math.h'),
testPackageUri.resolve('src/debug.h'),
testPackageUri.resolve('src/add.c'),
testPackageUri.resolve('src/add.h'),
testPackageUri.resolve('src/math.h'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cause.

]);

final addLibraryPath = assets
Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/add_asset_link/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main(List<String> arguments) async {
await CBuilder.library(
name: 'add',
assetName: 'dylib_add_build',
sources: ['src/native_add.c'],
sources: ['src/native_add.c', 'src/native_add.h'],
linkModePreference: LinkModePreference.dynamic,
).run(
input: input,
Expand Down
4 changes: 2 additions & 2 deletions pkgs/hooks_runner/test_data/drop_dylib_link/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ void main(List<String> arguments) async {
await CBuilder.library(
name: 'add',
assetName: 'dylib_add',
sources: ['src/native_add.c'],
sources: ['src/native_add.c', 'src/native_add.h'],
linkModePreference: LinkModePreference.dynamic,
).run(input: input, output: output, routing: routing);

await CBuilder.library(
name: 'multiply',
assetName: 'dylib_multiply',
sources: ['src/native_multiply.c'],
sources: ['src/native_multiply.c', 'src/native_multiply.h'],
linkModePreference: LinkModePreference.dynamic,
).run(input: input, output: output, routing: routing);
});
Expand Down
2 changes: 1 addition & 1 deletion pkgs/hooks_runner/test_data/native_add/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main(List<String> arguments) async {
final cbuilder = CBuilder.library(
name: packageName,
assetName: 'src/${packageName}_bindings_generated.dart',
sources: ['src/$packageName.c'],
sources: ['src/$packageName.c', 'src/$packageName.h'],
);
await cbuilder.run(input: input, output: output);
stdout.writeln('Some stdout.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ void main(List<String> arguments) async {
final cbuilder = CBuilder.library(
name: packageName,
assetName: '${packageName}_bindings_generated.dart',
sources: ['src/$packageName.c', 'src/native_multiply.c'],
sources: [
'src/$packageName.c',
'src/$packageName.h',
'src/native_multiply.c',
'src/native_multiply.h',
],
);
await cbuilder.run(input: input, output: output);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main(List<String> arguments) async {
final cbuilder = CBuilder.library(
name: duplicatedPackageName,
assetName: 'src/${packageName}_bindings_generated.dart',
sources: ['src/$duplicatedPackageName.c'],
sources: ['src/$duplicatedPackageName.c', 'src/$duplicatedPackageName.h'],
);
// Temp output to prevent outputting the dylib for bundling.
final outputBuilder = BuildOutputBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ void main(List<String> args) async {
CBuilder.library(
name: 'debug',
assetName: 'debug',
sources: ['src/debug.c'],
sources: ['src/debug.c', 'src/debug.h'],
buildMode: BuildMode.debug,
),
CBuilder.library(
name: 'math',
assetName: 'math',
sources: ['src/math.c'],
sources: ['src/math.c', 'src/math.h', 'src/debug.h'],
libraries: ['debug'],
buildMode: BuildMode.debug,
),
CBuilder.library(
name: 'add',
assetName: 'add.dart',
sources: ['src/add.c'],
sources: ['src/add.c', 'src/add.h', 'src/math.h'],
libraries: ['math'],
buildMode: BuildMode.debug,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main(List<String> arguments) async {
final cbuilder = CBuilder.library(
name: packageName,
assetName: 'src/${packageName}_bindings_generated.dart',
sources: ['src/$packageName.c'],
sources: ['src/$packageName.c', 'src/$packageName.h'],
);
await cbuilder.run(input: input, output: output);
});
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 builder = CBuilder.library(
name: 'recursive_invocation',
assetName: 'src/recursive_invocation.dart',
sources: ['src/recursive_invocation.c'],
sources: ['src/recursive_invocation.c', 'src/recursive_invocation.h'],
defines: {
if (input.config.code.targetOS == OS.windows)
// Ensure symbols are exported in dll.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main(List<String> args) async {
final builder = CBuilder.library(
name: 'add',
assetName: 'add.dart',
sources: ['src/add.c'],
sources: ['src/add.c', 'src/add.h'],
buildMode: BuildMode.debug,
);

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 builder = CBuilder.library(
name: 'my_add',
assetName: 'my_add.dart',
sources: ['src/my_add.c'],
sources: ['src/my_add.c', 'src/my_add.h'],
libraries: [...addLibrary.libraries],
libraryDirectories: [...addLibrary.libraryDirectories],
includes: [...addLibrary.includes],
Expand Down
Loading
Loading