mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
798 stars 44 forks source link

Pkg-config combination? #15

Closed shuaimu closed 7 years ago

shuaimu commented 7 years ago

This is probably another silly question. But is there any easy way to use the crate pkg_config to add include search path and link option? Thanks!

shuaimu commented 7 years ago

btw, my current approach:

        let output = Command::new("pkg-config")
                         .arg("--cflags")
                         .arg("--libs")
                         .arg("libraryname")
                         .output()
                         .expect("failed to execute pkg-config");
        let flags = format!("{}", String::from_utf8_lossy(&output.stdout));
        let flags_split = flags.split(" ");
        let mut cppbuild = cpp_build::Config::new();
        for f in flags_split {
            cppbuild.flag(f);
        }
        cppbuild.build("src/main.rs");

It works, but is there a more elegant way?

mystor commented 7 years ago

There might be a more elegant way to handle this, but rust-cpp doesn't really help with it. We internally use gcc-rs to do the actual compiling (https://github.com/alexcrichton/gcc-rs), so if there are other packages building pkg-config-based files with gcc-rs you can copy what they do.

I think that providing tools for parsing command lines is out of scope for rust-cpp. There might be crates for it on crates.io.

shuaimu commented 7 years ago

Thanks for your reply. I dived into the gcc-rs and rustc for a little while. I agree that it is out of the scope of rust-cpp.