Repository: rust-lang/rust-bindgen
Pull request #2749 (2024-02-05 20:36:24)

Fix several typos
Hi there. I noticed a typo when reviewing options. Fixed that one plus a few others I searched for.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 94b19f56..95b7ac29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -204,6 +204,7 @@
 # Unreleased
 ## Added
 ## Changed
+- Add target mappings for riscv64imac and riscv32imafc.
 ## Removed
 ## Fixed
 ## Security
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index ce4a3200..7021f865 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -279,7 +279,7 @@ fn setup_wrap_static_fns_test() {
 
     bindings
         .write_to_file(out_rust_file)
-        .expect("Cound not write bindings to the Rust file");
+        .expect("Could not write bindings to the Rust file");
 }
 
 fn main() {
diff --git a/bindgen/clang.rs b/bindgen/clang.rs
index 4a4ed89d..a9a0ec81 100644
--- a/bindgen/clang.rs
+++ b/bindgen/clang.rs
@@ -874,7 +874,7 @@ impl Cursor {
         unsafe { clang_getCXXAccessSpecifier(self.x) }
     }
 
-    /// Is the cursor's referrent publically accessible in C++?
+    /// Is the cursor's referent publically accessible in C++?
     ///
     /// Returns true if self.access_specifier() is `CX_CXXPublic` or
     /// `CX_CXXInvalidAccessSpecifier`.
diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs
index 9765a8bd..7f00f809 100644
--- a/bindgen/codegen/serialize.rs
+++ b/bindgen/codegen/serialize.rs
@@ -81,7 +81,7 @@ impl<'a> CSerialize<'a> for Function {
 
         let name = self.name();
 
-        // Function argoments stored as `(name, type_id)` tuples.
+        // Function arguments stored as `(name, type_id)` tuples.
         let args = {
             let mut count = 0;
 
diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs
index d085f5c5..9165f3d3 100644
--- a/bindgen/ir/annotations.rs
+++ b/bindgen/ir/annotations.rs
@@ -8,7 +8,7 @@ use std::str::FromStr;
 
 use crate::clang;
 
-/// What kind of visibility modifer should be used for a struct or field?
+/// What kind of visibility modifier should be used for a struct or field?
 #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
 pub enum FieldVisibilityKind {
     /// Fields are marked as private, i.e., struct Foo {bar: bool}
diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs
index fed6ba8a..bd4d0162 100644
--- a/bindgen/ir/comp.rs
+++ b/bindgen/ir/comp.rs
@@ -147,7 +147,7 @@ pub(crate) trait FieldMethods {
     /// If this is a bitfield, how many bits does it need?
     fn bitfield_width(&self) -> Option<u32>;
 
-    /// Is this feild declared public?
+    /// Is this field declared public?
     fn is_public(&self) -> bool;
 
     /// Get the annotations for this field.
diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs
index 517d3365..f13f34ab 100644
--- a/bindgen/ir/context.rs
+++ b/bindgen/ir/context.rs
@@ -36,7 +36,7 @@ use std::mem;
 #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)]
 pub(crate) struct ItemId(usize);
 
-/// Declare a newtype around `ItemId` with convesion methods.
+/// Declare a newtype around `ItemId` with conversion methods.
 macro_rules! item_id_newtype {
     (
         $( #[$attr:meta] )*
diff --git a/bindgen/ir/item_kind.rs b/bindgen/ir/item_kind.rs
index e8618498..9221b505 100644
--- a/bindgen/ir/item_kind.rs
+++ b/bindgen/ir/item_kind.rs
@@ -26,7 +26,7 @@ pub(crate) enum ItemKind {
 }
 
 impl ItemKind {
-    /// Get a reference to this `ItemKind`'s underying `Module`, or `None` if it
+    /// Get a reference to this `ItemKind`'s underlying `Module`, or `None` if it
     /// is some other kind.
     pub(crate) fn as_module(&self) -> Option<&Module> {
         match *self {
@@ -50,7 +50,7 @@ impl ItemKind {
         self.as_module().is_some()
     }
 
-    /// Get a reference to this `ItemKind`'s underying `Function`, or `None` if
+    /// Get a reference to this `ItemKind`'s underlying `Function`, or `None` if
     /// it is some other kind.
     pub(crate) fn as_function(&self) -> Option<&Function> {
         match *self {
@@ -64,13 +64,13 @@ impl ItemKind {
         self.as_function().is_some()
     }
 
-    /// Get a reference to this `ItemKind`'s underying `Function`, or panic if
+    /// Get a reference to this `ItemKind`'s underlying `Function`, or panic if
     /// it is some other kind.
     pub(crate) fn expect_function(&self) -> &Function {
         self.as_function().expect("Not a function")
     }
 
-    /// Get a reference to this `ItemKind`'s underying `Type`, or `None` if
+    /// Get a reference to this `ItemKind`'s underlying `Type`, or `None` if
     /// it is some other kind.
     pub(crate) fn as_type(&self) -> Option<&Type> {
         match *self {
@@ -79,7 +79,7 @@ impl ItemKind {
         }
     }
 
-    /// Get a mutable reference to this `ItemKind`'s underying `Type`, or `None`
+    /// Get a mutable reference to this `ItemKind`'s underlying `Type`, or `None`
     /// if it is some other kind.
     pub(crate) fn as_type_mut(&mut self) -> Option<&mut Type> {
         match *self {
@@ -93,13 +93,13 @@ impl ItemKind {
         self.as_type().is_some()
     }
 
-    /// Get a reference to this `ItemKind`'s underying `Type`, or panic if it is
+    /// Get a reference to this `ItemKind`'s underlying `Type`, or panic if it is
     /// some other kind.
     pub(crate) fn expect_type(&self) -> &Type {
         self.as_type().expect("Not a type")
     }
 
-    /// Get a reference to this `ItemKind`'s underying `Var`, or `None` if it is
+    /// Get a reference to this `ItemKind`'s underlying `Var`, or `None` if it is
     /// some other kind.
     pub(crate) fn as_var(&self) -> Option<&Var> {
         match *self {
diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs
index 93d8b3bf..d7f7cc65 100644
--- a/bindgen/ir/objc.rs
+++ b/bindgen/ir/objc.rs
@@ -39,7 +39,7 @@ pub(crate) struct ObjCInterface {
     /// The direct parent for this interface.
     pub(crate) parent_class: Option<ItemId>,
 
-    /// List of the methods defined in this interfae
+    /// List of the methods defined in this interface
     methods: Vec<ObjCMethod>,
 
     class_methods: Vec<ObjCMethod>,
@@ -137,7 +137,7 @@ impl ObjCInterface {
                 CXCursor_ObjCClassRef => {
                     if cursor.kind() == CXCursor_ObjCCategoryDecl {
                         // We are actually a category extension, and we found the reference
-                        // to the original interface, so name this interface approriately
+                        // to the original interface, so name this interface appropriately
                         interface.name = c.spelling();
                         interface.category = Some(cursor.spelling());
                     }
diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs
index b7a42932..2a24dd02 100644
--- a/bindgen/ir/ty.rs
+++ b/bindgen/ir/ty.rs
@@ -252,7 +252,7 @@ impl Type {
         Cow::Owned(name)
     }
 
-    /// Get this type's santizied name.
+    /// Get this type's sanitized name.
     pub(crate) fn sanitized_name<'a>(
         &'a self,
         ctx: &BindgenContext,
@@ -498,7 +498,7 @@ fn is_invalid_type_param_invalid_start() {
 }
 
 #[test]
-fn is_invalid_type_param_invalid_remaing() {
+fn is_invalid_type_param_invalid_remaining() {
     let ty = Type::new(Some("foo-".into()), None, TypeKind::TypeParam, false);
     assert!(ty.is_invalid_type_param())
 }
@@ -1092,7 +1092,7 @@ impl Type {
                         Item::from_ty_or_ref(inner, location, None, ctx);
                     if inner_id == potential_id {
                         warn!(
-                            "Generating oqaque type instead of self-referential \
+                            "Generating opaque type instead of self-referential \
                             typedef");
                         // This can happen if we bail out of recursive situations
                         // within the clang parsing.
diff --git a/bindgen/lib.rs b/bindgen/lib.rs
index c4ab1148..c2df8a8a 100644
--- a/bindgen/lib.rs
+++ b/bindgen/lib.rs
@@ -144,7 +144,7 @@ impl CodegenConfig {
         self.contains(CodegenConfig::VARS)
     }
 
-    /// Returns true if methds should be generated.
+    /// Returns true if methods should be generated.
     pub fn methods(self) -> bool {
         self.contains(CodegenConfig::METHODS)
     }
@@ -695,6 +695,11 @@ fn rust_to_clang_target(rust_target: &str) -> Box<str> {
         let mut clang_target = "riscv64-".to_owned();
         clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap());
         return clang_target.into();
+    } else if rust_target.starts_with("riscv64imac-") {
+        let mut clang_target = "riscv64-".to_owned();
+        clang_target
+            .push_str(rust_target.strip_prefix("riscv64imac-").unwrap());
+        return clang_target.into();
     } else if rust_target.ends_with("-espidf") {
         let mut clang_target =
             rust_target.strip_suffix("-espidf").unwrap().to_owned();
@@ -713,6 +718,11 @@ fn rust_to_clang_target(rust_target: &str) -> Box<str> {
         clang_target
             .push_str(rust_target.strip_prefix("riscv32imac-").unwrap());
         return clang_target.into();
+    } else if rust_target.starts_with("riscv32imafc-") {
+        let mut clang_target = "riscv32-".to_owned();
+        clang_target
+            .push_str(rust_target.strip_prefix("riscv32imafc-").unwrap());
+        return clang_target.into();
     }
     rust_target.into()
 }
@@ -1357,6 +1367,10 @@ fn test_rust_to_clang_target_riscv() {
         rust_to_clang_target("riscv64gc-unknown-linux-gnu").as_ref(),
         "riscv64-unknown-linux-gnu"
     );
+    assert_eq!(
+        rust_to_clang_target("riscv64imac-unknown-none-elf").as_ref(),
+        "riscv64-unknown-none-elf"
+    );
     assert_eq!(
         rust_to_clang_target("riscv32imc-unknown-none-elf").as_ref(),
         "riscv32-unknown-none-elf"
@@ -1365,6 +1379,10 @@ fn test_rust_to_clang_target_riscv() {
         rust_to_clang_target("riscv32imac-unknown-none-elf").as_ref(),
         "riscv32-unknown-none-elf"
     );
+    assert_eq!(
+        rust_to_clang_target("riscv32imafc-unknown-none-elf").as_ref(),
+        "riscv32-unknown-none-elf"
+    );
 }
 
 #[test]
diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs
index 1fc22416..6b5b4d8c 100644
--- a/bindgen/options/mod.rs
+++ b/bindgen/options/mod.rs
@@ -508,7 +508,7 @@ options! {
     constified_enums: RegexSet {
         methods: {
             regex_option! {
-                /// Mark the given `enum` as a set o integer constants.
+                /// Mark the given `enum` as a set of integer constants.
                 ///
                 /// This is similar to the [`Builder::constified_enum_module`] style, but the
                 /// constants are generated in the current module instead of in a new module.
@@ -1179,6 +1179,35 @@ options! {
                 self.options.input_headers.push(header.into().into_boxed_str());
                 self
             }
+
+            /// Add input C/C++ header(s) to generate bindings for.
+            ///
+            /// This can be used to generate bindings for a single header:
+            ///
+            /// ```ignore
+            /// let bindings = bindgen::Builder::default()
+            ///     .headers(["input.h"])
+            ///     .generate()
+            ///     .unwrap();
+            /// ```
+            ///
+            /// Or for multiple headers:
+            ///
+            /// ```ignore
+            /// let bindings = bindgen::Builder::default()
+            ///     .headers(["first.h", "second.h", "third.h"])
+            ///     .generate()
+            ///     .unwrap();
+            /// ```
+            pub fn headers<I: IntoIterator>(mut self, headers: I) -> Builder
+            where
+                I::Item: Into<String>,
+            {
+                self.options
+                    .input_headers
+                    .extend(headers.into_iter().map(Into::into).map(Into::into));
+                self
+            }
         },
         // This field is handled specially inside the macro.
         as_args: ignore,
@@ -1814,7 +1843,7 @@ options! {
         },
         as_args: "--dynamic-loading",
     },
-    /// Whether to equire successful linkage for all routines in a shared library.
+    /// Whether to require successful linkage for all routines in a shared library.
     dynamic_link_require_all: bool {
         methods: {
             /// Set whether to require successful linkage for all routines in a shared library.
@@ -1879,7 +1908,7 @@ options! {
         },
         as_args: "--c-naming",
     },
-    /// Wether to always emit explicit padding fields.
+    /// Whether to always emit explicit padding fields.
     force_explicit_padding: bool {
         methods: {
             /// Set whether to always emit explicit padding fields.
diff --git a/book/src/cpp.md b/book/src/cpp.md
index f5091b35..9b451b9d 100644
--- a/book/src/cpp.md
+++ b/book/src/cpp.md
@@ -74,7 +74,7 @@ cannot translate into Rust:
   
 * Many C++ specific aspects of calling conventions. For example in the Itanium abi types that are 
   "[non trivial for the purposes of calls](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial)" 
-  should be passed by pointer, even if they are otherwise eligable to be passed in a register.
+  should be passed by pointer, even if they are otherwise eligible to be passed in a register.
   Similarly in both the Itanium and MSVC ABIs such types are returned by "hidden parameter", much like
   large structs in C that would not fit into a register. This also applies to types with any base classes
   in the MSVC ABI (see [x64 calling convention](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values)).
diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md
index 1bb19e4d..d5d288d1 100644
--- a/book/src/non-system-libraries.md
+++ b/book/src/non-system-libraries.md
@@ -14,7 +14,7 @@ int hello();
 
 Given that the library has not been compiled yet, we need to modify the
 `build.rs` build script to compile the `hello.c` source file into a static
-libary:
+library:
 
 ```rust,ignore
 extern crate bindgen;
diff --git a/book/src/objc.md b/book/src/objc.md
index ce6d7567..ed6f2cb8 100644
--- a/book/src/objc.md
+++ b/book/src/objc.md
@@ -18,7 +18,7 @@ objc::runtime::Object` (the pointer to the objective-c instance). The trait
 `IFoo` is needed to allow for the generated inheritance.
 
 Functions that use or return objective-c pointers of instance `Foo` will return
-`Foo`. The reason this works is beacuse `Foo` represented as `transparent`.
+`Foo`. The reason this works is because `Foo` represented as `transparent`.
 This will be helpful for a lot of objective-c frameworks however there are some
 cases where functions return `instancetype` which is a type alias for `id` so
 an occasional `foo.0` may be required. An example of this would in the UIKit


Test patch:
diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs
index 9df45c3b..0e15155d 100644
--- a/bindgen-tests/tests/tests.rs
+++ b/bindgen-tests/tests/tests.rs
@@ -472,6 +472,42 @@ fn test_multiple_header_calls_in_builder() {
     }
 }
 
+#[test]
+fn test_headers_call_in_builder() {
+    let actual = builder()
+        .headers([
+            concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/func_ptr.h"),
+            concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h"),
+        ])
+        .clang_arg("--target=x86_64-unknown-linux")
+        .generate()
+        .unwrap()
+        .to_string();
+
+    let actual = format_code(actual).unwrap();
+
+    let expected_filename = concat!(
+        env!("CARGO_MANIFEST_DIR"),
+        "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs"
+    );
+    let expected = include_str!(concat!(
+        env!("CARGO_MANIFEST_DIR"),
+        "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs"
+    ));
+    let expected = format_code(expected).unwrap();
+
+    if actual != expected {
+        println!("Generated bindings differ from expected!");
+        error_diff_mismatch(
+            &actual,
+            &expected,
+            None,
+            Path::new(expected_filename),
+        )
+        .unwrap();
+    }
+}
+
 #[test]
 fn test_multiple_header_contents() {
     let actual = builder()