Repository navigation
Closed
Labels
contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)Contributions 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)A good starting issue for contributors (issues with this label will appear in /contribute)package:native_toolchain_c
Description
The CBuilder lists the C sources, but not the header files.
native/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart
Lines 12 to 19 in 952da66
| 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:
- Pass in the
.hfiles to sources, which will add them to the compiler invocation (which is fine for clang-like compiler).- Pro: Clanglike compilers can optimize if we pass the .h files to the compilation step. https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
- Not every compiler might like this. We can work around this by filtering
.hfiles out. - Pro: Similar design to GN/ninja, which also have the c and h files in a flat list.
- Add the header directory to the
includes(ty @blaugold!) - Add a
List<String> headersparameter/field. Which would only resolve the list of paths and add it to theBuildOutputdependencies.- 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.
- Add a
List<String> dependenciesparameter/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
sourcesthat it should include header files. - If needed for some compilers, filtering out
.hfiles in the compiler invocation.
Reacted by Salty Spaghetti and Iván Hernández Cazorla
Metadata
Metadata
Assignees
Labels
contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)Contributions 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)A good starting issue for contributors (issues with this label will appear in /contribute)package:native_toolchain_c
Activity
blaugold commentedon Jul 27, 2024
Just FYI,
includesadds all files that are contained in the provided directories to dependencies. So you could just add the directory with the headers toincludes.native/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart
Lines 66 to 71 in 7efefec
dcharkes commentedon Jul 29, 2024
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.
MiniPiku commentedon Mar 12, 2025
@dcharkes kindly take a look at the changes made
#2098
thank you :)