forked from 0x676e67/ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·149 lines (130 loc) · 4.22 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
#!/bin/bash
set -e
root=$(pwd)
: ${tag=latest}
: ${rmi=false}
: ${os=linux}
[ ! -d uploads ] && mkdir uploads
# Separate arrays for target architectures and Docker images
target_architectures=(
"x86_64-unknown-linux-musl"
"aarch64-unknown-linux-musl"
"armv7-unknown-linux-musleabi"
"armv7-unknown-linux-musleabihf"
"arm-unknown-linux-musleabi"
"arm-unknown-linux-musleabihf"
"armv5te-unknown-linux-musleabi"
"i686-unknown-linux-gnu"
"i586-unknown-linux-gnu"
"x86_64-pc-windows-msvc"
)
pull_docker_image() {
image="ghcr.io/rust-cross/rust-musl-cross:$1"
echo "Pulling $image"
docker pull $image
}
rmi_docker_image() {
image="ghcr.io/rust-cross/rust-musl-cross:$1"
echo "Removing $image docker image"
if [ "$rmi" = "true" ]; then
docker rmi $image
fi
}
build_macos_target() {
echo "Building $1"
cargo build --release --target $1 --features mimalloc
sudo chmod -R 777 target
cd target/$1/release
tar czvf ninja-$tag-$1.tar.gz ninja
shasum -a 256 ninja-$tag-$1.tar.gz >ninja-$tag-$1.tar.gz.sha256
mv ninja-$tag-$1.tar.gz $root/uploads/
mv ninja-$tag-$1.tar.gz.sha256 $root/uploads/
cd -
}
build_linux_target() {
docker_image="ghcr.io/rust-cross/rust-musl-cross:$1"
features=""
if [ "$1" = "armv5te-unknown-linux-musleabi" ] || [ "$1" = "arm-unknown-linux-musleabi" ] || [ "$1" = "arm-unknown-linux-musleabihf" ]; then
features="--features rpmalloc"
else
if [ "$1" = "i686-unknown-linux-gnu" ] || [ "$1" = "i586-unknown-linux-gnu" ]; then
features=""
else
features="--features mimalloc"
fi
fi
echo "Building $1"
docker run --rm -t --user=$UID:$(id -g $USER) \
-v $(pwd):/home/rust/src \
-v $HOME/.cargo/registry:/root/.cargo/registry \
-v $HOME/.cargo/git:/root/.cargo/git \
-e "FEATURES=$features" \
-e "TARGET=$1" \
$docker_image /bin/bash -c "sudo apt-get update && sudo apt-get install -y libc6-dev && cargo build --release --target \$TARGET \$FEATURES"
sudo chmod -R 777 target
if [ "$1" != "i686-unknown-linux-gnu" ] && [ "$1" != "i586-unknown-linux-gnu" ]; then
upx --best --lzma target/$1/release/ninja
fi
cd target/$1/release
tar czvf ninja-$tag-$1.tar.gz ninja
shasum -a 256 ninja-$tag-$1.tar.gz >ninja-$tag-$1.tar.gz.sha256
mv ninja-$tag-$1.tar.gz $root/uploads/
mv ninja-$tag-$1.tar.gz.sha256 $root/uploads/
cd -
}
build_windows_target() {
docker_image="ghcr.io/rust-cross/rust-musl-cross:$1"
echo "Building $1"
docker run --rm -t \
-v $(pwd):/home/rust/src \
-v $HOME/.cargo/registry:/usr/local/cargo/registry \
-v $HOME/.cargo/git:/usr/local/cargo/git \
$docker_image cargo xwin build --release --target $1
sudo chmod -R 777 target
upx --best --lzma target/$1/release/ninja.exe
cd target/$1/release
tar czvf ninja-$tag-$1.tar.gz ninja.exe
shasum -a 256 ninja-$tag-$1.tar.gz >ninja-$tag-$1.tar.gz.sha256
mv ninja-$tag-$1.tar.gz $root/uploads/
mv ninja-$tag-$1.tar.gz.sha256 $root/uploads/
cd -
}
if [ "$os" = "windows" ]; then
target="x86_64-pc-windows-msvc"
pull_docker_image "$target"
build_windows_target "$target"
rmi_docker_image "$target"
fi
if [ "$os" = "linux" ]; then
target_list=(
"x86_64-unknown-linux-musl"
"aarch64-unknown-linux-musl"
"armv7-unknown-linux-musleabi"
"armv7-unknown-linux-musleabihf"
"armv5te-unknown-linux-musleabi"
"arm-unknown-linux-musleabi"
"arm-unknown-linux-musleabihf"
"i686-unknown-linux-gnu"
"i586-unknown-linux-gnu"
)
for target in "${target_list[@]}"; do
pull_docker_image "$target"
build_linux_target "$target"
rmi_docker_image "$target"
done
fi
if [ "$os" = "macos" ]; then
target_list=(
"x86_64-apple-darwin"
"aarch64-apple-darwin"
)
for target in "${target_list[@]}"; do
echo "Adding $target to the build queue"
rustup target add "$target"
build_macos_target "$target"
done
fi
generate_directory_tree() {
find "$1" -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
generate_directory_tree "uploads"