-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathbuild_all.sh
More file actions
executable file
·134 lines (112 loc) · 4.09 KB
/
Copy pathbuild_all.sh
File metadata and controls
executable file
·134 lines (112 loc) · 4.09 KB
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
#! /bin/bash
set -euo pipefail
IMAGE_NAME="xelis-cargo-xwin"
# support: ARM64, ARMv7, x86_64 linux, Windows x86_64 (MSVC)
targets=("aarch64-unknown-linux-gnu" "armv7-unknown-linux-gnueabihf" "x86_64-unknown-linux-musl" "x86_64-unknown-linux-gnu" "x86_64-pc-windows-msvc")
binaries=("xelis_daemon" "xelis_miner" "xelis_wallet")
extra_files=("README.md" "API.md" "CHANGELOG.md" "LICENSE")
# verify that we have cross installed
if ! command -v cross &> /dev/null; then
echo "cross could not be found, please install it for cross compilation"
exit 1
fi
# Cross (and our Windows build) need docker to be running
echo "Starting docker daemon"
if ! sudo systemctl start docker 2>/dev/null; then
echo "Warning: could not start docker via systemd; make sure Docker is running if needed."
fi
echo "Updating using rustup"
rustup update stable
echo "Only build in stable"
rustup default stable
echo "Deleting build folder"
rm -rf build
# store the commit hash used for this build
commit_hash=$(git rev-parse HEAD)
echo "Using commit hash: $commit_hash"
export XELIS_COMMIT_HASH="$commit_hash"
# compile all binaries for all targets
echo "Compiling binaries for all targets"
for target in "${targets[@]}"; do
echo "Clean build cache for $target"
cross clean
# support the target (for tooling, even if Windows build happens in Docker)
rustup target add "$target"
if [[ "$target" == *"windows"* ]]; then
# ---- Windows (MSVC) build via cargo-xwin in Docker ----
# Ensure docker CLI is available
if ! command -v docker &> /dev/null; then
echo "docker could not be found, required for Windows build"
exit 1
fi
# Build the local image (based on messense/cargo-xwin + latest stable Rust)
echo "Building local Docker image $IMAGE_NAME..."
docker build -t "$IMAGE_NAME" -f Dockerfile.xwin .
docker run --rm -e XELIS_COMMIT_HASH="$commit_hash" -v "$PWD:/work" -w /work "$IMAGE_NAME" cargo xwin build --target "$target" --profile release-with-lto
else
# ---- Non-Windows builds via cross ----
XELIS_COMMIT_HASH="$commit_hash" cross build --target "$target" --profile release-with-lto
fi
mkdir -p "build/$target"
# copy generated binaries to build directory
for binary in "${binaries[@]}"; do
out_bin="$binary"
# add .exe extension to windows binaries
if [[ "$target" == *"windows"* ]]; then
out_bin="$binary.exe"
fi
cp "target/$target/release-with-lto/$out_bin" "build/$target/$out_bin"
done
# copy extra files
for file in "${extra_files[@]}"; do
cp "$file" "build/$target/$file"
done
done
echo "Creating archives for all targets"
for target in "${targets[@]}"; do
# generate checksums
echo "Generating checksums for $target"
cd "build/$target"
> checksums.txt
for binary in "${binaries[@]}"; do
out_bin="$binary"
# add .exe extension to windows binaries
if [[ "$target" == *"windows"* ]]; then
out_bin="$binary.exe"
fi
sha256sum "$out_bin" >> checksums.txt
done
cd ../..
# create archive
cd build/
if [[ "$target" == *"windows"* ]]; then
zip -r "$target.zip" "$target"
else
tar -czf "$target.tar.gz" "$target"
fi
cd ..
done
# Generate final checksums.txt in build/
echo "Generating final checksums.txt in build/"
cd build/
> checksums.txt
for target in "${targets[@]}"; do
if [[ "$target" == *"windows"* ]]; then
sha256sum "$target.zip" >> checksums.txt
else
sha256sum "$target.tar.gz" >> checksums.txt
fi
done
cd ..
read -r -p "Sign the checksums file with GPG? [y/N] " sign_checksums
if [[ "$sign_checksums" =~ ^([yY][eE][sS]|[yY]) ]]; then
if ! command -v gpg &> /dev/null; then
echo "gpg could not be found, please install it to sign the checksums file"
exit 1
fi
gpg --armor --detach-sign --output "build/checksums.txt.asc" "build/checksums.txt"
echo "Signed checksums file: build/checksums.txt.asc"
else
echo "Skipping GPG signing of checksums file"
fi
echo "Done"