Skip to content

Rewrite cxx-build crate #276

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

Merged
merged 24 commits into from
Sep 2, 2020
Merged

Rewrite cxx-build crate #276

merged 24 commits into from
Sep 2, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Sep 2, 2020

Fixes #213. Fixes #88. Supersedes #214. Supersedes #253.

The major improvement is that we no longer care where Cargo's target dir is located. Instead of doing anything based on relative paths from the target dir, we do it only based on the paths the user passes to cxx_build::bridge, which we know are relative to the manifest dir because that's the current directory when a build script runs.

For an invocation like cxx_build::bridge("src/lib.rs") the resulting layout of the OUT_DIR would be:

$  exa -T target/debug/build/cxx-demo-1848f7a3fc5320f1/out/
target/debug/build/cxx-demo-1848f7a3fc5320f1/out
└── cxxbridge
   ├── cxx-demo
   │  └── src
   │     ├── lib.rs -> ./lib.rs.h
   │     ├── lib.rs.cc
   │     └── lib.rs.h
   └── rust
      └── cxx.h

and the include paths would be #include "cxx-demo/src/lib.rs.h", where cxx-demo is the crate name and src/lib.rs is the path that the crate's build script gave cxx_build.

We'll put the OUT_DIR in here as well, to reduce the amount of code that
needs to be fallible.
This one is already handled by the following call to `write`.
When Cargo runs a build script, its current directory is set to the
manifest directory of the crate whose build script it is. That means if
crate A depends on crate B depends on cxx-build, the previous logic
would have found B's target dir (somewhere in the Cargo registry cache)
rather than the intended A target dir being used for the current build.
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

Successfully merging this pull request may close these issues.

Cannot #include gen.rs.h reliably when building with cargo due to dynamic out location Don't rely on the target directory being named 'target'
1 participant