Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghenry opened this issue Sep 13, 2024 · 4 comments

Comments

@ghenry
Copy link

ghenry commented Sep 13, 2024

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 <[email protected]> */
/* 
   _____            _              _____
  / ____|          | |            |  __ \
 | (___   ___ _ __ | |_ _ __ _   _| |__) |__  ___ _ __
  \___ \ / _ \ '_ \| __| '__| | | |  ___/ _ \/ _ \ '__|
  ____) |  __/ | | | |_| |  | |_| | |  |  __/  __/ |
 |_____/ \___|_| |_|\__|_|   \__, |_|   \___|\___|_|
                              __/ |
                             |___/
*/

#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.

@emilio
Copy link
Contributor

emilio commented Sep 25, 2024

You just need to pass the right -I flags to clang right?

@ghenry
Copy link
Author

ghenry commented Sep 26, 2024 via email

@ghenry
Copy link
Author

ghenry commented Sep 27, 2024

Hi @emilio

I could pass a .clang_arg("-I") into Builder. Will try.

@ghenry
Copy link
Author

ghenry commented Sep 27, 2024

The problem is config.h isn't in the same directory as expected anymore and more conf.h has hard code paths...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants