Expose control of import prefix to Cargo builds #347
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a global configuration object called cxx_build::CFG.
CFG.include_prefix
Presently the only exposed configuration is the
include_prefix
, the prefix at which C++ code from your crate as well as directly dependent crates can access the code generated during this build.By default, the
include_prefix
is equal to the name of the current crate. That means if our crate is calleddemo
and has Rust source files in a src/ directory and maybe some handwritten C++ header files in an include/ directory, then the current crate as well as downstream crates might include them as follows:By modifying
CFG.include_prefix
we can substitute a prefix that is different from the crate name if desired. Here we'll change it to"path/to"
which will make import paths take the form"path/to/include/wow.h"
and"path/to/src/lib.rs.h"
.Note that cross-crate imports are only made available between direct dependencies. Another crate must directly depend on your crate in order to #include its headers; a transitive dependency is not sufficient. Additionally, headers from a direct dependency are only importable if the dependency's Cargo.toml manifest contains a
links
key. If not, its headers will not be importable from outside of the same crate.