Skip to content

Commit

Permalink
Merge pull request rust-lang#2315 from ferrous-systems/book-custom-ta…
Browse files Browse the repository at this point in the history
…rget

Add FAQ about custom targets
  • Loading branch information
pvdrz authored Oct 20, 2022
2 parents 68c741d + c2d6f43 commit 61ced32
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion book/src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions)
- [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl)
- [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields)
- [How to generate bindings for a custom target?](#how-to-generate-bindings-for-a-custom-target)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -68,7 +69,7 @@ you're binding to that is pulling in STL headers.
### How to deal with bindgen generated padding fields?
Depending the architecture, toolchain versions and source struct, it is
possible that bindgen will generate padding fields named `__bindgen_padding_N`.
possible that bindgen will generate padding fields named `__bindgen_padding_N`.
As these fields might be present when compiling for one architecture but not
for an other, you should not initialize these fields manually when initializing
the struct. Instead, use the `Default` trait. You can either enable this when
Expand All @@ -95,3 +96,15 @@ SRC_DATA {

In the case bindgen generates a padding field, then this field will
be automatically initialized by `..Default::default()`.

### How to generate bindings for a custom target?

To generate bindings for a custom target you only need to pass the `--target`
argument to `libclang`. For example, if you want to generate bindings for the
`armv7a-none-eabi` target using the command line, you need to invoke `bindgen`
like so:
```bash
$ bindgen <input_headers> -- --target=armv7a-none-eabi
```
If you are using `bindgen` as a library, you should call
`builder.clang_arg("--target=armv7a-none-eabi")` on your `builder`.

0 comments on commit 61ced32

Please sign in to comment.