-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbuild_macos.sh
More file actions
executable file
·176 lines (139 loc) · 5.74 KB
/
build_macos.sh
File metadata and controls
executable file
·176 lines (139 loc) · 5.74 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
#!/bin/bash
#shellcheck source=/dev/null
source ./env.sh
WINDSEND_RUST_SERVER_BIN_NAME="WindSend-S-Rust"
mkdir -p ./bin
chmod +x ./*.sh
# 检查环境变量是否已经设置
if [ -z "$WINDSEND_PROJECT_VERSION" ]; then
read -rp "WINDSEND_PROJECT_VERSION:v" WINDSEND_PROJECT_VERSION
fi
# 若指定了版本号,则修改项目中的版本号
if [ -n "$WINDSEND_PROJECT_VERSION" ]; then
echo "WINDSEND_PROJECT_VERSION: $WINDSEND_PROJECT_VERSION"
export WINDSEND_PROJECT_VERSION
./version.sh
fi
######################################################################################
# Build WindSend Rust for x86_64
WindSendRustBin_X86_64DirName="WindSend-macos-x64-S-Rust-$BUILD_TAG"
rustBinName="wind_send"
rustTarget="x86_64-apple-darwin"
cd "$WINDSEND_PROJECT_PATH" || exit
cd "$WINDSEND_RUST_PROJECT_PATH" || exit
if ! cargo build --target $rustTarget --verbose --release; then
echo "Build x86_64 Failed!"
exit 1
fi
mkdir -p ../bin/"$WindSendRustBin_X86_64DirName"
cp -r target/$rustTarget/release/$rustBinName ../bin/"$WindSendRustBin_X86_64DirName"
mv ../bin/"$WindSendRustBin_X86_64DirName"/$rustBinName ../bin/"$WindSendRustBin_X86_64DirName"/$WINDSEND_RUST_SERVER_BIN_NAME
cd "$WINDSEND_PROJECT_PATH" || exit
cp README.md ./bin/"$WindSendRustBin_X86_64DirName"
cp README-EN.md ./bin/"$WindSendRustBin_X86_64DirName"
cp "$WINDSEND_RUST_PROJECT_PATH/$SERVER_PROGRAM_ICON_NAME" ./bin/"$WindSendRustBin_X86_64DirName"
cd ./bin || exit
zip -r "$WindSendRustBin_X86_64DirName".zip.temp "$WindSendRustBin_X86_64DirName"
######################################################################################
# Build WindSend for aarch64
WindSendRustBin_DirName="WindSend-macos-arm64-S-Rust-$BUILD_TAG"
rustBinName="wind_send"
rustTarget="aarch64-apple-darwin"
cd "$WINDSEND_PROJECT_PATH" || exit
cd "$WINDSEND_RUST_PROJECT_PATH" || exit
if ! cargo build --target $rustTarget --verbose --release; then
echo "Build aarch64 Failed!"
exit 1
fi
mkdir -p ../bin/"$WindSendRustBin_DirName"
cp -r target/$rustTarget/release/$rustBinName ../bin/"$WindSendRustBin_DirName"
mv ../bin/"$WindSendRustBin_DirName"/$rustBinName ../bin/"$WindSendRustBin_DirName"/$WINDSEND_RUST_SERVER_BIN_NAME
cd "$WINDSEND_PROJECT_PATH" || exit
cp README.md ./bin/"$WindSendRustBin_DirName"
cp README-EN.md ./bin/"$WindSendRustBin_DirName"
cp "$WINDSEND_RUST_PROJECT_PATH/$SERVER_PROGRAM_ICON_NAME" ./bin/"$WindSendRustBin_DirName"
cd ./bin || exit
zip -r "$WindSendRustBin_DirName".zip.temp "$WindSendRustBin_DirName"
######################################################################################
# .dmg 打包逻辑
package_dmg() {
# Enter the bin directory
cd "$WINDSEND_PROJECT_PATH" || exit
cd "./bin" || exit
ICONS_PATH="${WINDSEND_PROJECT_PATH}/app_icon/macos/AppIcon.icns"
APP_NAME="WindSend"
APP_BUNDLE="${APP_NAME}.app"
rust_project_path="${WINDSEND_RUST_PROJECT_PATH#/./}"
rust_bin_dir="$1"
# for executable files
mkdir -p "${APP_BUNDLE}/Contents/MacOS"
# for resources like icons
mkdir -p "${APP_BUNDLE}/Contents/Resources"
cp "${rust_bin_dir}/${WINDSEND_RUST_SERVER_BIN_NAME}" "${APP_BUNDLE}/Contents/MacOS/"
cp "$ICONS_PATH" "${APP_BUNDLE}/Contents/Resources/AppIcon.icns"
cp "../$rust_project_path/$SERVER_PROGRAM_ICON_NAME" "${APP_BUNDLE}/Contents/Resources/icon-192.png"
chmod +x "${APP_BUNDLE}/Contents/MacOS/${WINDSEND_RUST_SERVER_BIN_NAME}"
cat <<EOF >"${APP_BUNDLE}/Contents/Info.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>${WINDSEND_RUST_SERVER_BIN_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.doraemon.windsend.rs</string>
<key>CFBundleName</key>
<string>${APP_NAME}</string>
<key>CFBundleVersion</key>
<string>${WINDSEND_PROJECT_VERSION}</string>
<key>CFBundleShortVersionString</key>
<string>${WINDSEND_PROJECT_VERSION}</string>
<key>CFBundleIconFile</key>
<string>AppIcon.icns</string>
<key>LSUIElement</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
</plist>
EOF
RW_DMG="${APP_NAME}_temp.dmg"
hdiutil create -volname "${APP_NAME}" \
-srcfolder "${APP_BUNDLE}" \
-ov \
-format UDRW \
"${RW_DMG}" || exit 1
MOUNT_POINT="/Volumes/${APP_NAME}"
hdiutil attach "${RW_DMG}" -mountpoint "${MOUNT_POINT}"
ln -s /Applications "${MOUNT_POINT}/Applications"
hdiutil detach "${MOUNT_POINT}"
hdiutil convert "${RW_DMG}" -format UDZO -o "${rust_bin_dir}.dmg"
rm -f "${RW_DMG}"
rm -rf "${APP_BUNDLE}"
}
package_dmg "$WindSendRustBin_X86_64DirName"
package_dmg "$WindSendRustBin_DirName"
######################################################################################
# Press Enter to continue building WindSend Flutter for x86_64
if ! TheVariableIsTrue "$CI_RUNNING"; then
read -rp "Press Enter to continue..."
fi
flutterX86_64DirName="WindSend-macos-x64-flutter-$BUILD_TAG"
# Build WindSend Flutter for x86_64
cd "$WINDSEND_PROJECT_PATH" || exit
cd "$WINDSEND_FLUTTER_PATH" || exit
if ! flutter build macos --release; then
echo "Build Failed!"
exit 0
fi
mkdir -p ../../bin/"$flutterX86_64DirName"
APP_BUNDLE=$(find build/macos/Build/Products/Release/ -maxdepth 1 -name "*.app")
# cp -r build/macos/Build/Products/Release/* ../../bin/"$flutterX86_64DirName"
cp -r "$APP_BUNDLE" ../../bin/"$flutterX86_64DirName"
cd "$WINDSEND_PROJECT_PATH" || exit
cp README.md ./bin/"$flutterX86_64DirName"
cp README-EN.md ./bin/"$flutterX86_64DirName"
cd ./bin || exit
zip -r "$flutterX86_64DirName".zip "$flutterX86_64DirName"