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

Advice/example on docs.rs strategy #1341

Closed
metasim opened this issue Apr 12, 2024 · 2 comments
Closed

Advice/example on docs.rs strategy #1341

metasim opened this issue Apr 12, 2024 · 2 comments

Comments

@metasim
Copy link

metasim commented Apr 12, 2024

I've just released my first cxx project, wrapping a geospatial C++ library called PDAL. As expected, my docs.rs build is failing because PDAL isn't in the build container. So I'm wondering if there are any good examples of projects that get around this problem without resulting to vendoring the source. Or perhaps that is the best practice here?

If I were just using bindgen I would save off a version of the generated bindings for this purpose, but because the Rust side of the generation happens in #[cxx::bridge] macro, I'm assuming this approach won't work.

The other thing I tried was to disable the build.rs of the -sys sub-crate with a feature flag, but then the non-sys crate doesn't have the definitions it needs.

Any other approaches I should consider, or is vendoring the only viable way. (Does vendoring introduce licensing concerns?).

Thanks!

@dtolnay
Copy link
Owner

dtolnay commented Apr 14, 2024

Nothing in cxx_build has any impact on Rust metadata. It only does C++ stuff, which affects linkage but does not affect rustdoc because rustdoc uses metadata-only Rust builds.

You can skip the build script in docs.rs like this:

fn main() {
    println!("cargo:rerun-if-env-changed=DOCS_RS");
    if env::var_os("DOCS_RS").is_some() {
        return;
    }

    // cxx_build stuff
}

@metasim
Copy link
Author

metasim commented Apr 16, 2024

@dtolnay Thank you. I misunderstood, thinking that #[cxx::bridge] had to parse the files referenced by the include! directive. Thanks for the explanation.

@metasim metasim closed this as completed Apr 16, 2024
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