-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplatform_packages.sh
More file actions
executable file
·300 lines (262 loc) · 7.86 KB
/
platform_packages.sh
File metadata and controls
executable file
·300 lines (262 loc) · 7.86 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env bash
#
# build platform-specific packages
set -e
PLATFORM_DIR="platforms"
TEMPLATE_DIR="template"
CROSS_COMMIT="43a1220"
CROSS_TOOLCHAIN_COMMIT="d139724"
OSX_VERSION="12.3"
declare -A TARGETS
TARGETS["linux-x64"]="x86_64-unknown-linux-gnu"
TARGETS["linux-arm64"]="aarch64-unknown-linux-gnu"
TARGETS["darwin-x64"]="x86_64-apple-darwin"
TARGETS["darwin-arm64"]="aarch64-apple-darwin"
TARGETS["win32-x64"]="x86_64-pc-windows-gnu"
_die() {
echo "ERR: $*"
exit 1
}
_detect_platform() {
echo "detecting current host platform"
OS=$(node -e 'const os = require("os"); console.log(os.platform());')
CPU=$(node -e 'const os = require("os"); console.log(os.arch());')
}
_detect_version() {
echo "detecting package version"
VERSION="$(jq -r '.version' package.json)"
}
_reset_cross() {
local clean="$1"
git reset --hard $CROSS_COMMIT
pushd docker/cross-toolchains
git reset --hard $CROSS_TOOLCHAIN_COMMIT
popd
if [ -n "$clean" ]; then
(git submodule update)
fi
}
_patch_base_image_version() {
# patch base ubuntu image version
for f in docker/Dockerfile* docker/cross-toolchains/docker/Dockerfile.* src/docker/shared.rs; do
sed -i \
-e 's/ubuntu:20/ubuntu:22/' \
"$f"
done
# patch linux-image.sh for updated ubuntu
sed -i \
-e 's/kversion=5.10.0-26/kversion=6.1.0-39/' \
-e 's/bullseye/bookworm/' \
-e 's/archive-key-{7.0,8,9,10,11}/archive-key-12/' \
-e 's/release-{7,8,9,10,11}/release-12/' \
-e 's/archive_{2020,2021,2022,2023,2024}/archive_2025/' \
docker/linux-image.sh
# patch wine version for updated ubuntu
sed -i \
-e 's/version="9.0.0.0~focal-1"/version="10.0.0.0~jammy-1"/' \
-e 's/focal/jammy/g' \
docker/wine.sh
}
_build_cross_image() {
local target="$1"
pushd cross
_reset_cross
_patch_base_image_version
cargo build-docker-image "$target" --tag local
if [ -z "$KEEP" ]; then
_reset_cross 1
fi
popd
}
_build_cross_image_darwin() {
local target="$1"
pushd cross
_reset_cross
_patch_base_image_version
# patch darwin scripts
sed -i \
-e "s/OSX_VERSION_MIN=10.7/OSX_VERSION_MIN=$OSX_VERSION/" \
docker/cross-toolchains/docker/darwin.sh
sed -i \
-e 's#-fuse-ld=#-fuse-ld=/opt/osxcross/bin/#' \
docker/cross-toolchains/docker/darwin-entry.sh
MACOS_SDK_URL="https://github.com/joseluisq/macosx-sdks/releases/download/$OSX_VERSION/MacOSX$OSX_VERSION.sdk.tar.xz"
cargo build-docker-image "$target-cross" --tag local --build-arg "MACOS_SDK_URL=$MACOS_SDK_URL"
if [ -z "$KEEP" ]; then
_reset_cross 1
fi
popd
}
_build_package() {
local os="$1"
local cpu="$2"
local filename ext platform platform_dir target
filename="librgblibcffi"
platform="$os-$cpu"
platform_dir="$PLATFORM_DIR/$platform"
target=${TARGETS[$platform]}
[ -z "$target" ] && _die "unsupported platform \"$os-$cpu\""
echo
echo
echo "================================================"
echo "building for $platform ($target)"
echo "================================================"
echo
case $os in
linux)
ext="so"
_build_cross_image "$target"
;;
darwin)
ext="dylib"
_build_cross_image_darwin "$target"
;;
win32)
filename="rgblibcffi"
ext="dll"
_build_cross_image "$target"
;;
*)
_die "unsupprted OS: $os"
;;
esac
# platform files initial setup
if [ -z "$KEEP" ]; then
# clear platform data then setup template files and rgb-lib submodule
rm -rf "$platform_dir"
mkdir -p "$PLATFORM_DIR"
cp -a $TEMPLATE_DIR "$platform_dir"
cp -a rgb-lib "$platform_dir/"
else
# only sync template files, keeping everything else as it is
[ -d "$platform_dir" ] || _die "missing template dir, cannot sync"
rsync -av $TEMPLATE_DIR/ "$platform_dir/"
fi
# configure cross
cp Cross.toml "$platform_dir/rgb-lib/bindings/c-ffi/"
# set platform-specific bits in binding.gyp
sed -i \
-e "s/%TARGET%/$target/" \
"$platform_dir/binding.gyp"
# set platform-specific bits and version in package.json
_detect_version
sed -i \
-e "s/%PLATFORM%/$platform/" \
-e "s/%OS%/$os/" \
-e "s/%CPU%/$cpu/" \
-e "s/%FILENAME%/$filename/" \
-e "s/%EXTENSION%/$ext/" \
-e "s/%TARGET%/$target/" \
-e "s/%VERSION%/$VERSION/" \
"$platform_dir/package.json"
# set platform-specific bits in README.md
sed -i \
-e "s/%OS%/$os/" \
-e "s/%CPU%/$cpu/" \
"$platform_dir/README.md"
# build
pushd "$platform_dir"
npm run build
case $os in
win32)
pushd "rgb-lib/bindings/c-ffi/target/$target/release"
gendef rgblibcffi.dll
/usr/x86_64-w64-mingw32/bin/dlltool -d rgblibcffi.def -l rgblibcffi.lib
popd
;;
esac
popd
}
_publish_package() {
local os="$1"
local cpu="$2"
local platform platform_dir target
platform="$os-$cpu"
platform_dir="$PLATFORM_DIR/$platform"
target=${TARGETS[$platform]}
[ -z "$target" ] && _die "unsupported platform \"$os-$cpu\""
echo "publishing package for $platform ($target)"
pushd "$platform_dir"
npm publish --access public
popd
}
# package builds
_build() {
case "$1" in
"")
_detect_platform
_build_package "$OS" "$CPU"
;;
all)
echo "building for all platforms"
_build_package "linux" "x64"
_build_package "linux" "arm64"
_build_package "darwin" "x64"
_build_package "darwin" "arm64"
_build_package "win32" "x64"
;;
*)
echo "building for the specified platform"
_build_package "$1" "$2"
;;
esac
}
# local platform package installation
_install() {
local platform_dir
_detect_platform
echo "installing package for $OS-$CPU"
platform_dir="$PLATFORM_DIR/$OS-$CPU"
_detect_version
pushd "$platform_dir"
npm pack
popd
npm install --no-save "$platform_dir/rgb-tools-rgb-lib-$OS-$CPU-$VERSION.tgz"
}
# package publishing
_publish() {
case "$1" in
all)
echo "publishing packages for all platforms"
_publish_package "linux" "x64"
_publish_package "linux" "arm64"
_publish_package "darwin" "x64"
_publish_package "darwin" "arm64"
_publish_package "win32" "x64"
;;
*)
echo "publishing the package for the specified platform"
_publish_package "$1" "$2"
;;
esac
}
_help() {
echo "$(basename "$0") [build|install|publish] [<OS> <CPU>|all|]"
echo ""
echo "commands:"
echo " build build the native library for the specifed platform(s)"
echo " install installs the package for the current host platform"
echo " publish publish the package for the specified platform(s)"
echo ""
echo "arguments:"
echo " build none: build for the current host platform"
echo " <OS> and <CPU>: build for the specifed platform"
echo " \"all\": build for all supported platforms"
echo " install takes no arguments"
echo " publish <OS> and <CPU>: publish the package for the specifed platform"
echo " \"all\": publish the packages for all supported platforms"
}
case $1 in
build)
_build "$2" "$3"
;;
install)
_install
;;
publish)
_publish "$2" "$3"
;;
*)
_help
;;
esac