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

fix: feature flag compiler errors #256

Merged
merged 5 commits into from Dec 27, 2022
Merged

Conversation

Wodann
Copy link
Contributor

@Wodann Wodann commented Nov 8, 2022

No description provided.

secp256k1 = ["revm_precompiles/secp256k1"]
k256 = ["revm_precompiles/k256_ecrecover"]
web3db = []
Copy link
Contributor Author

@Wodann Wodann Dec 16, 2022

Choose a reason for hiding this comment

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

Removed deprecated feature flag web3db, as it will cause cargo t --all-features to fail

@@ -1,9 +1,7 @@
#[cfg(any(feature = "k256_ecrecover", feature = "secp256k1"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing feature cfg, as this only works when either the k256_ecrecover or secp256k1 feature flags are on. Ensures that cargo t --no-default-features succeeds.

@Wodann
Copy link
Contributor Author

Wodann commented Dec 16, 2022

Rebased on latest. @rakita if there's anything you'd like me to change, please let me know.

@@ -112,6 +112,7 @@ impl Precompiles {
static INSTANCE: OnceCell<Precompiles> = OnceCell::new();
INSTANCE.get_or_init(|| {
let fun = vec![
#[cfg(any(feature = "k256_ecrecover", feature = "secp256k1"))]
Copy link
Member

Choose a reason for hiding this comment

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

I dont want to disable ECRECOVER if default is not present, it seems like a footgun. As I said here I am fine with build failure: #252 (comment)

Having this would make this more user-friendly: https://doc.rust-lang.org/std/macro.compile_error.html

Something like

#[cfg(all(not(feature = "k256_ecrecover"), not(feature = "secp256k1")))]
compile_error!(
    "To support ecrecover precompile please enable one of these two features, `k256_ecrecover` or `secp256k1`
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the above mentioned compile_error to the secp256k1 module

@rakita
Copy link
Member

rakita commented Dec 20, 2022

to unblock this I decided to have k256 as default and have only secp256k1 feature.

Reasoning behind this can be found here:
https://github.com/bluealloy/revm/pull/256/files#diff-dddad4f9af653f2ddf5fb5cd993a7873baed17e3ca758f4acf205a529663bd24R29-R32

@Wodann please tell me if this works for you

@Wodann
Copy link
Contributor Author

Wodann commented Dec 20, 2022

The problem by reverting those changes (even with a default feature set) is that when people compile with --no-default-features they get non-descript compiler errors that they have to chase to realise that they don't have the proper flag. A crate should always succeed compilation (unless there is a compile_error!), even if default features are disabled. Those were avoided by the #[cfg(..) macros that I added in this PR originally

@rakita
Copy link
Member

rakita commented Dec 23, 2022

The problem by reverting those changes (even with a default feature set) is that when people compile with --no-default-features they get non-descript compiler errors that they have to chase to realise that they don't have the proper flag. A crate should always succeed compilation (unless there is a compile_error!), even if default features are disabled. Those were avoided by the #[cfg(..) macros that I added in this PR originally

Totally agreeing with this, I had bad choice of the word default, I meant as k256 is not optional and seckp256k1 is a feature flag that would use C lib instead of k256. It will always compile.

@rakita
Copy link
Member

rakita commented Dec 27, 2022

@Wodann does this work for you?

@Wodann
Copy link
Contributor Author

Wodann commented Dec 27, 2022

Yup, LGTM! Thanks for clarifying 😊

@rakita rakita merged commit 7e98fef into bluealloy:main Dec 27, 2022
@Wodann Wodann deleted the fix/secp256k1 branch December 28, 2022 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants