Skip to content
This repository has been archived by the owner on Feb 11, 2025. It is now read-only.

Build features #104

Merged
merged 11 commits into from
Mar 5, 2024
Merged

Build features #104

merged 11 commits into from
Mar 5, 2024

Conversation

pmikolajczyk41
Copy link
Member

Problem

When specifying a contract dependency with some required features (apart from ink-as-dependency), e.g.:

psp22 = { git = "https://github.com/Cardinal-Cryptography/PSP22.git", default-features = false, features = ["contract", "ink-as-dependency"] }

using either #[drink::contract_bundle_provider] or #[drink::test] used to end up with some linking error, because actually such psp22 would be built without the contract feature.

Solution in this PR

After ~2h of playing with the output from cargo metadata and dependency resolution, I went for the easiest, yet not so accurate approach:

  1. the main contract (the one that is located in the current crate) is still built without any features on
  2. for every contract dependency (i.e. a package with ink-as-dependecy feature present) I take all the features that were turned on on any resolution path. This means that even if some other dependency would depend on such PSP22 with a feature not-related-to-contracts(while our main contract wouldn't), the not-related-to-contracts feature is included; the only exception is the std feature, which is always included on a certain dependency resolution path.

Of course, there are cases where this approach is not correct, but I really don't see any point in wasting more time now, at least somebody actually will have the problem.

Ad 1.: I think that it is now not possible to fetch the --features argument passed to cargo in a procedural macro. One can inspect all present CARGO_FEATURE_<name> env variables (https://doc.rust-lang.org/cargo/reference/environment-variables.html), but then recreating original name (modulo underscores, dashes, capitalization) is hehe.

@kroist
Copy link
Collaborator

kroist commented Feb 21, 2024

Code seems good, but this has to be explicit:

It is stated in documentation, that root package features are not being checked. So I think it would be great to state somewhere (better README.md), that if user wants to test the contract which has features, it should be done in external package

@pmikolajczyk41
Copy link
Member Author

it is stated in the macro docs

@pmikolajczyk41 pmikolajczyk41 merged commit 0e33fb1 into main Mar 5, 2024
2 checks passed
@pmikolajczyk41 pmikolajczyk41 deleted the build-features branch March 5, 2024 09:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants