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