-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild-static-libraries.sh
executable file
·100 lines (69 loc) · 3.71 KB
/
build-static-libraries.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
set -ex
#############################################################################################################################
## Copy GHC libs
mkdir -p /target/{profiling,vanilla}/{ghc,dependencies,concordium}
mkdir -p /binaries/{lib,bin}
LIB_DIR=$(stack --stack-yaml /build/concordium-consensus/stack.static.yaml ghc -- --print-libdir)
find "$LIB_DIR" -type f -name "*_p.a" ! -name "*_debug_p.a" ! -name "*rts_p.a" ! -name "*ffi_p.a" -exec cp {} /target/profiling/ghc/ \;
find "$LIB_DIR" -type f -name "*.a" ! -name "*_p.a" ! -name "*_l.a" ! -name "*_debug.a" ! -name "*rts.a" ! -name "*ffi.a" -exec cp {} /target/vanilla/ghc/ \;
cd /build
#############################################################################################################################
## Build the project
stack build --profile --flag "concordium-consensus:-dynamic" --stack-yaml /build/concordium-consensus/stack.static.yaml
find /build/concordium-consensus/.stack-work -type f -name "*.a" ! -name "*_p.a" -exec cp {} /target/vanilla/concordium/ \;
find /build/concordium-consensus/.stack-work -type f -name "*_p.a" -exec cp {} /target/profiling/concordium/ \;
#############################################################################################################################
## Copy rust binaries
LOCAL_INSTALL_ROOT=$(stack --stack-yaml /build/concordium-consensus/stack.static.yaml path --profile --local-install-root)
cp "$LOCAL_INSTALL_ROOT"/bin/{generate-update-keys,genesis,database-exporter} /binaries/bin/
cp /build/concordium-base/rust-src/target/release/*.so /binaries/lib/
cp /build/concordium-base/smart-contracts/wasm-chain-integration/target/release/*.so /binaries/lib/
#############################################################################################################################
## Copy dependencies
find ~/.stack/snapshots/x86_64-linux/ -type f -name "*.a" ! -name "*_p.a" -exec cp {} /target/vanilla/dependencies \;
find ~/.stack/snapshots/x86_64-linux/ -type f -name "*_p.a" -exec cp {} /target/profiling/dependencies \;
mkdir -p /target/rust
cp -r /build/concordium-base/rust-src/target/release/*.a /target/rust/
find /target /binaries -type f -exec strip --strip-debug {} \;
#############################################################################################################################
## Remove ruststd symbols from rust libraries
(
cd /target/rust
for i in $(ls)
do
ar x $i;
rm $i;
done
set +e
for file in $(find . -type f -name "*.o"); do
if nm $file | grep "\(T __rust_alloc\)\|\(T __rdl_alloc\)\|\(T __clzsi2\)\|\(T rust_eh_personality\)" >> /dev/null; then
echo "Removing file:";
echo $file;
rm $file;
fi
done
set -e
ar rcs libRcrypto.a *.o
rm *.o
cp /build/concordium-base/smart-contracts/wasm-chain-integration/target/release/libconcordium_smart_contract_engine.a /target/rust/libconcordium_smart_contract_engine.a
ar x libconcordium_smart_contract_engine.a
set +e
for file in $(find . -type f -name "*.o"); do
nm $file | grep "\(T __rust_alloc\)\|\(T __rdl_alloc\)\|\(T __clzsi2\)\|\(T rust_eh_personality\)" >> /dev/null;
if [ $? -eq 0 ]; then
echo "Removing file:"
echo $file
rm $file;
fi
done
set -e
rm libconcordium_smart_contract_engine.a
ar rcs libconcordium_smart_contract_engine.a *.o
rm *.o
)
cd /build
#############################################################################################################################
tar czf static-consensus-$GHC_VERSION.tar.gz /target
tar czf static-consensus-binaries-$GHC_VERSION.tar.gz /binaries
rm -rf /target /binaries