Skip to content

Commit

Permalink
Problem: absolute path inside dylib (fix #123)
Browse files Browse the repository at this point in the history
add x86_64 dylib build

update Makefile

test dylib works

fix main

reformat

add rpath option

add rpath comment

 add more comment

remove un-necessary

change readme

make simple

add or

typo

add or for windows

restore readme

untar

restore

disable test

separate test

change name

tidyup test

fix compile option

add comment

remove mac-test
  • Loading branch information
leejw51crypto committed Jun 30, 2022
1 parent 59501a7 commit c9f320f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/mac-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
- name: Build play-cpp-sdk library
run: ./checkmac.sh && cargo build --package play-cpp-sdk --release --target x86_64-apple-darwin

- name: Test building demo project
working-directory: demo
run: make x86_64_build_test

- name: Build demo project
working-directory: demo
run: make x86_64_build
Expand All @@ -40,6 +44,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"
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ The following build events are included in the project file:
git clone https://github.com/crypto-com/play-cpp-sdk.git
```
2. Unzip the archive file into `demo` folder
3. Copy the dynamic library to `/usr/local/lib`
``` sh
cd demo
cp lib/libplay_cpp_sdk.dylib /usr/local/lib
```
4. Under `demo` folder and build the `demo` project
3. Under `demo` folder and build the `demo` project
``` sh
make
make x86_64_build
```

### Linux
Expand Down
41 changes: 39 additions & 2 deletions demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@ dynamic: easywsclient.o
$(FLAGS) \
-L lib \

x86_64_build: prepare_x86_64 easywsclient.o.x86_64
# test whether dylib loading correctly
x86_64_test_dylib:
./demo test

x86_64_build: x86_64_build_static x86_64_build_dynamic

x86_64_build_test: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 \
Expand All @@ -65,6 +73,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

Expand Down
37 changes: 25 additions & 12 deletions demo/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,34 @@
#include <thread>

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_login();
std::cout<<"OK"<<std::endl;
} 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;
}

0 comments on commit c9f320f

Please sign in to comment.