Devolutions / conan-rs

A Rust wrapper of the conan C/C++ package manager (conan.io) to simplify usage in build scripts
Apache License 2.0
36 stars 11 forks source link

followed instruction but not seeing my library in the build output #10

Closed EMCP closed 1 year ago

EMCP commented 1 year ago

Hi first time getting into Rust.. pivoting away from C++.. and I have a custom Conan recipe that is not public.. but have been using it fairly easily for a year or so..

when I went to try the step-by-step instructions for integrating that conan recipe with my test project.. it failed to show any connection or loading had occurred.. is this because the library is private? or did I miss a step possibly?

Cargo.toml

[package]
name = "rust_twsapi_demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cxx = "1.0.80"

[build-dependencies]
conan = "0.3.0"

conanfile.txt

[requires]
twsapi/10.17.01@stonks/prod

build.rs

use std::path::Path;
use std::env;

use conan::*;

fn main() {
    let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
    let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
    let conan_profile = format!("{}-{}", target_os, target_arch);

    let command = InstallCommandBuilder::new()
        .with_profile(&conan_profile)
        .build_policy(BuildPolicy::Missing)
        .recipe_path(Path::new("conanfile.txt"))
        .build();

    if let Some(build_info) = command.generate() {
        println!("using conan build info");
        build_info.cargo_emit();
    }
}

Result

cargo -vv build
       Fresh unicode-ident v1.0.5
       Fresh proc-macro2 v1.0.47
       Fresh cc v1.0.74
       Fresh quote v1.0.21
       Fresh syn v1.0.103
       Fresh autocfg v1.1.0
       Fresh memchr v2.5.0
       Fresh serde_derive v1.0.147
       Fresh serde v1.0.147
       Fresh libc v0.2.137
       Fresh aho-corasick v0.7.19
       Fresh ryu v1.0.11
       Fresh cxxbridge-flags v1.0.80
       Fresh regex-syntax v0.6.28
       Fresh itoa v1.0.4
       Fresh hashbrown v0.12.3
       Fresh regex v1.7.0
       Fresh serde_json v1.0.87
       Fresh indexmap v1.9.1
       Fresh which v3.1.1
       Fresh lazy_static v1.4.0
       Fresh conan v0.3.0
       Fresh link-cplusplus v1.0.7
       Fresh cxxbridge-macro v1.0.80
       Fresh cxx v1.0.80
       Fresh rust_twsapi_demo v0.1.0 (/home/emcp/Dev/temp/rust_twsapi_demo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
EMCP commented 1 year ago

also for reference

$ conan --version
Conan version 1.51.2

$ cargo --version
cargo 1.65.0 (4bc8f24d3 2022-10-20)

EDIT:

Ah, I think I get it.. these instructions didn't mention to conan install but I found an old blog post which had that part.. and once I did that.. it seemed to start springing to life (albeit with an error)

https://blog.conan.io/2016/06/23/Rust-cargo-and-Conan-C_and_C++-package-manager-integration.html

Would it be appropriate I do a PR on the Doc just to add that step somewhere?

awakecoding commented 1 year ago

Hum... can you run cargo clean + "cargo -vv build" again now that it appears to be doing something more? That first log looks like it did absolutely nothing, and I wonder if it even called your build.rs script. cargo -vv build should reveal a few lines of output that begin with "cargo:" emitted by conan-rs

EMCP commented 1 year ago

it turned out the issue was indeed lacking the conan install . step.. I will close this but again.. if you're open to it I am happy to add it in the README.md

awakecoding commented 1 year ago

it turned out the issue was indeed lacking the conan install . step.. I will close this but again.. if you're open to it I am happy to add it in the README.md

Something is off, because conan-rs builds the "conan install" command already, you shouldn't have to call it yourself. Maybe it's not getting called correctly for you? https://github.com/Devolutions/conan-rs/blob/master/src/lib.rs

EMCP commented 1 year ago

ahah.. well in that case..

I am running in Kubuntu 22.04 ... unsure how to proceed to debug it but yeah nothing worked or showed up until after the install manually was triggered

awakecoding commented 1 year ago

Was this a fresh environment in which conan was never called before? I wonder if calling conan install didn't end up initializing your conan default settings

EMCP commented 1 year ago

I cannot recall.. it's pretty fresh within the last couples months and I cannot recall if I used this env explicitly with conan beyond simply installing.. but I can see I already had my package in the repo listings so I would guess no it was already run before

EDIT: im pretty sure at a minimum I'd installed conan AND built some local packages on this machine .. so I don't think it's brand-brand new

UPDATE:

I just took a look on a brand new install of conan.. on a different machine.. added conanrs .. have a existing conanfile.txt .. and again.. nothing is being triggered as far as the conan install . is concerned..

Consistently seeing this issue..

if I cargo build -vv before conan install . .. you will not see the C++

EMCP commented 1 year ago

I updated https://github.com/Devolutions/conan-rs/issues/11#issuecomment-1305738518 , with some information about what I am seeing.. it seems conan gets into the mix but I am having trouble reaching my Headers I had installed via conan install . .. so perhaps there's a deeper issue.

EMCP commented 1 year ago

I think, based on the response in #11 , there may be an issue with my conans profile .. when I do a manual conan install . I am not seeing conanbuildinfo.json but instead conanbuildinfo.txt could that be a source of the problem?

EMCP commented 1 year ago

closing.. all is working now.. turns out the files do not get installed in the CWD but in some .conan area... then you wire those into CXX