Skip to content

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

@haerdib

Description

@haerdib

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions