diff --git a/.github/workflows/mac-build.yml b/.github/workflows/mac-build.yml index 435e6dd9..f23143d7 100644 --- a/.github/workflows/mac-build.yml +++ b/.github/workflows/mac-build.yml @@ -40,6 +40,8 @@ jobs: cp ./LICENSE build cp ./CHANGELOG.md build cd build + install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib + otool -L ./lib/libplay_cpp_sdk.dylib tar zcvf ../play_cpp_sdk_${PLATFORM}.tar.gz * cd .. shasum -a 256 *.tar.gz > "checksums-$PLATFORM.txt" diff --git a/demo/Makefile b/demo/Makefile index 16d61135..662c1202 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -53,9 +53,14 @@ dynamic: easywsclient.o $(FLAGS) \ -L lib \ -x86_64_build: prepare_x86_64 easywsclient.o.x86_64 +x86_64_test_dylib: + ./demo test + +x86_64_build: x86_64_build_static x86_64_build_dynamic x86_64_test_dylib + +x86_64_build_static: prepare_x86_64 easywsclient.o.x86_64 arch -x86_64 \ - g++ -o demo \ + g++ -o demostatic \ easywsclient.o \ main.cc \ chainmain.cc \ @@ -65,6 +70,35 @@ x86_64_build: prepare_x86_64 easywsclient.o.x86_64 -std=c++14 \ $(FLAGS) +# use -rpath option to add the path to the dynamic library loading path +# -rpath lib in gcc or +# install_name_tool -add_rpath @executable_path/lib ./demo +# in mac, to use DYLD_LIBRARY_PATH, it is normalized to use $rpath in dylib +x86_64_build_dynamic : prepare_x86_64 easywsclient.o.x86_64 + install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib + otool -L ./lib/libplay_cpp_sdk.dylib + arch -x86_64 \ + g++ -o demo \ + easywsclient.o \ + main.cc \ + chainmain.cc \ + cronos.cc \ + extra.cc \ + ./include/walletconnectcallback.cc \ + ./include/nft.cc \ + ./include/pay.cc \ + ./include/defi-wallet-core-cpp/src/contract.rs.cc \ + ./include/defi-wallet-core-cpp/src/core.cc \ + ./include/defi-wallet-core-cpp/src/nft.rs.cc \ + ./include/defi-wallet-core-cpp/src/uint.rs.cc \ + ./include/extra-cpp-bindings/src/lib.rs.cc \ + lib/libplay_cpp_sdk.dylib \ + lib/libcxxbridge1.a \ + -std=c++14 \ + -rpath lib + $(FLAGS) + + run_static: . ./.env && ./demostatic diff --git a/demo/main.cc b/demo/main.cc index d1c385a7..907a97bf 100644 --- a/demo/main.cc +++ b/demo/main.cc @@ -17,21 +17,33 @@ #include int main(int argc, char *argv[]) { - try { - chainmain_process(); // chain-main - test_chainmain_nft(); // chainmain nft tests - test_login(); // decentralized login - cronos_process(); // cronos - test_cronos_testnet(); // cronos testnet - } catch (const rust::cxxbridge1::Error &e) { - // Use `Assertion failed`, the same as `assert` function + if (argc >= 2) { + if ("test" == std::string(argv[1])) { + // check wheter calling works + try { + test_wallet_connect(); + } catch (const std::exception &e) { std::cout << "Assertion failed: " << e.what() << std::endl; + } + return 0; } + } - test_interval(); + try { + chainmain_process(); // chain-main + test_chainmain_nft(); // chainmain nft tests + test_login(); // decentralized login + cronos_process(); // cronos + test_cronos_testnet(); // cronos testnet + } catch (const rust::cxxbridge1::Error &e) { + // Use `Assertion failed`, the same as `assert` function + std::cout << "Assertion failed: " << e.what() << std::endl; + } - test_blackscout_cronoscan(); - test_wallet_connect(); + test_interval(); - return 0; + test_blackscout_cronoscan(); + test_wallet_connect(); + + return 0; }