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

access path to the project from a crate's build script #8375

Closed
lucasfernog opened this issue Jun 17, 2020 · 4 comments
Closed

access path to the project from a crate's build script #8375

lucasfernog opened this issue Jun 17, 2020 · 4 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@lucasfernog
Copy link

I'm writing a library that needs to access the CARGO_MANIFEST_DIR from the app that uses it, is that possible? The objective is read application assets at compile time.

@lucasfernog lucasfernog added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jun 17, 2020
@ehuss
Copy link
Contributor

ehuss commented Jun 17, 2020

I'm not sure I understand the question. You can can call std::env::var("CARGO_MANIFEST_DIR") from a build script to get the project directory (whichever project is using the build script).

@lucasfernog
Copy link
Author

When cargo starts building my crate (let's name it my-tool), it assigns the CARGO_MANIFEST_DIR environment variable to the path of this crate's manifest (e.g. /path/to/my-tool). What I'd like to know is the path of the manifest of the crate that's using my-tool as a dependency (let's name it my-app).

Is the only option here to force the my-app/build.rs to call my-tool/build.rs?

@ehuss
Copy link
Contributor

ehuss commented Jun 17, 2020

Ah, I think I see what you mean. No, dependencies do not have any information about the packages that depend on it. Your my-app/build.rs would need to specy my-tool as a build dependency and interact with it via its API. Perhaps an analogous example is the cc crate where you load it as a build dependency, and then pass relative paths into it.

@lucasfernog
Copy link
Author

Alright, thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants