I'm trying to compile Dawn with cmake & ninja using clang installed via homebrew on macos.
/opt/homebrew/opt/llvm/bin/clang++ --version
Homebrew clang version 18.1.7
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
The compilation fails with the following error:
FAILED: dawn/third_party/abseil/absl/random/CMakeFiles/absl_random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o
/opt/homebrew/opt/llvm/bin/clang++ -I/Users/dimaafanasev/curiosity/dawn/third_party/abseil-cpp -O2 -g -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk -fPIC -Wno-array-parameter -Wno-deprecated-builtins -Wno-unknown-warning-option -Wall -Wextra -Wcast-qual -Wconversion -Wfloat-overflow-conversion -Wfloat-zero-conversion -Wfor-loop-analysis -Wformat-security -Wgnu-redeclared-enum -Winfinite-recursion -Winvalid-constexpr -Wliteral-conversion -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wself-assign -Wshadow-all -Wshorten-64-to-32 -Wsign-conversion -Wstring-conversion -Wtautological-overlap-compare -Wtautological-unsigned-zero-compare -Wundef -Wuninitialized -Wunreachable-code -Wunused-comparison -Wunused-local-typedefs -Wunused-result -Wvla -Wwrite-strings -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -DNOMINMAX -Xarch_x86_64 -maes -msse4.1 -Xarch_arm64 -march=armv8-a+crypto -Wno-unused-command-line-argument -MD -MT dawn/third_party/abseil/absl/random/CMakeFiles/absl_random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o -MF dawn/third_party/abseil/absl/random/CMakeFiles/absl_random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o.d -o dawn/third_party/abseil/absl/random/CMakeFiles/absl_random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o -c /Users/dimaafanasev/curiosity/dawn/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc
clang++: error: unsupported option '-msse4.1' for target 'arm64-apple-darwin23.5.0'
The issue is caused by lines 13-54 in dawn/third_party/abseil-cpp/absl/copts/AbseilConfigureCopts.cmake
.
Relevant part of the comment states:
...
# When compiling for multiple architectures, a build system can invoke a
# compiler either
#
# - once: a single command line for multiple architectures (Ninja build)
# - twice: two command lines per each architecture (Xcode build system)
#
# If case of Xcode, it would be possible to set an Xcode-specific attributes
# like XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=arm64] or similar.
#
# In both cases, the viable strategy is to pass all arguments at once, allowing
# the compiler to dispatch arch-specific arguments to a designated backend.
But it's not the viable strategy, since clang fails with unsupported options. It might be bug in clang, but I'm not skilled enough to say for sure.
Simply removing the x86_64
on line 41 in the relevant file fixes the issue:
# In both cases, the viable strategy is to pass all arguments at once, allowing
# the compiler to dispatch arch-specific arguments to a designated backend.
set(ABSL_RANDOM_RANDEN_COPTS "")
- foreach(_arch IN ITEMS "x86_64" "arm64")
+ foreach(_arch IN ITEMS "arm64")
string(TOUPPER "${_arch}" _arch_uppercase)
string(REPLACE "X86_64" "X64" _arch_uppercase ${_arch_uppercase})
foreach(_flag IN LISTS ABSL_RANDOM_HWAES_${_arch_uppercase}_FLAGS)
But it's not a proper fix, since the purpose of this config is to support compilation for multiple architectures.
It's seems that bug is already reported in absl library: abseil/abseil-cpp#1241