rust-lang / rust-lang/rust-bindgen

Controlling where to look for files - make distcheck and VPATH builds, finding config.h and other includes

Open
#2,930 4 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

Intro

SentryPeer is being extended using Rust as a lib. This Rust lib also uses SentryPeer via a C lib it generates, hence the use of cbindgen and bindgen in the same build.rs. This is all driven by autotools.

Input C/C++ Header

https://github.com/SentryPeer/SentryPeer/blob/main/sentrypeer_rust/wrapper.h

/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only  */
/* Copyright (c) 2021 - 2024 Gavin Henry <ghenry@sentrypeer.org> */
/* 
   _____            _              _____
  / ____|          | |            |  __ \
 | (___   ___ _ __ | |_ _ __ _   _| |__) |__  ___ _ __
  \___ \ / _ \ '_ \| __| '__| | | |  ___/ _ \/ _ \ '__|
  ____) |  __/ | | | |_| |  | |_| | |  |  __/  __/ |
 |_____/ \___|_| |_|\__|_|   \__, |_|   \___|\___|_|
                              __/ |
                             |___/
*/

#include "../src/conf.h"
#include "../src/sip_message_event.h"
#include "../src/sip_daemon.h"
Bindgen Invocation

https://github.com/SentryPeer/SentryPeer/blob/main/sentrypeer_rust/build.rs

    // The bindgen::Builder is the main entry point
    // to bindgen, and lets you build up options for
    // the resulting bindings.
    let bindings = bindgen::Builder::default()
        // The input header we would like to generate
        // bindings for.
        .header("wrapper.h")
        // Pick the functions we want to generate bindings for
        .allowlist_function("sentrypeer_config_new|sentrypeer_config_destroy")
        .allowlist_function("sip_message_event_new|sip_message_event_destroy")
        .allowlist_function("sip_log_event")
        // Tell cargo to invalidate the built crate whenever any of the
        // included header files changed.
        .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
        // Finish the builder and generate the bindings.
        .generate()
        // Unwrap the Result and panic on failure.
        .expect("Unable to generate bindings");

    // Write the bindings to the $OUT_DIR/bindings.rs file.
    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings.rs, so can't use SentryPeer C lib!");

What options do I have for setting where we look for files?

Output
  --- stderr
  src_dir: ../..
  ./../src/conf.h:21:10: fatal error: '../config.h' file not found
  thread 'main' panicked at build.rs:60:10:
  Unable to generate bindings: ClangDiagnostic("./../src/conf.h:21:10: fatal error: '../config.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
make[2]: *** [Makefile:2850: /home/ghenry/src/sentrypeer/sentrypeer-4.0.0/_build/sub/sentrypeer_rust/target/release/libsentrypeer_rust.a] Error 101
make[2]: Leaving directory '/home/ghenry/src/sentrypeer/sentrypeer-4.0.0/_build/sub'
make[1]: *** [Makefile:942: all] Error 2
make[1]: Leaving directory '/home/ghenry/src/sentrypeer/sentrypeer-4.0.0/_build/sub'

I'm passing in SRC_DIR from my makefile here:

https://github.com/SentryPeer/SentryPeer/blob/main/Makefile.am#L273

This is all to try and get make distcheck to work for VPATH

Maybe I just can't. make dist and running all the usual works:

./configure
make
make check
make install

Thanks.

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

Start with sentrypeer_rust/build.rs and wrapper.h, then inspect Makefile.am and src/conf.h to trace include paths during a VPATH build. Reproduce the reported failure with make distcheck and determine how generated config.h and other headers should be located. Done means the Rust bindings build successfully in the VPATH/distcheck setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.