fireblocks / mpc-lib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to run it on mac m1 machine

aabdullah29 opened this issue · comments

Firstly, I appreciate this README; it's very helpful for me. I successfully ran this code on Ubuntu OS using the provided instructions. However, I am unable to run it on my Mac M1 machine. Please let me know if this code supports macOS. If so, could you please guide me on how to run it on macOS?

feel free to check the PRs #20 and #22. With those patches and cmake you will be able to create the libcosigner.dylib
At the moment I can verify it builds with -DMPC_LIB_SKIP_TESTS=ON

Thanks for your response. I updated the mentioned patches, and now I encounter this error:

CXX  <=  cosigner/cosigner_exception.cpp
clang: error: unsupported argument 'skylake' to option '-march='

have you tried building with cmake?

CMake works for me. Could you please guide me on what I should do next?

will you be able to build and install cmake and openssl dev headers (dependencies)? You can build those by yourself on macOS or use Homebrew (https://brew.sh).
I prefer to build them separately and have a pet project if you prefer: https://github.com/kozyilmaz/tools
A simplified version of my command line looks like this once you have everything you need:

PKG_CONFIG_PATH=$ROOT/lib/pkgconfig \
cmake -DCMAKE_INSTALL_PREFIX=$ROOT \
-DCMAKE_SHARED_LIBRARY_SUFFIX_CXX=".so" \
-DBUILD_SHARED_LIBS=OFF \
-DMPC_LIB_SKIP_TESTS=ON \
-DOPENSSL_ROOT_DIR=$ROOT \
. \

Thank you for helping me. The build was created successfully. Now, how can I run the test scripts?

Signing tests still have some compilation issues (at least on macOS Sonoma), looking into those for now.

[ 44%] Building CXX object test/cosigner/CMakeFiles/cosigner_test.dir/ecdsa_offline_test.cpp.o
In file included from /Users/loki/devel/sentinel/mpc-lib/mpc-lib-latest/test/cosigner/ecdsa_offline_test.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/chrono:771:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__chrono/calendar.h:13:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__chrono/duration.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__compare/three_way_comparable.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__compare/common_comparison_category.h:15:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/cstddef:46:5: error: <cstddef> tried including <stddef.h> but didn't find libc++'s <stddef.h> header.           This usually means that your header search paths are not configured properly.           The header search paths should contain the C++ Standard Library headers before           any C Standard Library, and you are probably using compiler flags that make that           not be the case.
#   error <cstddef> tried including <stddef.h> but didn't find libc++'s <stddef.h> header. \
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/cstddef:59:9: error: no member named 'nullptr_t' in the global namespace
using ::nullptr_t;
      ~~^
In file included from /Users/loki/devel/sentinel/mpc-lib/mpc-lib-latest/test/cosigner/ecdsa_offline_test.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/chrono:771:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__chrono/calendar.h:13:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__chrono/duration.h:20:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/limits:827:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/type_traits:456:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__type_traits/is_compound.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__type_traits/is_fundamental.h:14:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__type_traits/is_null_pointer.h:26:28: error: use of undeclared identifier 'nullptr_t'; did you mean 'nullptr'?
struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
                           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__type_traits/is_null_pointer.h:26:28: error: template argument for template type parameter must be a type
struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
                           ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__type_traits/is_null_pointer.h:23:17: note: template parameter is declared here
template <class _Tp>
                ^

I also get the same error.

Hey @aabdullah29, I made it compile and run on macOS, you can use #20, #22 #27, #28 patches and you should specify libuuid paths explicitly.
Quick recap on the error you see: cmake is pointing UUID_INCLUDE_PATH to macOS kernel headers which causes the C++ header confusion
UUID_INCLUDE_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/Kernel.framework/Headers

Anyway, here is my compile command:

( cd mpc-lib-latest && mkdir -p _build && cd _build; \
		PKG_CONFIG_PATH=/Users/loki/devel/sentinel/release/arm64/lib/pkgconfig \
		cmake -DCMAKE_INSTALL_PREFIX=/Users/loki/devel/sentinel/release/arm64 \
		-DCMAKE_C_COMPILER=gcc \
		-DCMAKE_CXX_COMPILER=g++ \
		-DCMAKE_C_FLAGS="-fPIC " \
		-DCMAKE_CXX_FLAGS="-fPIC " \
		-DCMAKE_EXE_LINKER_FLAGS=" " \
		-DCMAKE_SHARED_LINKER_FLAGS=" " \
		-DCMAKE_STATIC_LINKER_FLAGS=" " \
		-DCMAKE_SHARED_LIBRARY_SUFFIX_CXX=".so" \
		-DBUILD_SHARED_LIBS=OFF \
		-DOPENSSL_ROOT_DIR=/Users/loki/devel/sentinel/release/arm64 \
		-DUUID_INCLUDE_DIR=/Users/loki/devel/sentinel/release/arm64/include \
		-DUUID_LIBRARY=/Users/loki/devel/sentinel/release/arm64/lib/libuuid.a \
		.. \
	)
-- The C compiler identification is AppleClang 15.0.0.15000309
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /Users/loki/devel/sentinel/release/arm64/lib/libcrypto.a (found suitable version "1.1.1w", minimum required is "1.1.1")
-- UUID_LIBRARY=/Users/loki/devel/sentinel/release/arm64/lib/libuuid.a
-- UUID_INCLUDE_DIR=/Users/loki/devel/sentinel/release/arm64/include
-- Found UUID: /Users/loki/devel/sentinel/release/arm64/lib/libuuid.a
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/loki/devel/sentinel/mpc-lib/mpc-lib-latest/_build

It will compile everything and then you can run cosigner_test under mpc-lib/_build/test/cosigner

and it looks like all cosigner_test passes successfully on macOS
All tests passed (2366 assertions in 4 test cases)

Hey @nadav-fireblocks @igorkh-fb may I get your feedback on upstreaming #20, #22, #27, #28 to support macOS builds?

@kozyilmaz Thank you! I tried it, but I'm facing some issues with the UUID. I will try to fix it, and hopefully, it will work afterward. I appreciate your cooperation.

@kozyilmaz your changes are welcomed, although they still have not gone through review. I'm sure they will serve many.

Splitting your changes into multiple pull requests is very much appreciated. Do you maintain a fork with all of them combined?

Compilation in macOS was a non goal of this project so far as there are docker based workarounds, which lowers the prioritization of upstreaming the changes. Note that we have no CI testing for macOS, which means support for macOS may stop working.

The essential reason for the delay is several internal issues and conflicts (unrelated to your changes) that we/myself will resolve first before merging your code.

Hi @nadav-fireblocks thank you for your swift reply!

Below is the fork and branch that all patches are committed:
https://github.com/kozyilmaz/mpc-lib/tree/macos-support

About CI for macOS, I have a project that helps me create statically linked binaries on macOS and I manage dependencies with it. Currently I build all mpc-lib dependencies from that repo:
https://github.com/kozyilmaz/tools/tree/master/packages
Long story short I can create a dependency.sh script that can be used for macOS CI, if you are ok with it

Please take your time, I appreciate Fireblocks' OSS commitment and just trying to make it better.