aws / aws-lc-rs

aws-lc-rs is a cryptographic library using AWS-LC for its cryptographic operations. The library strives to be API-compatible with the popular Rust library named ring.
Other
236 stars 40 forks source link

Build fails for some targets because of missing _ISOC11_SOURCE preprocessor definition #370

Closed ancwrd1 closed 2 months ago

ancwrd1 commented 3 months ago

When trying to build the aws-lc-rs or the dependent project it fails for some targets (in particular x86_64-pc-windows-gnu) with a compiler error around static_assert. Error example:

rust/aws-lc-rs/aws-lc-sys/aws-lc/crypto/refcount_win.c:23:15: error: expected declaration specifiers or '...' before '_Alignof'
     23 | static_assert(alignof(CRYPTO_refcount_t) == alignof(LONG),
        |               ^~~~~~~

This happens because the standard <assert.h> header for MinGW toolchain contains this:

#if (defined _ISOC11_SOURCE \
     || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)) \
    && !defined (__cplusplus)
/* Static assertion.  Requires support in the compiler.  */
#undef static_assert
#define static_assert _Static_assert
#endif

The workaround is to use CFLAGS="-D_ISOC11_SOURCE" env variable when building. A better solution to my opinion is to configure the build scripts to include it by default.

Edit: I think it happens because build scripts set "-std=c99", and assert_static is c11 feature.

justsmth commented 3 months ago

Thanks for submitting this issue. For most platforms, AWS-LC's C code is expected to be compliant with C99. However, Windows (of course) often requires exceptions to be made.

Let me take some time to investigate this (and potentially other issues?) when building AWS-LC w/ MinGW. I'll then follow up here.

justsmth commented 2 months ago

As of our v1.7.1 release, I believe this issue to be resolved. Feel free to reopen or create a new issue if you are still having a problem building aws-lc-rs. Thanks!