Skip to content

Replace hand-written FFI imports and C wrappers by automatically generated bindings using clang-bootstrap#39

Merged
jorisdral merged 5 commits into
mainfrom
jdral/clang-bootstrap-diagnostics
Mar 11, 2026
Merged

Replace hand-written FFI imports and C wrappers by automatically generated bindings using clang-bootstrap#39
jorisdral merged 5 commits into
mainfrom
jdral/clang-bootstrap-diagnostics

Conversation

@jorisdral

@jorisdral jorisdral commented Mar 4, 2026

Copy link
Copy Markdown
Member

Resolves #40

@jorisdral
jorisdral force-pushed the jdral/clang-bootstrap-diagnostics branch from 7c857f1 to a3c5822 Compare March 4, 2026 15:53
@jorisdral
jorisdral marked this pull request as ready for review March 4, 2026 16:11
@jorisdral

jorisdral commented Mar 4, 2026

Copy link
Copy Markdown
Member Author

@jorisdral jorisdral changed the title Use clang-bootstrap to generate FFI imports for diagnostic reporting Replace hand-written FFI imports and C wrappers by automatically generated bindings using clang-bootstrap Mar 4, 2026
@jorisdral jorisdral changed the title Replace hand-written FFI imports and C wrappers by automatically generated bindings using clang-bootstrap Replace hand-written FFI imports and C wrappers by automatically generated bindings using clang-bootstrap Mar 4, 2026
@jorisdral
jorisdral marked this pull request as draft March 4, 2026 16:48
@jorisdral

Copy link
Copy Markdown
Member Author

Though the cleanup was originally only targetting the Diagnostics Reporting section of libclang C library, I'm now moving the PR to draft status again so that I can apply the cleanup everywhere

@jorisdral
jorisdral force-pushed the jdral/type_getoffsetof branch from 5a53eff to 2c8f84d Compare March 5, 2026 12:31
@jorisdral
jorisdral force-pushed the jdral/clang-bootstrap-diagnostics branch from a3c5822 to 491b3cb Compare March 5, 2026 12:34
Base automatically changed from jdral/type_getoffsetof to main March 5, 2026 12:51
@jorisdral
jorisdral force-pushed the jdral/clang-bootstrap-diagnostics branch from 491b3cb to 8685a35 Compare March 5, 2026 16:20
We will be replacing these hand-written foreign imports by automatically
generated ones in the `FFI` module. But first we move the hand-written foreign
imports to the `FFI` module so that we get a nice diff that we can inspect for
any discrepancies between the hand-written foreign imports and the (future)
automatically generated foreign imports.
For a nicer diff, we make sure that the foreign imports in the `FFI` module are
sorted according to the order in which we will automatically generate foreign
imports in the future. The sort order is picked to match the
`libclang`/`clang-c` documentation: https://clang.llvm.org/doxygen/topics.html
Again, this is done to improve the diff between the manually written foreign
imports we have now and the automatically generated ones that will replace them.
Not strictly necessary, but useful nonetheless.
@jorisdral
jorisdral force-pushed the jdral/clang-bootstrap-diagnostics branch 2 times, most recently from 95064eb to d6683c5 Compare March 9, 2026 09:56
Comment thread bootstrap/clang-bootstrap.hs
Comment thread bootstrap/clang-bootstrap.hs Outdated
Comment thread bootstrap/clang-bootstrap.hs Outdated
Comment thread src/Clang/LowLevel/Core.hs Outdated
Comment thread src/Clang/LowLevel/Core.hs Outdated
Comment thread src/Clang/LowLevel/Core.hs
Comment thread bootstrap/clang-bootstrap.hs
…rated bindings using `clang-bootstrap

Notable differences in the `foreign imports`

* Use `ConstPtr` rather than `Ptr` for pointer-to-const-qualified-contents
* Use `CUInt` rather than `BitfieldEnum CXDiagnosticDisplayOptions` for
  `unsigned Options`. The `BitfieldEnum` is still used, but at a higher level
  than the raw `foreign import`s.
* `foreign import`s that now use `capi` rather than `ccall`:
  - `nowrapper_parseTranslationUnit`
  - `nowrapper_parseTranslationUnit2`
* `foreign import`s that now use `unsafe` rather than `safe`:
  - `wrap_Location_isFromMainFile`
  - `nowrapper_disposeTranslationUnit`
  - `nowrapper_getTranslationUnitTargetInfo`
  - `nowrapper_TargetInfo_dispose`
  - `wrap_TargetInfo_getTriple`
@jorisdral
jorisdral force-pushed the jdral/clang-bootstrap-diagnostics branch from a731705 to 26048b6 Compare March 11, 2026 09:19
@jorisdral
jorisdral marked this pull request as ready for review March 11, 2026 09:21
@jorisdral
jorisdral added this pull request to the merge queue Mar 11, 2026
Merged via the queue into main with commit d6e482d Mar 11, 2026
11 checks passed
@jorisdral
jorisdral deleted the jdral/clang-bootstrap-diagnostics branch March 11, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace hand-written FFI imports and C wrappers by automatically generated bindings using clang-bootstrap

2 participants