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

Export libcxxbridge1.a #1293

Open
NoeMurr opened this issue Dec 11, 2023 · 0 comments
Open

Export libcxxbridge1.a #1293

NoeMurr opened this issue Dec 11, 2023 · 0 comments

Comments

@NoeMurr
Copy link

NoeMurr commented Dec 11, 2023

Hi all,

I need help to understand how to properly compile the bindings setting the target paths.

current situation

I'm building a rust library let's call it lib_a.
For this library I created the bindings for c++ and they are compiled as the library cpp-bindings.
To be able to compile a c++ library correctly I have to link also the library libcxxbridge1.a.

this is my build.rs file:

use std::env;

fn main() {
    let out_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_owned()) + "/" + &env::var("PROFILE").unwrap() + "/cpp-bindings";

    cxx_build::bridge("src/interface.rs")
        .flag_if_supported("-std=c++11")
        .out_dir(out_dir)
        .compile("cpp-bindings");

    println!("cargo:rerun-if-changed=src/interface.rs");
}

Like that, when I'm building in rust I get a filesystem's structure that is similar to:

project/
    |--> target
            |--> cxxbridge
                |--> bindings
                    |--> src
                        |--> interface.rs (link to interface.rs.h)
                        |--> interface.rs.h 
                |--> rust
                    |--> cxx.h (link to crate)
            |--> build
                 [...]
                 |--> cxx-<HASH> 
                    [...] 
                    |--> libcxxbridge1.a
            |--> <PROFILE>
                 [...]
                 |--> lib_a.so
                 |--> cpp-bindings
                     [...]
                     |--> libcpp-bindings.a

Desired situation

I would like to be able to have all the libraries that are needed for c++ in one single directory under the target/<PROFILE> directory.
something like:

project
    |--> target
        |--> <PROFILE>
            [...]
            |--> cxxbridge
                |--> bindings-headers
                    [... identical to above ... ]
            |--> libcxxbridge1.a (could be a link)
            |--> libcpp-bindings.a (could be a link)
            |--> lib_a.so

The perfect solution would be to be able to also join together the library libcxxbridge1.a and libcpp-bindings.a but that's just a plus the important part would be to be able to access to them in an easy way.

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

1 participant