matusnovak / wrenbind17

A header only library for binding C++17 classes and functions to Wren, an embeddable programming language
https://matusnovak.github.io/wrenbind17
MIT License
65 stars 10 forks source link

Add Support for M1 Macs #11

Closed PossiblyAShrub closed 1 year ago

PossiblyAShrub commented 1 year ago

While I was trying to run a project of mine on MacOS, I encountered some build errors from wrenbind17. They could be reproduced with the snippet below. The main problem was that each header was not self-sufficient and thus had missing includes on MacOS.

// main.cpp (in the repository root)
#include <wrenbind17/wrenbind17.hpp>

int main() { return 0; }

Then running clang main.cpp -I./libs/wren/src/include -I./include -std=c++17 resulted in the following beast:

Lengthy error message
In file included from main.cpp:1:
In file included from ././include/wrenbind17/wrenbind17.hpp:8:
In file included from ././include/wrenbind17/std.hpp:3:
././include/wrenbind17/module.hpp:93:34: error: implicit instantiation of undefined template 'std::vector'
        std::vector raw;
                                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:259:28: note: template is declared here
class _LIBCPP_TEMPLATE_VIS vector;
                           ^
In file included from main.cpp:1:
In file included from ././include/wrenbind17/wrenbind17.hpp:8:
In file included from ././include/wrenbind17/std.hpp:3:
In file included from ././include/wrenbind17/module.hpp:4:
In file included from ././include/wrenbind17/foreign.hpp:7:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/unordered_map:836:76: error: binding reference of type 'pair<...>' to value of type 'const pair<...>' drops 'const' qualifier
    pointer operator->() const {return pointer_traits::pointer_to(__i_->__get_value());}
                                                                           ^~~~~~~~~~~~~~~~~~~
././include/wrenbind17/vm.hpp:88:38: note: in instantiation of member function 'std::__hash_map_iterator, void *> *>>::operator->' requested here
                    auto source = mod->second.str();
                                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/pointer_traits.h:153:67: note: passing argument to parameter '__r' here
                                      __nat, element_type>::type& __r) _NOEXCEPT
                                                                  ^
In file included from main.cpp:1:
In file included from ././include/wrenbind17/wrenbind17.hpp:8:
In file included from ././include/wrenbind17/std.hpp:3:
In file included from ././include/wrenbind17/module.hpp:4:
In file included from ././include/wrenbind17/foreign.hpp:7:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/unordered_map:437:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:2107:29: error: cannot initialize objectparameter of type 'std::__hash_node_base, void *> *>' with an expression of type 'std::__hash_node, void *>'
            __pn->__next_ = __h.get()->__ptr();
                            ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:1115:14: note: in instantiation of function template specialization 'std::__hash_table, std::__unordered_map_hasher, std::hash, std::equal_to, true>, std::__unordered_map_equal, std::equal_to, std::hash, true>, std::allocator>>::__emplace_unique_key_args>' requested here
      return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:1079:14: note: in instantiation of function template specialization 'std::__hash_table, std::__unordered_map_hasher, std::hash, std::equal_to, true>, std::__unordered_map_equal, std::equal_to, std::hash, true>, std::allocator>>::__emplace_unique_extract_key>' requested here
      return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:1137:14: note: in instantiation of function template specialization 'std::__hash_table, std::__unordered_map_hasher, std::hash, std::equal_to, true>, std::__unordered_map_equal, std::equal_to, std::hash, true>, std::allocator>>::__emplace_unique>' requested here
      return __emplace_unique(_VSTD::forward<_Pp>(__x));
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/unordered_map:1141:30: note: in instantiation of function template specialization 'std::__hash_table, std::__unordered_map_hasher, std::hash, std::equal_to, true>, std::__unordered_map_equal, std::equal_to, std::hash, true>, std::allocator>>::__insert_unique, void>' requested here
            {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
                             ^
././include/wrenbind17/vm.hpp:280:36: note: in instantiation of function template specialization 'std::unordered_map::insert, void>' requested here
                it = data->modules.insert(std::make_pair(name, ForeignModule(name, data->vm.get()))).first;
                                   ^
In file included from main.cpp:1:
In file included from ././include/wrenbind17/wrenbind17.hpp:8:
In file included from ././include/wrenbind17/std.hpp:3:
In file included from ././include/wrenbind17/module.hpp:4:
In file included from ././include/wrenbind17/foreign.hpp:7:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/unordered_map:437:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:2112:23: error: cannot initialize objectparameter of type 'std::__hash_node_base, void *> *>' with an expression of type 'std::__hash_node, void *>'
                    = __h.get()->__ptr();
                      ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__hash_table:2119:16: error: static_cast from 'std::unique_ptr, void *>, std::__hash_node_destructor, void *>>>>::pointer' (aka 'std::__hash_node, void*> *') to 'std::__hash_table, std::__unordered_map_hasher, std::hash, std::equal_to, true>, std::__unordered_map_equal, std::equal_to, std::hash, true>, std::allocator>>::__next_pointer' (aka 'std::__hash_node_base, void *> *> *'), which are not related by inheritance, is not allowed
        __nd = static_cast<__next_pointer>(__h.release());
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 errors generated.

Another issue was that the version of Catch2 used by wrenbind17's test suite did not support M1 macs. I've updated to the latest version which fixes the issue.

Changes

codecov-commenter commented 1 year ago

Codecov Report

Merging #11 (0c7fd2e) into master (5b0b08b) will not change coverage. The diff coverage is n/a.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##           master      #11   +/-   ##
=======================================
  Coverage   89.52%   89.52%           
=======================================
  Files          20       20           
  Lines        1327     1327           
=======================================
  Hits         1188     1188           
  Misses        139      139           
Impacted Files Coverage Δ
include/wrenbind17/allocator.hpp 100.00% <ø> (ø)
include/wrenbind17/any.hpp 95.77% <ø> (ø)
include/wrenbind17/caller.hpp 97.10% <ø> (ø)
include/wrenbind17/exception.hpp 100.00% <ø> (ø)
include/wrenbind17/foreign.hpp 92.59% <ø> (ø)
include/wrenbind17/handle.hpp 96.15% <ø> (ø)
include/wrenbind17/method.hpp 96.00% <ø> (ø)
include/wrenbind17/module.hpp 96.96% <ø> (ø)
include/wrenbind17/object.hpp 79.41% <ø> (ø)
include/wrenbind17/pop.hpp 92.12% <ø> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

matusnovak commented 1 year ago

Hi @PossiblyAShrub

Thank you for the PR. I do not have M1 Mac to test it out so I will trust you :D I like that you have also included a new test tests/can_compile.cpp. I did not think of that before.