diff --git a/ext/digest/blake3/blake3_dispatch.c b/ext/digest/blake3/blake3_dispatch.c index 14dfbbe..f58eebd 100644 --- a/ext/digest/blake3/blake3_dispatch.c +++ b/ext/digest/blake3/blake3_dispatch.c @@ -19,7 +19,8 @@ #endif #if !defined(BLAKE3_ATOMICS) -#if defined(__has_include) +#if defined(__has_include) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 201112L #if __has_include() && !defined(_MSC_VER) #define BLAKE3_ATOMICS 1 #else @@ -27,7 +28,7 @@ #endif /* __has_include() && !defined(_MSC_VER) */ #else #define BLAKE3_ATOMICS 0 -#endif /* defined(__has_include) */ +#endif /* defined(__has_include) && C11 */ #endif /* BLAKE3_ATOMICS */ #if BLAKE3_ATOMICS diff --git a/ext/digest/blake3/extconf.rb b/ext/digest/blake3/extconf.rb index 6d1b8f5..05c9850 100644 --- a/ext/digest/blake3/extconf.rb +++ b/ext/digest/blake3/extconf.rb @@ -24,6 +24,10 @@ # Extra per-object compiler flags, keyed by object basename. simd_cflags = {} +def blake3_disable(macro) + $CPPFLAGS << " -D#{macro}" +end + # Probe used to confirm the compiler both accepts +flag+ and can compile the # intrinsics the backend relies on. def blake3_have_isa?(name, flag, snippet) @@ -55,7 +59,7 @@ def blake3_have_isa?(name, flag, snippet) objs << obj simd_cflags[obj] = flag else - $defs << "-D#{no_macro}" + blake3_disable(no_macro) end end when /\A(aarch64|arm64)\z/i @@ -67,11 +71,11 @@ def blake3_have_isa?(name, flag, snippet) # No optimized backend wired up for this architecture (e.g. 32-bit x86, # ppc): build portable-only. Disabling every x86 ISA keeps the dispatcher # from referencing backends we didn't compile, and NEON is forced off. - $defs << "-DBLAKE3_NO_SSE2" - $defs << "-DBLAKE3_NO_SSE41" - $defs << "-DBLAKE3_NO_AVX2" - $defs << "-DBLAKE3_NO_AVX512" - $defs << "-DBLAKE3_USE_NEON=0" + blake3_disable("BLAKE3_NO_SSE2") + blake3_disable("BLAKE3_NO_SSE41") + blake3_disable("BLAKE3_NO_AVX2") + blake3_disable("BLAKE3_NO_AVX512") + blake3_disable("BLAKE3_USE_NEON=0") end $objs = objs.map { |o| "#{o}.#{$OBJEXT}" }