-
Notifications
You must be signed in to change notification settings - Fork 34
/
build.sh
executable file
·185 lines (169 loc) · 5.8 KB
/
build.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
set -ex
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*)
EXE_SUFFIX=
if [[ "$(uname -m)" == "arm64" ]] || [[ "$(uname -m)" == "aarch64" ]]; then
HOST_TRIPLE=aarch64-apple-darwin
ARTIFACT=platform-tools-osx-aarch64.tar.bz2
else
HOST_TRIPLE=x86_64-apple-darwin
ARTIFACT=platform-tools-osx-x86_64.tar.bz2
fi;;
MINGW*)
EXE_SUFFIX=.exe
HOST_TRIPLE=x86_64-pc-windows-msvc
ARTIFACT=platform-tools-windows-x86_64.tar.bz2;;
Linux* | *)
EXE_SUFFIX=
if [[ "$(uname -m)" == "arm64" ]] || [[ "$(uname -m)" == "aarch64" ]]; then
HOST_TRIPLE=aarch64-unknown-linux-gnu
ARTIFACT=platform-tools-linux-aarch64.tar.bz2
else
HOST_TRIPLE=x86_64-unknown-linux-gnu
ARTIFACT=platform-tools-linux-x86_64.tar.bz2
fi
esac
cd "$(dirname "$0")"
OUT_DIR="$(realpath ./)/${1:-out}"
rm -rf "${OUT_DIR}"
mkdir -p "${OUT_DIR}"
pushd "${OUT_DIR}"
git clone --single-branch --branch solana-tools-v1.43 --recurse-submodules --shallow-submodules https://github.com/anza-xyz/rust.git
echo "$( cd rust && git rev-parse HEAD ) https://github.com/anza-xyz/rust.git" >> version.md
git clone --single-branch --branch solana-tools-v1.43 https://github.com/anza-xyz/cargo.git
echo "$( cd cargo && git rev-parse HEAD ) https://github.com/anza-xyz/cargo.git" >> version.md
pushd rust
if [[ "${HOST_TRIPLE}" == "x86_64-pc-windows-msvc" ]] ; then
# Do not build lldb on Windows
sed -i -e 's#enable-projects = \"clang;lld;lldb\"#enable-projects = \"clang;lld\"#g' config.toml
fi
./build.sh
popd
pushd cargo
if [[ "${HOST_TRIPLE}" == "x86_64-unknown-linux-gnu" ]] ; then
OPENSSL_STATIC=1 OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu OPENSSL_INCLUDE_DIR=/usr/include/openssl cargo build --release
else
OPENSSL_STATIC=1 cargo build --release
fi
popd
if [[ "${HOST_TRIPLE}" != "x86_64-pc-windows-msvc" ]] ; then
git clone --single-branch --branch solana-tools-v1.43 https://github.com/anza-xyz/newlib.git
echo "$( cd newlib && git rev-parse HEAD ) https://github.com/anza-xyz/newlib.git" >> version.md
mkdir -p newlib_build
mkdir -p newlib_install
pushd newlib_build
CC="${OUT_DIR}/rust/build/${HOST_TRIPLE}/llvm/bin/clang" \
AR="${OUT_DIR}/rust/build/${HOST_TRIPLE}/llvm/bin/llvm-ar" \
RANLIB="${OUT_DIR}/rust/build/${HOST_TRIPLE}/llvm/bin/llvm-ranlib" \
../newlib/newlib/configure --target=sbf-solana-solana --host=sbf-solana --build="${HOST_TRIPLE}" --prefix="${OUT_DIR}/newlib_install"
make install
popd
fi
# Copy rust build products
mkdir -p deploy/rust
cp version.md deploy/
cp -R "rust/build/${HOST_TRIPLE}/stage1/bin" deploy/rust/
cp -R "cargo/target/release/cargo${EXE_SUFFIX}" deploy/rust/bin/
mkdir -p deploy/rust/lib/rustlib/
cp -R "rust/build/${HOST_TRIPLE}/stage1/lib/rustlib/${HOST_TRIPLE}" deploy/rust/lib/rustlib/
cp -R "rust/build/${HOST_TRIPLE}/stage1/lib/rustlib/sbf-solana-solana" deploy/rust/lib/rustlib/
find . -maxdepth 6 -type f -path "./rust/build/${HOST_TRIPLE}/stage1/lib/*" -exec cp {} deploy/rust/lib \;
mkdir -p deploy/rust/lib/rustlib/src/rust
cp "rust/build/${HOST_TRIPLE}/stage1/lib/rustlib/src/rust/Cargo.lock" deploy/rust/lib/rustlib/src/rust
cp -R "rust/build/${HOST_TRIPLE}/stage1/lib/rustlib/src/rust/library" deploy/rust/lib/rustlib/src/rust
# Copy llvm build products
mkdir -p deploy/llvm/{bin,lib}
while IFS= read -r f
do
bin_file="rust/build/${HOST_TRIPLE}/llvm/build/bin/${f}${EXE_SUFFIX}"
if [[ -f "$bin_file" ]] ; then
cp -R "$bin_file" deploy/llvm/bin/
fi
done < <(cat <<EOF
clang
clang++
clang-cl
clang-cpp
clang-18
ld.lld
ld64.lld
llc
lld
lld-link
lldb
lldb-vscode
llvm-ar
llvm-objcopy
llvm-objdump
llvm-readelf
llvm-readobj
EOF
)
cp -R "rust/build/${HOST_TRIPLE}/llvm/build/lib/clang" deploy/llvm/lib/
if [[ "${HOST_TRIPLE}" != "x86_64-pc-windows-msvc" ]] ; then
cp -R newlib_install/sbf-solana/lib/lib{c,m}.a deploy/llvm/lib/
cp -R newlib_install/sbf-solana/include deploy/llvm/
cp -R rust/src/llvm-project/lldb/scripts/solana/* deploy/llvm/bin/
cp -R rust/build/${HOST_TRIPLE}/llvm/lib/liblldb.* deploy/llvm/lib/
if [[ "${HOST_TRIPLE}" == "x86_64-unknown-linux-gnu" || "${HOST_TRIPLE}" == "aarch64-unknown-linux-gnu" ]]; then
cp -r rust/build/${HOST_TRIPLE}/llvm/local/lib/python* deploy/llvm/lib
else
cp -R rust/build/${HOST_TRIPLE}/llvm/lib/python* deploy/llvm/lib/
fi
fi
# Check the Rust binaries
while IFS= read -r f
do
"./deploy/rust/bin/${f}${EXE_SUFFIX}" --version
done < <(cat <<EOF
cargo
rustc
rustdoc
EOF
)
# Check the LLVM binaries
while IFS= read -r f
do
if [[ -f "./deploy/llvm/bin/${f}${EXE_SUFFIX}" ]] ; then
"./deploy/llvm/bin/${f}${EXE_SUFFIX}" --version
fi
done < <(cat <<EOF
clang
clang++
clang-cl
clang-cpp
ld.lld
llc
lld-link
llvm-ar
llvm-objcopy
llvm-objdump
llvm-readelf
llvm-readobj
solana-lldb
EOF
)
tar -C deploy -jcf ${ARTIFACT} .
rm -rf deploy
# Package LLVM binaries for Move project
MOVE_DEV_TAR=${ARTIFACT/platform-tools/move-dev}
mkdir move-dev
if [[ "${HOST_TRIPLE}" == "x86_64-pc-windows-msvc" ]] ; then
rm -f rust/build/${HOST_TRIPLE}/llvm/bin/{llvm-ranlib.exe,llvm-lib.exe,llvm-dlltool.exe}
fi
mv "rust/build/${HOST_TRIPLE}/llvm/"{bin,include,lib} move-dev/
tar -jcf "${MOVE_DEV_TAR}" move-dev
popd
mv "${OUT_DIR}/${ARTIFACT}" .
mv "${OUT_DIR}/${MOVE_DEV_TAR}" .
# Build linux binaries on macOS in docker
if [[ "$(uname)" == "Darwin" ]] && [[ $# == 1 ]] && [[ "$1" == "--docker" ]] ; then
docker system prune -a -f
docker build -t solanalabs/platform-tools .
id=$(docker create solanalabs/platform-tools /build.sh "${OUT_DIR}")
docker cp build.sh "${id}:/"
docker start -a "${id}"
docker cp "${id}:${OUT_DIR}/solana-sbf-tools-linux-x86_64.tar.bz2" "${OUT_DIR}"
fi