binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Cannot build on MacOS

Open VillainsRule opened this issue 8 months ago • 1 comments

Here's the error log. Using normal cmake command as instructed in README.

[ 76%] Building CXX object CMakeFiles/binaryen.dir/src/wasm/wasm-debug.cpp.o In file included from /Users/user/Downloads/binaryen/src/wasm/wasm-debug.cpp:21: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ObjectYAML/DWARFEmitter.h:15: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:16: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringRef.h:12: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/STLExtras.h:21: /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/iterator.h:68:19: error: 'iterator<std::forward_iterator_tag, llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' is deprecated [-Werror,-Wdeprecated-declarations] 68 | : public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT, | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:489:14: note: in instantiation of template class 'llvm::iterator_facade_base<llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>, std::forward_iterator_tag, llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' requested here 489 | : public iterator_facade_base<DerivedTy, std::forward_iterator_tag, | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:548:34: note: in instantiation of template class 'llvm::StringMapIterBase<llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>, llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' requested here 548 | class StringMapIterator : public StringMapIterBase<StringMapIterator<ValueTy>, | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/pair.h:74:7: note: in instantiation of template class 'llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>' requested here 74 | _T1 first; | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:378:47: note: in instantiation of template class 'std::pair<llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>, bool>' requested here 378 | ValueTy &operator[](StringRef Key) { return try_emplace(Key).first->second; } | ^ /Users/user/Downloads/binaryen/src/wasm/wasm-debug.cpp:59:17: note: in instantiation of member function 'llvm::StringMap<std::unique_ptrllvm::MemoryBuffer>::operator[]' requested here 59 | sections[section.name.substr(1)] = llvm::MemoryBuffer::getMemBufferCopy( | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__iterator/iterator.h:23:29: note: 'iterator<std::forward_iterator_tag, llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' has been explicitly marked deprecated here 23 | struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator { | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:731:41: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX17' 731 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:696:49: note: expanded from macro '_LIBCPP_DEPRECATED' 696 | # define _LIBCPP_DEPRECATED attribute((deprecated)) | ^ In file included from /Users/user/Downloads/binaryen/src/wasm/wasm-debug.cpp:21: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ObjectYAML/DWARFEmitter.h:15: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:16: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringRef.h:12: In file included from /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/STLExtras.h:21: /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/iterator.h:68:19: error: 'iterator<std::forward_iterator_tag, const llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' is deprecated [-Werror,-Wdeprecated-declarations] 68 | : public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT, | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:489:14: note: in instantiation of template class 'llvm::iterator_facade_base<llvm::StringMapConstIterator<std::unique_ptrllvm::MemoryBuffer>, std::forward_iterator_tag, const llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' requested here 489 | : public iterator_facade_base<DerivedTy, std::forward_iterator_tag, | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:531:14: note: in instantiation of template class 'llvm::StringMapIterBase<llvm::StringMapConstIterator<std::unique_ptrllvm::MemoryBuffer>, const llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' requested here 531 | : public StringMapIterBase<StringMapConstIterator<ValueTy>, | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/is_constructible.h:24:103: note: in instantiation of template class 'llvm::StringMapConstIterator<std::unique_ptrllvm::MemoryBuffer>' requested here 24 | struct _LIBCPP_TEMPLATE_VIS is_constructible : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {}; | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/pair.h:158:14: note: in instantiation of template class 'std::is_constructible<llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>, const llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer> &>' requested here 158 | return is_constructible<first_type, _U1>::value && is_constructible<second_type, _U2>::value; | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/pair.h:177:59: note: in instantiation of function template specialization 'std::pair<llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>, bool>::_CheckArgs::__is_pair_constructible<const llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer> &, const bool &>' requested here 177 | __enable_if_t<_CheckArgsDep<_Dummy>::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0> | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/pair.h:180:7: note: while substituting prior template arguments into non-type template parameter [with _Dummy = true] 180 | pair(_T1 const& __t1, _T2 const& __t2) noexcept(is_nothrow_copy_constructible<first_type>::value && | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 181 | is_nothrow_copy_constructible<second_type>::value) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 182 | : first(__t1), second(__t2) {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/pair.h:577:10: note: while substituting deduced template arguments into function template 'pair' [with _Dummy = (no value), $1 = (no value)] 577 | return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>( | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:436:19: note: in instantiation of function template specialization 'std::make_pair<llvm::StringMapIterator<std::unique_ptrllvm::MemoryBuffer>, bool>' requested here 436 | return std::make_pair(iterator(TheTable + BucketNo, false), | ^ /Users/user/Downloads/binaryen/third_party/llvm-project/include/llvm/ADT/StringMap.h:378:47: note: in instantiation of function template specialization 'llvm::StringMap<std::unique_ptrllvm::MemoryBuffer>::try_emplace<>' requested here 378 | ValueTy &operator[](StringRef Key) { return try_emplace(Key).first->second; } | ^ /Users/user/Downloads/binaryen/src/wasm/wasm-debug.cpp:59:17: note: in instantiation of member function 'llvm::StringMap<std::unique_ptrllvm::MemoryBuffer>::operator[]' requested here 59 | sections[section.name.substr(1)] = llvm::MemoryBuffer::getMemBufferCopy( | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__iterator/iterator.h:23:29: note: 'iterator<std::forward_iterator_tag, const llvm::StringMapEntry<std::unique_ptrllvm::MemoryBuffer>>' has been explicitly marked deprecated here 23 | struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator { | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:731:41: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX17' 731 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:696:49: note: expanded from macro '_LIBCPP_DEPRECATED' 696 | # define _LIBCPP_DEPRECATED attribute((deprecated)) | ^ 2 errors generated. make[2]: *** [CMakeFiles/binaryen.dir/src/wasm/wasm-debug.cpp.o] Error 1 make[1]: *** [CMakeFiles/binaryen.dir/all] Error 2 make: *** [all] Error 2 user@null binaryen %

VillainsRule avatar May 16 '25 17:05 VillainsRule

Does setting ENABLE_WERROR=OFF in the CMakeCache.txt or via cmake -DENABLE_ERROR=OFF ... fix it?

tlively avatar May 16 '25 18:05 tlively

Encountering the same error. @tlively -DENABLE_ERROR=OFF didn't fix it

davebryson avatar Jun 22 '25 11:06 davebryson

Encountering the same error. @tlively -DENABLE_ERROR=OFF didn't fix it

Glad to know it's not just me! What MacOS system version are you using (M1, etc)?

VillainsRule avatar Jun 22 '25 22:06 VillainsRule

It's not ideal, but you should be able to at least work around this by adding -Wno-deprecated-declarations to CMAKE_CXX_FLAGS. Can you also share an updated log from the build with ENABLE_WERROR=OFF? I would have expected that to fix this.

tlively avatar Jun 23 '25 21:06 tlively

Just hit this myself. Looks to me like the root of the issue is that a header included from LLVM is using std::iterator which is deprecated in C++17. Combined with -Werror being enabled, that's an error.

My workaround is to patch wasm-debug.cpp like so:

diff --git a/src/wasm/wasm-debug.cpp b/src/wasm/wasm-debug.cpp
index abe1cd05c..06df94ab6 100644
--- a/src/wasm/wasm-debug.cpp
+++ b/src/wasm/wasm-debug.cpp
@@ -18,7 +18,18 @@
 #include "wasm.h"
 
 #ifdef BUILD_LLVM_DWARF
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "llvm/ObjectYAML/DWARFEmitter.h"
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 #include "llvm/ObjectYAML/DWARFYAML.h"
 #include "llvm/include/llvm/DebugInfo/DWARFContext.h"

which suppresses the deprecation warning from the offending LLVM header without disabling any other diagnostics.

aiusepsi avatar Jul 02 '25 20:07 aiusepsi