integritee-network / worker

Integritee off-chain worker and sidechain validateer
Apache License 2.0
89 stars 46 forks source link

Add compile error in case std dependent crate get imported with neither `std` nor `sgx_tstd` feature #841

Open haerdib opened 2 years ago

haerdib commented 2 years ago

We have compile errors in case both, sgx_tstd and std, are getting imported simultaneously (check out https://github.com/integritee-network/pallets/blob/master/primitives/utils/src/lib.rs#L22-L23). But not in case none get imported, even though at least one is necessary. This is happening very easily by importing a crate with default-features = false but without adding the std nor sgx feature.

This has caused problems already, and it's hard to find the root cause just from the error messages. It might make sense to add a compile error assertion, this way at least the root cause is obvious.

Proposing the following:

#[cfg(all(not(feature = "std"), not(feature = "sgx")))]
compile_error!("Either feature \"std\" or feature \"sgx\" must be enabled");

Alternative: Make crates no_std compatible but declarations, that need sgx_tstd/ std should only be available within the sgx or std feature. This will also report an error where the root cause is fairly obvious.

murerfel commented 2 years ago

Agreed, we should add a corresponding check and give a descriptive compiler error when it fails 👍