protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.34k stars 15.45k forks source link

Issue with x86 Windows builds (MSVC) and ABSL usage of intrinsics #18503

Open imrichardcole opened 3 days ago

imrichardcole commented 3 days ago

What version of protobuf and what language are you using?

28.0

What operating system (Linux, Windows, ...) and version?

Windows 10 Enterprise and Windows 2016 server

What runtime / compiler are you using (e.g., python version or gcc version)

Latest MSVC v143

What did you do?

I've built protobuf from the v28.0 tag using MSVC v143. I then go onto use these builds in my own project. My x64 build compiles without issue, but I run into errors when building x86.

What did you expect to see

A build that works on both x64 and x86.

What did you see instead?

I get the following two C3861 compiler errors:

'_mm_crc32_u64': identifier not found
'_mm_cvtsi128_si64': identifier not found

In both cases the error is coming from the crc32_x86_arm_combined_simd.h header file. This comes in as an absl submodule via the protobuf git repo.

Perhaps the issue is in how I'm compiling protobuf? The only CMake arg that stands out is my usage of -Dprotobuf_MSVC_STATIC_RUNTIME=OFF

Some intrinsic functions are found e.g _mm_crc32_u16 and they're picked up from include\intrin.h and include\nmmintrin.h as part of the MSVC distribution.

imrichardcole commented 3 days ago

To work around this, I can set the following in my own CMakeLists.txt:

if(32_BIT_BUILD)
  add_definitions(ProjectLib "/arch:SSE2")
endif()

But would need to understand this workaround in the context of the wider application.