Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ffigen] Add Header Files to CBuilder Sources #2098

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ 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',
],
);
await cbuilder.run(
input: input,
Expand Down
1 change: 1 addition & 0 deletions pkgs/native_assets_cli/lib/src/api/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import '../validation.dart';
/// assetName: '$packageName.dart',
/// sources: [
/// 'src/$packageName.c',
/// 'src/$packageName.h',
/// ],
/// );
/// await cbuilder.run(
Expand Down
19 changes: 19 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ import 'output_type.dart';
import 'run_cbuilder.dart';

/// Specification for building an artifact with a C compiler.
///
/// **Note:** When configuring `CBuilder` in your `hook/build.dart`,
/// include both `.c` source files and `.h` header files in the `sources` list.
/// This ensures that changes to header files (e.g., `native_add_library.h`)
/// invalidate the build cache, triggering a rebuild when necessary. For example:
///
/// ```dart
/// final cbuilder = CBuilder.library(
/// name: 'native_add_library',
/// assetName: 'src/native_add_library_bindings_generated.dart',
/// sources: [
/// 'src/native_add_library.c',
/// 'src/native_add_library.h',
/// ],
/// );
/// ```
///
/// This class provides options to define sources, dependencies,
/// and compiler configurations for building C-based native libraries.
class CBuilder extends CTool implements Builder {
/// The dart files involved in building this artifact.
///
Expand Down
7 changes: 7 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ abstract class CTool {
/// Resolved against [LinkInput.packageRoot].
///
/// The sources will be reported as dependencies of the hook.
///
/// This should include both C source files (e.g., `.c`) and header files
/// (e.g., `.h`). Including header files ensures that changes to them
/// invalidate the build cache, triggering recompilation when necessary.
///
/// If a compiler does not support this, the build system may filter `.h` files
/// from the compilation step while still tracking them as dependencies.
final List<String> sources;

/// Include directories to pass to the linker.
Expand Down
Loading