cbindgen.toml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. # The language to output bindings in
  2. #
  3. # possible values: "C", "C++", "Cython"
  4. #
  5. # default: "C++"
  6. language = "C"
  7. # Options for wrapping the contents of the header:
  8. # 在文件头部添加的注释信息
  9. # An optional string of text to output at the beginning of the generated file
  10. # default: doesn't emit anything
  11. header = "/* DragonOS's C FFI for rust. This file is licensed under GPLv2 */"
  12. # 在文件尾部添加的信息
  13. # An optional string of text to output at the end of the generated file
  14. # default: doesn't emit anything
  15. # trailer = "/* Text to put at the end of the generated file */"
  16. # An optional name to use as an include guard
  17. # default: doesn't emit an include guard
  18. # include_guard = "mozilla_wr_bindings_h"
  19. # 是否生成一个 `#pragma once`
  20. pragma_once = true
  21. # An optional string of text to output between major sections of the generated
  22. # file as a warning against manual editing
  23. #
  24. # default: doesn't emit anything
  25. autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
  26. # Whether to include a comment with the version of cbindgen used to generate the file
  27. # default: false
  28. # include_version = true
  29. # An optional namespace to output around the generated bindings
  30. # default: doesn't emit a namespace
  31. namespace = "ffi"
  32. # An optional list of namespaces to output around the generated bindings
  33. # default: []
  34. # namespaces = ["mozilla", "wr"]
  35. # An optional list of namespaces to declare as using with "using namespace"
  36. # default: []
  37. # using_namespaces = ["mozilla", "wr"]
  38. # A list of sys headers to #include (with angle brackets)
  39. # default: []
  40. sys_includes = []
  41. # 生成的binding文件要include的头文件
  42. # A list of headers to #include (with quotes)
  43. # default: []
  44. includes = ["stdint.h"]
  45. # Whether cbindgen's default C/C++ standard imports should be suppressed. These
  46. # imports are included by default because our generated headers tend to require
  47. # them (e.g. for uint32_t). Currently, the generated imports are:
  48. #
  49. # * for C: <stdarg.h>, <stdbool.h>, <stdint.h>, <stdlib.h>, <uchar.h>
  50. #
  51. # * for C++: <cstdarg>, <cstdint>, <cstdlib>, <new>, <cassert> (depending on config)
  52. #
  53. # default: false
  54. no_includes = true
  55. # Whether to make a C header C++ compatible.
  56. # These will wrap generated functions into a `extern "C"` block, e.g.
  57. #
  58. # #ifdef __cplusplus
  59. # extern "C" {
  60. # #endif // __cplusplus
  61. #
  62. # // Generated functions.
  63. #
  64. # #ifdef __cplusplus
  65. # } // extern "C"
  66. # #endif // __cplusplus
  67. #
  68. # If the language is not C this option won't have any effect.
  69. #
  70. # default: false
  71. cpp_compat = false
  72. # A list of lines to add verbatim after the includes block
  73. #after_includes = "#define VERSION 1"
  74. # Code Style Options
  75. # The style to use for curly braces
  76. #
  77. # possible values: "SameLine", "NextLine"
  78. #
  79. # default: "SameLine"
  80. braces = "NextLine"
  81. # The desired length of a line to use when formatting lines
  82. # default: 100
  83. line_length = 120
  84. # The amount of spaces to indent by
  85. # default: 2
  86. tab_width = 4
  87. # Include doc comments from Rust as documentation
  88. documentation = true
  89. # How the generated documentation should be commented.
  90. #
  91. # possible values:
  92. # * "c": /* like this */
  93. # * "c99": // like this
  94. # * "c++": /// like this
  95. # * "doxy": like C, but with leading *'s on each line
  96. # * "auto": "c++" if that's the language, "doxy" otherwise
  97. #
  98. # default: "auto"
  99. documentation_style = "doxy"
  100. # How much of the documentation for each item is output.
  101. #
  102. # possible values:
  103. # * "short": Only the first line.
  104. # * "full": The full documentation.
  105. #
  106. # default: "full"
  107. documentation_length = "short"
  108. # Codegen Options
  109. # When generating a C header, the kind of declaration style to use for structs
  110. # or enums.
  111. #
  112. # possible values:
  113. # * "type": typedef struct { ... } MyType;
  114. # * "tag": struct MyType { ... };
  115. # * "both": typedef struct MyType { ... } MyType;
  116. #
  117. # default: "both"
  118. style = "both"
  119. # If this option is true `usize` and `isize` will be converted into `size_t` and `ptrdiff_t`
  120. # instead of `uintptr_t` and `intptr_t` respectively.
  121. usize_is_size_t = true
  122. # A list of substitutions for converting cfg's to ifdefs. cfgs which aren't
  123. # defined here will just be discarded.
  124. #
  125. # e.g.
  126. # `#[cfg(target = "freebsd")] ...`
  127. # becomes
  128. # `#if defined(DEFINE_FREEBSD) ... #endif`
  129. [defines]
  130. "target_os = freebsd" = "DEFINE_FREEBSD"
  131. "feature = serde" = "DEFINE_SERDE"
  132. [export]
  133. # A list of additional items to always include in the generated bindings if they're
  134. # found but otherwise don't appear to be used by the public API.
  135. #
  136. # default: []
  137. include = ["MyOrphanStruct", "MyGreatTypeRename"]
  138. # A list of items to not include in the generated bindings
  139. # default: []
  140. exclude = ["Bad"]
  141. # 生成的内容的前缀
  142. # A prefix to add before the name of every item
  143. # default: no prefix is added
  144. # prefix = "CAPI_"
  145. # Types of items that we'll generate. If empty, then all types of item are emitted.
  146. #
  147. # possible items: (TODO: explain these in detail)
  148. # * "constants":
  149. # * "globals":
  150. # * "enums":
  151. # * "structs":
  152. # * "unions":
  153. # * "typedefs":
  154. # * "opaque":
  155. # * "functions":
  156. #
  157. # default: []
  158. item_types = ["enums", "structs", "opaque", "functions"]
  159. # Whether applying rules in export.rename prevents export.prefix from applying.
  160. #
  161. # e.g. given this toml:
  162. #
  163. # [export]
  164. # prefix = "capi_"
  165. # [export.rename]
  166. # "MyType" = "my_cool_type"
  167. #
  168. # You get the following results:
  169. #
  170. # renaming_overrides_prefixing = true:
  171. # "MyType" => "my_cool_type"
  172. #
  173. # renaming_overrides_prefixing = false:
  174. # "MyType => capi_my_cool_type"
  175. #
  176. # default: false
  177. renaming_overrides_prefixing = true
  178. # Table of name conversions to apply to item names (lhs becomes rhs)
  179. [export.rename]
  180. "MyType" = "my_cool_type"
  181. "my_function" = "BetterFunctionName"
  182. # Table of things to prepend to the body of any struct, union, or enum that has the
  183. # given name. This can be used to add things like methods which don't change ABI,
  184. # mark fields private, etc
  185. [export.pre_body]
  186. "MyType" = """
  187. MyType() = delete;
  188. private:
  189. """
  190. # Table of things to append to the body of any struct, union, or enum that has the
  191. # given name. This can be used to add things like methods which don't change ABI.
  192. [export.body]
  193. "MyType" = """
  194. void cppMethod() const;
  195. """
  196. # Configuration for name mangling
  197. [export.mangle]
  198. # Whether the types should be renamed during mangling, for example
  199. # c_char -> CChar, etc.
  200. rename_types = "PascalCase"
  201. # Whether the underscores from the mangled name should be omitted.
  202. remove_underscores = false
  203. [layout]
  204. # A string that should come before the name of any type which has been marked
  205. # as `#[repr(packed)]`. For instance, "__attribute__((packed))" would be a
  206. # reasonable value if targeting gcc/clang. A more portable solution would
  207. # involve emitting the name of a macro which you define in a platform-specific
  208. # way. e.g. "PACKED"
  209. #
  210. # default: `#[repr(packed)]` types will be treated as opaque, since it would
  211. # be unsafe for C callers to use a incorrectly laid-out union.
  212. packed = "PACKED"
  213. # A string that should come before the name of any type which has been marked
  214. # as `#[repr(align(n))]`. This string must be a function-like macro which takes
  215. # a single argument (the requested alignment, `n`). For instance, a macro
  216. # `#define`d as `ALIGNED(n)` in `header` which translates to
  217. # `__attribute__((aligned(n)))` would be a reasonable value if targeting
  218. # gcc/clang.
  219. #
  220. # default: `#[repr(align(n))]` types will be treated as opaque, since it
  221. # could be unsafe for C callers to use a incorrectly-aligned union.
  222. aligned_n = "ALIGNED"
  223. [fn]
  224. # 函数开头要加入的内容
  225. # An optional prefix to put before every function declaration
  226. # default: no prefix added
  227. # prefix = "WR_START_FUNC"
  228. # 函数声明的结尾要加入的内容
  229. # An optional postfix to put after any function declaration
  230. # default: no postix added
  231. # postfix = "WR_END_FUNC"
  232. # How to format function arguments
  233. #
  234. # possible values:
  235. # * "horizontal": place all arguments on the same line
  236. # * "vertical": place each argument on its own line
  237. # * "auto": only use vertical if horizontal would exceed line_length
  238. #
  239. # default: "auto"
  240. args = "horizontal"
  241. # An optional string that should prefix function declarations which have been
  242. # marked as `#[must_use]`. For instance, "__attribute__((warn_unused_result))"
  243. # would be a reasonable value if targeting gcc/clang. A more portable solution
  244. # would involve emitting the name of a macro which you define in a
  245. # platform-specific way. e.g. "MUST_USE_FUNC"
  246. # default: nothing is emitted for must_use functions
  247. must_use = "MUST_USE_FUNC"
  248. # An optional string that will be used in the attribute position for functions
  249. # that don't return (that return `!` in Rust).
  250. #
  251. # For instance, `__attribute__((noreturn))` would be a reasonable value if
  252. # targeting gcc/clang.
  253. no_return = "NO_RETURN"
  254. # An optional string that, if present, will be used to generate Swift function
  255. # and method signatures for generated functions, for example "CF_SWIFT_NAME".
  256. # If no such macro is available in your toolchain, you can define one using the
  257. # `header` option in cbindgen.toml
  258. # default: no swift_name function attributes are generated
  259. # swift_name_macro = "CF_SWIFT_NAME"
  260. # A rule to use to rename function argument names. The renaming assumes the input
  261. # is the Rust standard snake_case, however it accepts all the different rename_args
  262. # inputs. This means many options here are no-ops or redundant.
  263. #
  264. # possible values (that actually do something):
  265. # * "CamelCase": my_arg => myArg
  266. # * "PascalCase": my_arg => MyArg
  267. # * "GeckoCase": my_arg => aMyArg
  268. # * "ScreamingSnakeCase": my_arg => MY_ARG
  269. # * "None": apply no renaming
  270. #
  271. # technically possible values (that shouldn't have a purpose here):
  272. # * "SnakeCase": apply no renaming
  273. # * "LowerCase": apply no renaming (actually applies to_lowercase, is this bug?)
  274. # * "UpperCase": same as ScreamingSnakeCase in this context
  275. # * "QualifiedScreamingSnakeCase" => same as ScreamingSnakeCase in this context
  276. #
  277. # default: "None"
  278. rename_args = "PascalCase"
  279. # This rule specifies the order in which functions will be sorted.
  280. #
  281. # "Name": sort by the name of the function
  282. # "None": keep order in which the functions have been parsed
  283. #
  284. # default: "None"
  285. sort_by = "Name"
  286. [struct]
  287. # A rule to use to rename struct field names. The renaming assumes the input is
  288. # the Rust standard snake_case, however it acccepts all the different rename_args
  289. # inputs. This means many options here are no-ops or redundant.
  290. #
  291. # possible values (that actually do something):
  292. # * "CamelCase": my_arg => myArg
  293. # * "PascalCase": my_arg => MyArg
  294. # * "GeckoCase": my_arg => mMyArg
  295. # * "ScreamingSnakeCase": my_arg => MY_ARG
  296. # * "None": apply no renaming
  297. #
  298. # technically possible values (that shouldn't have a purpose here):
  299. # * "SnakeCase": apply no renaming
  300. # * "LowerCase": apply no renaming (actually applies to_lowercase, is this bug?)
  301. # * "UpperCase": same as ScreamingSnakeCase in this context
  302. # * "QualifiedScreamingSnakeCase" => same as ScreamingSnakeCase in this context
  303. #
  304. # default: "None"
  305. rename_fields = "PascalCase"
  306. # An optional string that should come before the name of any struct which has been
  307. # marked as `#[must_use]`. For instance, "__attribute__((warn_unused))"
  308. # would be a reasonable value if targeting gcc/clang. A more portable solution
  309. # would involve emitting the name of a macro which you define in a
  310. # platform-specific way. e.g. "MUST_USE_STRUCT"
  311. #
  312. # default: nothing is emitted for must_use structs
  313. must_use = "MUST_USE_STRUCT"
  314. # Whether a Rust type with associated consts should emit those consts inside the
  315. # type's body. Otherwise they will be emitted trailing and with the type's name
  316. # prefixed. This does nothing if the target is C, or if
  317. # [const]allow_static_const = false
  318. #
  319. # default: false
  320. # associated_constants_in_body: false
  321. # Whether to derive a simple constructor that takes a value for every field.
  322. # default: false
  323. derive_constructor = true
  324. # Whether to derive an operator== for all structs
  325. # default: false
  326. derive_eq = false
  327. # Whether to derive an operator!= for all structs
  328. # default: false
  329. derive_neq = false
  330. # Whether to derive an operator< for all structs
  331. # default: false
  332. derive_lt = false
  333. # Whether to derive an operator<= for all structs
  334. # default: false
  335. derive_lte = false
  336. # Whether to derive an operator> for all structs
  337. # default: false
  338. derive_gt = false
  339. # Whether to derive an operator>= for all structs
  340. # default: false
  341. derive_gte = false
  342. [enum]
  343. # A rule to use to rename enum variants, and the names of any fields those
  344. # variants have. This should probably be split up into two separate options, but
  345. # for now, they're the same! See the documentation for `[struct]rename_fields`
  346. # for how this applies to fields. Renaming of the variant assumes that the input
  347. # is the Rust standard PascalCase. In the case of QualifiedScreamingSnakeCase,
  348. # it also assumed that the enum's name is PascalCase.
  349. #
  350. # possible values (that actually do something):
  351. # * "CamelCase": MyVariant => myVariant
  352. # * "SnakeCase": MyVariant => my_variant
  353. # * "ScreamingSnakeCase": MyVariant => MY_VARIANT
  354. # * "QualifiedScreamingSnakeCase": MyVariant => ENUM_NAME_MY_VARIANT
  355. # * "LowerCase": MyVariant => myvariant
  356. # * "UpperCase": MyVariant => MYVARIANT
  357. # * "None": apply no renaming
  358. #
  359. # technically possible values (that shouldn't have a purpose for the variants):
  360. # * "PascalCase": apply no renaming
  361. # * "GeckoCase": apply no renaming
  362. #
  363. # default: "None"
  364. rename_variants = "None"
  365. # Whether an extra "sentinel" enum variant should be added to all generated enums.
  366. # Firefox uses this for their IPC serialization library.
  367. #
  368. # WARNING: if the sentinel is ever passed into Rust, behaviour will be Undefined.
  369. # Rust does not know about this value, and will assume it cannot happen.
  370. #
  371. # default: false
  372. add_sentinel = false
  373. # Whether enum variant names should be prefixed with the name of the enum.
  374. # default: false
  375. prefix_with_name = false
  376. # Whether to emit enums using "enum class" when targeting C++.
  377. # default: true
  378. enum_class = true
  379. # Whether to generate static `::MyVariant(..)` constructors and `bool IsMyVariant()`
  380. # methods for enums with fields.
  381. #
  382. # default: false
  383. derive_helper_methods = false
  384. # Whether to generate `const MyVariant& AsMyVariant() const` methods for enums with fields.
  385. # default: false
  386. derive_const_casts = false
  387. # Whether to generate `MyVariant& AsMyVariant()` methods for enums with fields
  388. # default: false
  389. derive_mut_casts = false
  390. # The name of the macro/function to use for asserting `IsMyVariant()` in the body of
  391. # derived `AsMyVariant()` cast methods.
  392. #
  393. # default: "assert" (but also causes `<cassert>` to be included by default)
  394. cast_assert_name = "MOZ_RELEASE_ASSERT"
  395. # An optional string that should come before the name of any enum which has been
  396. # marked as `#[must_use]`. For instance, "__attribute__((warn_unused))"
  397. # would be a reasonable value if targeting gcc/clang. A more portable solution
  398. # would involve emitting the name of a macro which you define in a
  399. # platform-specific way. e.g. "MUST_USE_ENUM"
  400. #
  401. # Note that this refers to the *output* type. That means this will not apply to an enum
  402. # with fields, as it will be emitted as a struct. `[struct]must_use` will apply there.
  403. #
  404. # default: nothing is emitted for must_use enums
  405. must_use = "MUST_USE_ENUM"
  406. # Whether enums with fields should generate destructors. This exists so that generic
  407. # enums can be properly instantiated with payloads that are C++ types with
  408. # destructors. This isn't necessary for structs because C++ has rules to
  409. # automatically derive the correct constructors and destructors for those types.
  410. #
  411. # Care should be taken with this option, as Rust and C++ cannot
  412. # properly interoperate with eachother's notions of destructors. Also, this may
  413. # change the ABI for the type. Either your destructor-full enums must live
  414. # exclusively within C++, or they must only be passed by-reference between
  415. # C++ and Rust.
  416. #
  417. # default: false
  418. derive_tagged_enum_destructor = false
  419. # Whether enums with fields should generate copy-constructor. See the discussion on
  420. # derive_tagged_enum_destructor for why this is both useful and very dangerous.
  421. #
  422. # default: false
  423. derive_tagged_enum_copy_constructor = false
  424. # Whether enums with fields should generate copy-assignment operators.
  425. #
  426. # This depends on also deriving copy-constructors, and it is highly encouraged
  427. # for this to be set to true.
  428. #
  429. # default: false
  430. derive_tagged_enum_copy_assignment = false
  431. # Whether enums with fields should generate an empty, private destructor.
  432. # This allows the auto-generated constructor functions to compile, if there are
  433. # non-trivially constructible members. This falls in the same family of
  434. # dangerousness as `derive_tagged_enum_copy_constructor` and co.
  435. #
  436. # default: false
  437. private_default_tagged_enum_constructor = false
  438. [const]
  439. # Whether a generated constant can be a static const in C++ mode. I have no
  440. # idea why you would turn this off.
  441. #
  442. # default: true
  443. allow_static_const = true
  444. # Whether a generated constant can be constexpr in C++ mode.
  445. #
  446. # default: true
  447. allow_constexpr = false
  448. # This rule specifies the order in which constants will be sorted.
  449. #
  450. # "Name": sort by the name of the constant
  451. # "None": keep order in which the constants have been parsed
  452. #
  453. # default: "None"
  454. sort_by = "Name"
  455. [macro_expansion]
  456. # Whether bindings should be generated for instances of the bitflags! macro.
  457. # default: false
  458. bitflags = true
  459. # Options for how your Rust library should be parsed
  460. [parse]
  461. # Whether to parse dependent crates and include their types in the output
  462. # default: false
  463. parse_deps = true
  464. # A white list of crate names that are allowed to be parsed. If this is defined,
  465. # only crates found in this list will ever be parsed.
  466. #
  467. # default: there is no whitelist (NOTE: this is the opposite of [])
  468. include = ["webrender", "webrender_traits"]
  469. # A black list of crate names that are not allowed to be parsed.
  470. # default: []
  471. exclude = ["libc"]
  472. # Whether to use a new temporary target directory when running `rustc -Zunpretty=expanded`.
  473. # This may be required for some build processes.
  474. #
  475. # default: false
  476. clean = false
  477. # Which crates other than the top-level binding crate we should generate
  478. # bindings for.
  479. #
  480. # default: []
  481. extra_bindings = ["my_awesome_dep"]
  482. [parse.expand]
  483. # A list of crate names that should be run through `cargo expand` before
  484. # parsing to expand any macros. Note that if a crate is named here, it
  485. # will always be parsed, even if the blacklist/whitelist says it shouldn't be.
  486. #
  487. # default: []
  488. crates = ["euclid"]
  489. # If enabled, use the `--all-features` option when expanding. Ignored when
  490. # `features` is set. For backwards-compatibility, this is forced on if
  491. # `expand = ["euclid"]` shorthand is used.
  492. #
  493. # default: false
  494. all_features = false
  495. # When `all_features` is disabled and this is also disabled, use the
  496. # `--no-default-features` option when expanding.
  497. #
  498. # default: true
  499. default_features = true
  500. # A list of feature names that should be used when running `cargo expand`. This
  501. # combines with `default_features` like in your `Cargo.toml`. Note that the features
  502. # listed here are features for the current crate being built, *not* the crates
  503. # being expanded. The crate's `Cargo.toml` must take care of enabling the
  504. # appropriate features in its dependencies
  505. #
  506. # default: []
  507. features = ["cbindgen"]
  508. [ptr]
  509. # An optional string to decorate all pointers that are
  510. # required to be non null. Nullability is inferred from the Rust type: `&T`,
  511. # `&mut T` and `NonNull<T>` all require a valid pointer value.
  512. non_null_attribute = "_Nonnull"
  513. # Options specific to Cython bindings.