Skip to content

include!(concat!(env!("OUT_DIR"), "/bindings.rs")) should work #1964

@matklad

Description

@matklad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions