forked from libapps/libapps-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·167 lines (147 loc) · 3.5 KB
/
build.sh
File metadata and controls
executable file
·167 lines (147 loc) · 3.5 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
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
#!/bin/bash
# Copyright 2012 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -xe
# Default version must come first.
SSH_VERSIONS=( 9.9 8.6 )
ncpus=$(getconf _NPROCESSORS_ONLN || echo 2)
DEBUG=0
OFFICIAL_RELEASE=0
for i in $@; do
case $i in
"--debug")
DEBUG=1
;;
"--official-release")
OFFICIAL_RELEASE=1
;;
*)
echo "usage: $0 [--debug]"
exit 1
;;
esac
done
cd "$(dirname "$0")"
mkdir -p output
# Build the toolchain packages.
tc_pkgs=(
# Build tools.
gnuconfig
mandoc
protobuf
# WASM toolchain.
binaryen
wabt
wasi-sdk
)
for tc_pkg in "${tc_pkgs[@]}"; do
./third_party/${tc_pkg}/build --toolchain build
done
# The plugin packages.
pkgs=(
zlib
openssl
ldns
$(printf 'openssh-%s ' "${SSH_VERSIONS[@]}")
)
./wassh-libc-sup/build --toolchain wasip1
for pkg in "${pkgs[@]}"; do
./third_party/${pkg}/build --toolchain wasip1
done
# Packages for mosh.
mosh_pkgs=(
zlib
openssl
ncurses
protobuf
mosh
)
./wassh-libc-sup/build --toolchain wasip1-threads
for pkg in "${mosh_pkgs[@]}"; do
./third_party/${pkg}/build --toolchain wasip1-threads
done
# Install the WASM programs.
#
# We use -O2 as that seems to provide good enough shrinkage. -O3/-O4 take
# much longer but don't produce singificnatly larger/smaller files. -Os/-Oz
# also aren't that much smaller than -O2. So use this pending more testing.
WASM_OPTS=()
if [[ ${DEBUG} == 1 ]]; then
WASM_OPTS+=( -O0 )
else
WASM_OPTS+=( -O2 )
fi
pushd output >/dev/null
cat <<EOF >Makefile.wasm-opt
# Only use single core because versions <102 are known to segfault, and upstream
# doesn't seem to have any idea if they actually fixed it, or if it just happens
# to mostly work now.
# https://github.com/WebAssembly/binaryen/issues/2273
#
# Also force single core because it significantly outperforms multicore runs due
# to some extreme internal threading overhead.
# https://github.com/WebAssembly/binaryen/issues/2740
export BINARYEN_CORES = 1
# Disable implicit rules we don't need.
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
WASM_OPTS = ${WASM_OPTS[*]}
WASM_OPT = ${PWD}/bin/wasm-opt
all:
EOF
emit_wasm_opt_rule() {
local src="$1"
local dst="$2"
(
echo "all: ${dst}"
echo "${dst}: ${src}"
printf '\t$(WASM_OPT) ${WASM_OPTS} $< -o $@\n'
) >>Makefile.wasm-opt
}
first="true"
for version in "${SSH_VERSIONS[@]}"; do
if [[ "${first}" == "true" ]]; then
first=
dir="plugin/wasm"
else
dir+="-openssh-${version}"
fi
mkdir -p "${dir}"
for prog in scp sftp ssh ssh-keygen; do
emit_wasm_opt_rule \
build/wasm32-wasip1/openssh-${version}*/work/openssh-*/${prog} \
"${dir}/${prog}.wasm"
done
done
emit_wasm_opt_rule \
build/wasm32-wasip1-threads/mosh-*/work/mosh-*/src/frontend/mosh-client \
plugin/wasm/mosh-client.wasm
make -f Makefile.wasm-opt -j${ncpus} -O
popd >/dev/null
# Generate the final artifacts.
if [[ $DEBUG == 1 ]]; then
tarname="debug.tar"
else
tarname="release.tar"
fi
cd output
# Only spend extra time on this on official release builders. All other modes
# can get by with slightly larger file.
if [[ "${OFFICIAL_RELEASE}" == 1 ]]; then
comp_level="-9"
else
comp_level="-0"
fi
# Use reproducible options since the inputs should be reproducible too.
(
find plugin/ -type f -print0
) | \
LC_ALL=C tar \
--numeric-owner \
--owner=0 --group=0 \
--mtime="1970-01-01" \
--sort=name \
--null --files-from - \
-cf - \
| xz -T0 ${comp_level} >"${tarname}.xz"