Skip to content

MACRO: support env!("OUT_DIR") in include macro calls#4542

Merged
bors[bot] merged 8 commits intomasterfrom
undin/env-out-dir
Oct 25, 2019
Merged

MACRO: support env!("OUT_DIR") in include macro calls#4542
bors[bot] merged 8 commits intomasterfrom
undin/env-out-dir

Conversation

@Undin
Copy link
Member

@Undin Undin commented Oct 18, 2019

Under the hood, it uses output of cargo build --build-plan command to get value of OUT_DIR variable

2019-10-18 14 03 23

Fixes #1908

@Undin
Copy link
Member Author

Undin commented Oct 20, 2019

I've filed a separate issue #4546 related to the corresponding user notification about the absence of expected generated files

Undin added 2 commits October 25, 2019 12:42
This value need to support code included via include macro calls like `include!(concat!(env!("OUT_DIR"), "/bindings.rs"))`.
At this moment this info extracted from output of `cargo build --build-plan` command.
@Undin Undin force-pushed the undin/env-out-dir branch from 0e0e374 to 21862de Compare October 25, 2019 09:49
@Undin Undin force-pushed the undin/env-out-dir branch from 21862de to f185c10 Compare October 25, 2019 09:51
@Undin
Copy link
Member Author

Undin commented Oct 25, 2019

@vlad20012 I've fixed all discussed issues

@vlad20012
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Oct 25, 2019
4542: MACRO: support `env!("OUT_DIR")` in include macro calls r=vlad20012 a=Undin

Under the hood, it uses output of `cargo build --build-plan` command to get value of `OUT_DIR` variable

![2019-10-18 14 03 23](https://user-images.githubusercontent.com/2539310/67089379-1cb9fd80-f1b0-11e9-95c3-1fec12f9095d.gif)

Fixes #1908

Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
@Undin Undin added this to the v109 milestone Oct 25, 2019
@bors
Copy link
Contributor

bors bot commented Oct 25, 2019

@CAD97
Copy link

CAD97 commented Oct 28, 2019

Thought I should drop this here:

I've requested a way to get OUT_DIR from cargo metadata because cargo build --build-plan always causes a full rebuild after.

val additionalArgs = mutableListOf("-Z", "unstable-options", "--all-targets", "--build-plan")
// Hack to make cargo think that current channel is nightly because we need unstable `--build-plan` option here
val envs = EnvironmentVariablesData.create(mapOf(
RUSTC_BOOTSTRAP to "1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😨

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that this functionality can break at any moment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are closely monitoring changes in the rust toolchain and ready for breaking changes in the build-plan or other nightly features that we use. We'd want a more explicit way to unlock all nightly command-line options on the stable toolchain but now there is only "RUSTC_BOOTSTRAP" magic.

@vlad20012
Copy link
Member

vlad20012 commented Oct 28, 2019

@CAD97 thanks for the comment! Now we're going to disable the feature because of this. (the feature has not yet been released)

@bjorn3
Copy link

bjorn3 commented Oct 28, 2019

@vlad20012 Maybe enable it only when the user is actually using a nightly compiler. Or do you want to not diverge the supported features between stable and nightly users?

@vlad20012
Copy link
Member

vlad20012 commented Oct 28, 2019

@bjorn3 Umm, I'm about the issue that build-plan invocation forces cargo to make full rebuild on the next build. I don't see differences between stable and nightly compiler in this case. But we'll make some option to enable this feature back

Undin added a commit that referenced this pull request Oct 29, 2019
…ault

Recently supported name resolution for included files uses `cargo build --build-plan` to fetch value of `OUT_DIR` environment variable (see #4542).
Found out that `cargo build --build-plan` force next `build` command to recompile whole project (including dependencies).
See rust-lang/cargo#5579 (comment).
At this moment it is part of refresh, i.e. it is invoked on each `Cargo.toml` change, project reopening, etc. So this command is invoked quite frequently.
It can be rather unexpected for large project to make full compilation after each project reopening

So we decided to disable it by default until it will be fixed from cargo side or we'll find better way to get `OUT_DIR` value
bors bot added a commit that referenced this pull request Oct 29, 2019
4573: MACRO: disable name resolution for include with env("OUT_DIR") by default r=Undin a=Undin

Recently supported name resolution for included files uses `cargo build --build-plan` to fetch value of `OUT_DIR` environment variable (see #4542).
Found out that `cargo build --build-plan` force next `build` command to recompile whole project (including dependencies).
See rust-lang/cargo#5579 (comment).
At this moment it is part of refresh, i.e. it is invoked on each `Cargo.toml` change, project reopening, etc. So this command is invoked quite frequently.
It can be rather unexpected for large project to make full compilation after each project reopening

So we decided to disable it by default until it will be fixed from cargo side or we'll find better way to get `OUT_DIR` value


Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
bors bot added a commit that referenced this pull request Oct 28, 2021
8012: CARGO: improve work with generated sources r=vlad20012 a=Undin

In Rust ecosystem, it's quite common to generate some source via build scripts during compilation. Usually, such generated sources are included into project via `include!` macro. The plugin can work with such sources but the corresponding support is currently under `org.rust.cargo.evaluate.build.scripts` [experimental feature](https://plugins.jetbrains.com/plugin/8182-rust/docs/rust-faq.html#experimental-features). See #1908 for more context and details

Since #4542, the plugin added all `out` directories of all packages as source roots into project content root entry. And it worked in general, but this approach has some disadvantages:
- each `out` directory is displayed in `Project Structure` settings. If a project uses many libraries that produce a lot of own `out` directories, `Project Structure` becomes too large and complicated for manual editing
- it doesn't work if `out` directory is located outside of the project directory (for example, because of the custom path of `target` directory)

The new approach just provides all `out` directories via `IndexableSetContributor` API to make IDE index generated sources that solve all described issues

Fixes #6808
Fixes #6844
Fixes #6998
Fixes #7583
Fixes #7934


changelog: Improve work with generated sources provided via `org.rust.cargo.evaluate.build.scripts` [experimental feature](https://plugins.jetbrains.com/plugin/8182-rust/docs/rust-faq.html#experimental-features). Now the plugin doesn't pollute `Project Structure` view with entries for generated `out` directories. Also, the custom paths of target directories are also supported


Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

4 participants