rust-lang / rust-lang/rust-bindgen

type is redefined

Open
#2,571 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header

Header

#include "AeronArchive.h"

the actual header can be found here
https://github.com/real-logic/aeron/blob/1.41.4/aeron-archive/src/main/cpp/client/AeronArchive.h

Bindgen Invocation

bindgen code

    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:rerun-if-changed=bindings.h");

    let aeron_path = canonicalize(Path::new("./aeron")).unwrap();
    let header_path = aeron_path.join("aeron-archive/src/main/cpp/client");
    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

    let cmake_output = Config::new(&aeron_path)
        .build();

    let base_lib_dir = cmake_output.join("build");
    println!(
        "cargo:rustc-link-search=native={}",
        base_lib_dir.join("lib").display()
    );
    // Because the `cmake_output` path is different for debug/release, we're not worried
    // about accidentally linking the Debug library when this is a release build or vice-versa
    println!(
        "cargo:rustc-link-search=native={}",
        base_lib_dir.join("lib/Debug").display()
    );
    println!(
        "cargo:rustc-link-search=native={}",
        base_lib_dir.join("binaries/Debug").display()
    );
    println!(
        "cargo:rustc-link-search=native={}",
        base_lib_dir.join("lib/Release").display()
    );
    println!(
        "cargo:rustc-link-search=native={}",
        base_lib_dir.join("binaries/Release").display()
    );

    println!("cargo:rustc-link-lib=static=aeron_archive_client");
    println!("cargo:rustc-link-lib=static=aeron_archive_client_wrapper");
    println!("cargo:rustc-link-lib=stdc++");

    println!("cargo:include={}", header_path.display());
    let bindings = bindgen::Builder::default()
        .clang_arg(format!("-I{}", header_path.display()))
        .clang_arg(format!(
            "-I{}",
            aeron_path.join("aeron-client/src/main/c").display()
        ))
        .header("bindings.h")
        .enable_cxx_namespaces()
        // enable C++
        .clang_args(&["-x", "c++", "--std=c++14"])
        .opaque_type("std::.*")
        .constified_enum_module("aeron_.*_enum")
        .derive_debug(false)
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate aeron bindings");

    bindings
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings!");
Actual Results

error

error[E0428]: the name `this_t` is defined multiple times
     --> /home/alex/workspaces/personal/aeron-lib/target/debug/build/libaeron_archive-sys-0a7352ee9f461a4a/out/bindings.rs:10595:5
      |
10115 |     pub type this_t = root::aeron::concurrent::logbuffer::BufferClaim;
      |     ------------------------------------------------------------------ previous definition of the type `this_t` here
...
10595 |     pub type this_t = root::aeron::ChannelUri;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `this_t` redefined here
      |
      = note: `this_t` must be defined only once in the type namespace of this module

error[E0428]: the name `this_t` is defined multiple times
     --> /home/alex/workspaces/personal/aeron-lib/target/debug/build/libaeron_archive-sys-0a7352ee9f461a4a/out/bindings.rs:10597:5
      |
10115 |     pub type this_t = root::aeron::concurrent::logbuffer::BufferClaim;
      |     ------------------------------------------------------------------ previous definition of the type `this_t` here
...
10597 |     pub type this_t = root::aeron::archive::client::Context;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `this_t` redefined here
      |
      = note: `this_t` must be defined only once in the type namespace of this module

error[E0428]: the name `this_t` is defined multiple times
     --> /home/alex/workspaces/personal/aeron-lib/target/debug/build/libaeron_archive-sys-0a7352ee9f461a4a/out/bindings.rs:10598:5
      |
10115 |     pub type this_t = root::aeron::concurrent::logbuffer::BufferClaim;
      |     ------------------------------------------------------------------ previous definition of the type `this_t` here
...
10598 |     pub type this_t = root::aeron::BufferBuilder;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `this_t` redefined here
      |
      = note: `this_t` must be defined only once in the type namespace of this module

generated file

// skip other line....
    pub type this_t = root::aeron::ChannelUri;
    pub type this_t = root::aeron::archive::client::Context;
    pub type this_t = root::aeron::BufferBuilder;
}
Expected Results

no redefined type

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce generation from build.rs using bindings.h and AeronArchive.h, then inspect the generated bindings.rs entries where multiple pub type this_t definitions appear. Trace bindgen's C++ namespace handling and type-name generation, and consider the issue done when the same invocation produces bindings.rs without duplicate Rust type definitions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.