To support code-gen from build.rs, we should fully support all elements of include!(concat!(env!("OUT_DIR"), "/bindings.rs")) incantation.
This needs a few moving parts to be in place:
- we should extract the
OUT_DIR from cargo. It looks like this info might be missing from cargo metadata at present, but we can always start with heuristic, while working on proper solution upstream in parallel
- we need to support
env! macro. To do this, we need to add an env: FxHashMap<String, String> to the CrateGraph, similarly to how we added cfg recently. When expanding env!, we should look in the map first, and fall back to real std::env::var after that.
include! and concat! seem to use "eager expansion" of some sorts. We need to figure what this means, how it is implemented in rustc, and add it to rust-analyzer. Might be tricky.
- handling the actual
include! shouldn't be hard: we only need to plug the included file into the raw_items machinery. Work to support include!("some-path.rs") can be done in parallel to other bullet points here
To support code-gen from
build.rs, we should fully support all elements ofinclude!(concat!(env!("OUT_DIR"), "/bindings.rs"))incantation.This needs a few moving parts to be in place:
OUT_DIRfrom cargo. It looks like this info might be missing fromcargo metadataat present, but we can always start with heuristic, while working on proper solution upstream in parallelenv!macro. To do this, we need to add anenv: FxHashMap<String, String>to theCrateGraph, similarly to how we addedcfgrecently. When expandingenv!, we should look in the map first, and fall back to realstd::env::varafter that.include!andconcat!seem to use "eager expansion" of some sorts. We need to figure what this means, how it is implemented in rustc, and add it to rust-analyzer. Might be tricky.include!shouldn't be hard: we only need to plug the included file into the raw_items machinery. Work to supportinclude!("some-path.rs")can be done in parallel to other bullet points here