Skip to content

[native_toolchain_c] Changes to header files should be added to the dependencies #1332

Closed

Description

@dcharkes

The CBuilder lists the C sources, but not the header files.

final cbuilder = CBuilder.library(
name: packageName,
assetName: '$packageName.dart',
sources: [
'src/$packageName.c',
],
dartBuildFiles: ['hook/build.dart'],
);

This means the headers are not added to the dependencies. Which means that any changes to the header files do not cause cache invalidation.

Thanks for the feedback @SaltySpaghetti!

Possible solutions:

  1. Pass in the .h files to sources, which will add them to the compiler invocation (which is fine for clang-like compiler).
  2. Add the header directory to the includes (ty @blaugold!)
  3. Add a List<String> headers parameter/field. Which would only resolve the list of paths and add it to the BuildOutput dependencies.
    • Pro: most to the point.
    • Con: if there's other dependencies which are not header files this parameter can be used to shoe-horn these deps in.
  4. Add a List<String> dependencies parameter/field.
  • Con: Is not as discoverable as headers.

I'm leaning towards option 1.

A PR would contain:

  • Updating all example/test projects to include the header files in sources:
  • Adding some documentation to sources that it should include header files.
  • If needed for some compilers, filtering out .h files in the compiler invocation.

Activity

  1. added
    contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)
    good first issueA good starting issue for contributors (issues with this label will appear in /contribute)
    on Jul 12, 2024
  2. blaugold commented on Jul 27, 2024

    @blaugold
    Contributor

    Just FYI, includes adds all files that are contained in the provided directories to dependencies. So you could just add the directory with the headers to includes.

    /// Include directories to pass to the compiler.
    ///
    /// Resolved against [BuildConfig.packageRoot].
    ///
    /// Used to output the [BuildOutput.dependencies].
    final List<String> includes;

  3. dcharkes commented on Jul 29, 2024

    @dcharkes
    CollaboratorAuthor

    Just FYI, includes adds all files that are contained in the provided directories to dependencies. So you could just add the directory with the headers to includes.

    /// Include directories to pass to the compiler.
    ///
    /// Resolved against [BuildConfig.packageRoot].
    ///
    /// Used to output the [BuildOutput.dependencies].
    final List<String> includes;

    Thanks @blaugold!
    If option 1 works though, I believe that option 1 is better. But if there's issues with option 1, than option 2 is a good one too.

  4. MiniPiku commented on Mar 12, 2025

    @MiniPiku

    @dcharkes kindly take a look at the changes made
    #2098
    thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)good first issueA good starting issue for contributors (issues with this label will appear in /contribute)package:native_toolchain_c

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions