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

proc macro crate causes extra dependency compilation in workspace #10645

Closed
kaspar030 opened this issue May 10, 2022 · 2 comments
Closed

proc macro crate causes extra dependency compilation in workspace #10645

kaspar030 opened this issue May 10, 2022 · 2 comments
Labels
A-features2 Area: issues specifically related to the v2 feature resolver C-bug Category: bug

Comments

@kaspar030
Copy link

Problem

In a project workspace with many examples all having a library crate dependency with default features and a single proc-macro crate with the same dependency, the dependency is built twice.
All examples are using one of the compilations, only the proc macro crate is using the other.

All crates in the workspace are setting edition 2018, but the workspace is setting resolver = "2".

This is the PR where the issue can be reproduced: hacspec/hacspec#72

In this case, Hacspec's type checker can't handle the two versions of that library, which is another problem.
BUT, why does the library crate need to be compiled twice even though it is only used with default features?

Steps

  1. clone initial no_std work hacspec/hacspec#72
  2. run cargo clean && cargo build
  3. ls target/debug/deps | grep libhacspec_lib

Observe there are two versions of libhacspec_lib.

  1. removing "resolver=2" from Cargo.toml and repeat step 2+3

Observe there's only one version of libhacspec_lib.

Possible Solution(s)

It seems like the proc macro build ignores all feature settings?

Notes

No response

Version

cargo 1.62.0-nightly (a44758ac8 2022-05-04)
@ehuss
Copy link
Contributor

ehuss commented May 11, 2022

Thanks for the report! This is a known issue with proc-macros inside a workspace (#8312). Essentially the proc-macro activates features as a member of the workspace, and then separately as a proc-macro dependency. In your particular case, this causes some dependencies to be built twice, once with the "default" feature enabled and once without. This is due to the frequent use of default-features=false.

One workaround is to not use default-features=false like this:

diff --git a/lib/Cargo.toml b/lib/Cargo.toml
index 2b70fb9ec..b544d009f 100644
--- a/lib/Cargo.toml
+++ b/lib/Cargo.toml
@@ -12,7 +12,7 @@ repository = "https://github.com/hacspec/hacspec"
 [dependencies]
 num = { version = "0.4", default-features = false }
 secret_integers = { path = "../utils/secret-integers", optional = true, version = "0.1.7" } #FIXME: publish new version
-abstract_integers = { path = "../utils/abstract-integers", version = "0.1.5", default-features = false } #FIXME: publish new version
+abstract_integers = { path = "../utils/abstract-integers", version = "0.1.5" } #FIXME: publish new version
 hacspec-attributes = { path = "../utils/attributes",  optional = true, version = "0.1.0-beta.1" }
 
 [features]
diff --git a/utils/abstract-integers/Cargo.toml b/utils/abstract-integers/Cargo.toml
index a2c4c07eb..a491e0e2c 100644
--- a/utils/abstract-integers/Cargo.toml
+++ b/utils/abstract-integers/Cargo.toml
@@ -10,7 +10,7 @@ license = "Apache-2.0"
 readme = "README.md"
 
 [dependencies]
-num = { version = "0.4", default-features = false }
+num = { version = "0.4" }
 num-bigint = { version = "0.3", default-features = false }
 
 [features]

It may also be possible to avoid it by building the workspace without the proc-macros (like the derive one). I'm not sure if that will work, though.

I did discover that there is a bug in cargo tree where it is not correctly showing these duplicates. I have filed #10651 for that.

Closing as a duplicate of #8312

@ehuss ehuss closed this as completed May 11, 2022
@ehuss ehuss added the A-features2 Area: issues specifically related to the v2 feature resolver label May 11, 2022
@kaspar030
Copy link
Author

Thanks a lot for the detailed response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features2 Area: issues specifically related to the v2 feature resolver C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants