Skip to content

Commit e1616f9

Browse files
committed
Problem: absolute path inside dylib (fix #123)
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
1 parent 2c7ec3a commit e1616f9

File tree

5 files changed

+100
-21
lines changed

5 files changed

+100
-21
lines changed

.github/workflows/mac-build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
cp ./LICENSE build
4141
cp ./CHANGELOG.md build
4242
cd build
43+
install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib
44+
otool -L ./lib/libplay_cpp_sdk.dylib
4345
tar zcvf ../play_cpp_sdk_${PLATFORM}.tar.gz *
4446
cd ..
4547
shasum -a 256 *.tar.gz > "checksums-$PLATFORM.txt"

.github/workflows/mac-test.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Mac Build Test CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release/**
8+
paths-ignore:
9+
- README.md
10+
tags:
11+
- "v*.*.*"
12+
pull_request:
13+
paths-ignore:
14+
- README.md
15+
16+
jobs:
17+
mac-test:
18+
runs-on: macos-11
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
submodules: recursive
23+
24+
- name: Add target x86_64-apple-darwin
25+
run: rustup target add x86_64-apple-darwin
26+
27+
- name: Build play-cpp-sdk library
28+
run: ./checkmac.sh && cargo build --package play-cpp-sdk --release --target x86_64-apple-darwin
29+
30+
- name: Build demo project
31+
working-directory: demo
32+
run: make x86_64_build_test
33+
34+

README.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,9 @@ The following build events are included in the project file:
5454
git clone https://github.com/crypto-com/play-cpp-sdk.git
5555
```
5656
2. Unzip the archive file into `demo` folder
57-
3. Copy the dynamic library to `/usr/local/lib`
58-
``` sh
59-
cd demo
60-
cp lib/libplay_cpp_sdk.dylib /usr/local/lib
61-
```
62-
4. Under `demo` folder and build the `demo` project
57+
3. Under `demo` folder and build the `demo` project
6358
``` sh
64-
make
59+
make x86_64_build
6560
```
6661

6762
### Linux

demo/Makefile

+38-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@ dynamic: easywsclient.o
5353
$(FLAGS) \
5454
-L lib \
5555

56-
x86_64_build: prepare_x86_64 easywsclient.o.x86_64
56+
x86_64_test_dylib:
57+
./demo test
58+
59+
x86_64_build: x86_64_build_static x86_64_build_dynamic
60+
61+
x86_64_build_test:x86_64_build_dynamic x86_64_test_dylib
62+
63+
x86_64_build_static: prepare_x86_64 easywsclient.o.x86_64
5764
arch -x86_64 \
58-
g++ -o demo \
65+
g++ -o demostatic \
5966
easywsclient.o \
6067
main.cc \
6168
chainmain.cc \
@@ -65,6 +72,35 @@ x86_64_build: prepare_x86_64 easywsclient.o.x86_64
6572
-std=c++14 \
6673
$(FLAGS)
6774

75+
# use -rpath option to add the path to the dynamic library loading path
76+
# -rpath lib in gcc or
77+
# install_name_tool -add_rpath @executable_path/lib ./demo
78+
# in mac, to use DYLD_LIBRARY_PATH, it is normalized to use $rpath in dylib
79+
x86_64_build_dynamic : prepare_x86_64 easywsclient.o.x86_64
80+
install_name_tool -id @rpath/libplay_cpp_sdk.dylib ./lib/libplay_cpp_sdk.dylib
81+
otool -L ./lib/libplay_cpp_sdk.dylib
82+
arch -x86_64 \
83+
g++ -o demo \
84+
easywsclient.o \
85+
main.cc \
86+
chainmain.cc \
87+
cronos.cc \
88+
extra.cc \
89+
./include/walletconnectcallback.cc \
90+
./include/nft.cc \
91+
./include/pay.cc \
92+
./include/defi-wallet-core-cpp/src/contract.rs.cc \
93+
./include/defi-wallet-core-cpp/src/core.cc \
94+
./include/defi-wallet-core-cpp/src/nft.rs.cc \
95+
./include/defi-wallet-core-cpp/src/uint.rs.cc \
96+
./include/extra-cpp-bindings/src/lib.rs.cc \
97+
lib/libplay_cpp_sdk.dylib \
98+
lib/libcxxbridge1.a \
99+
-std=c++14 \
100+
-rpath lib
101+
$(FLAGS)
102+
103+
68104
run_static:
69105
. ./.env && ./demostatic
70106

demo/main.cc

+24-12
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,33 @@
1717
#include <thread>
1818

1919
int main(int argc, char *argv[]) {
20-
try {
21-
chainmain_process(); // chain-main
22-
test_chainmain_nft(); // chainmain nft tests
23-
test_login(); // decentralized login
24-
cronos_process(); // cronos
25-
test_cronos_testnet(); // cronos testnet
26-
} catch (const rust::cxxbridge1::Error &e) {
27-
// Use `Assertion failed`, the same as `assert` function
20+
if (argc >= 2) {
21+
if ("test" == std::string(argv[1])) {
22+
// check wheter calling works
23+
try {
24+
test_wallet_connect();
25+
} catch (const std::exception &e) {
2826
std::cout << "Assertion failed: " << e.what() << std::endl;
27+
}
28+
return 0;
2929
}
30+
}
3031

31-
test_interval();
32+
try {
33+
chainmain_process(); // chain-main
34+
test_chainmain_nft(); // chainmain nft tests
35+
test_login(); // decentralized login
36+
cronos_process(); // cronos
37+
test_cronos_testnet(); // cronos testnet
38+
} catch (const rust::cxxbridge1::Error &e) {
39+
// Use `Assertion failed`, the same as `assert` function
40+
std::cout << "Assertion failed: " << e.what() << std::endl;
41+
}
3242

33-
test_blackscout_cronoscan();
34-
test_wallet_connect();
43+
test_interval();
3544

36-
return 0;
45+
test_blackscout_cronoscan();
46+
test_wallet_connect();
47+
48+
return 0;
3749
}

0 commit comments

Comments
 (0)