-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-mac.sh
executable file
·115 lines (93 loc) · 3.71 KB
/
build-mac.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
#!/usr/bin/env bash
# exit when any command fails
set -e
# Load in some secrets
if test -f .env; then
source .env
fi
target_dir='target/universal-apple-darwin/release'
build_binary() {
# Set minimum macOS version to support older OS versions
export MACOSX_DEPLOYMENT_TARGET=10.7
# Build x86_64 binary (also re-creates target/universal-apple-darwin/meta/Info.plist)
cargo build --target x86_64-apple-darwin --release
# Build ARM64 binary (also re-creates target/universal-apple-darwin/meta/Info.plist)
cargo build --target aarch64-apple-darwin --release
# Clean universal binary and app bundle
rm -rf "${target_dir:?}/"
# Build universal binary
mkdir -p "$target_dir/"
lipo -create -output "$target_dir/Browsers" target/x86_64-apple-darwin/release/browsers target/aarch64-apple-darwin/release/browsers
}
build_app_bundle() {
# Build .app bundle
mkdir -p "$target_dir/Browsers.app/Contents"
mkdir -p "$target_dir/Browsers.app/Contents/MacOS"
mkdir -p "$target_dir/Browsers.app/Contents/Resources"
mkdir -p "$target_dir/Browsers.app/Contents/Resources/i18n/en-US"
mkdir -p "$target_dir/Browsers.app/Contents/Resources/icons"
mkdir -p "$target_dir/Browsers.app/Contents/Resources/icons/512x512"
mkdir -p "$target_dir/Browsers.app/Contents/Resources/repository"
# FYI: extra/macos/Info.plist is copied
# to target/universal-apple-darwin/meta/Info.plist
# by build.rs (because it also sets version from Cargo.toml)
cp target/universal-apple-darwin/meta/Info.plist target/universal-apple-darwin/release/Browsers.app/Contents/Info.plist
cp extra/macos/icons/Browsers.icns "$target_dir/Browsers.app/Contents/Resources/Browsers.icns"
cp resources/icons/512x512/software.Browsers.png "$target_dir/Browsers.app/Contents/Resources/icons/512x512/software.Browsers.png"
cp resources/i18n/en-US/builtin.ftl "$target_dir/Browsers.app/Contents/Resources/i18n/en-US/builtin.ftl"
cp resources/repository/application-repository.toml "$target_dir/Browsers.app/Contents/Resources/repository/application-repository.toml"
cp target/universal-apple-darwin/release/Browsers "$target_dir/Browsers.app/Contents/MacOS/Browsers"
}
sign_app_bundle() {
# Sign with hardened runtime (hardened runtime is required for notarization)
rcodesign sign \
--p12-file "$P12_FILE" \
--p12-password "$P12_PASSWORD" \
--code-signature-flags runtime \
"./$target_dir/Browsers.app"
}
notarize_app_bundle() {
rcodesign notary-submit \
--api-key-path "$NOTARY_API_KEY_JSON_FILE" \
--staple \
"./$target_dir/Browsers.app"
}
build_dmg() {
# Build .dmg disk image installer
cd extra/macos/dmg || exit
./mac-dmg-build.sh
cd ../../../
}
# This is a good format for auto-updating
make_archives() {
rm -f "./${target_dir:?}/browsers_mac.tar.gz"
rm -f "./${target_dir:?}/browsers_mac.tar.gz.sha256"
rm -f "./${target_dir:?}/browsers_mac.tar.gz.sig"
rm -f "./${target_dir:?}/browsers_mac.tar.xz"
rm -f "./${target_dir:?}/browsers_mac.tar.xz.sha256"
rm -f "./${target_dir:?}/browsers_mac.tar.xz.sig"
# .tar.gz
tar -zcf "./$target_dir/browsers_mac.tar.gz" \
-C "./$target_dir" \
./Browsers.app
create_signatures "$target_dir" "browsers_mac.tar.gz"
# .tar.xz
tar -Jcf "./$target_dir/browsers_mac.tar.xz" \
-C "./$target_dir" \
./Browsers.app
create_signatures "$target_dir" "browsers_mac.tar.xz"
}
create_signatures() {
local target_dir="$1"
local file_name="$2"
# creates $filename.sha256
shasum --algorithm 256 "./$target_dir/$file_name" | cut -f1 -d' ' > "./$target_dir/$file_name.sha256"
# creates $filename.sig
signify -S -s "$APPCAST_SECRET_KEY_FILE" -m "./$target_dir/$file_name"
}
build_binary
build_app_bundle
sign_app_bundle
notarize_app_bundle
build_dmg
make_archives