-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild_maclinux.sh
More file actions
382 lines (327 loc) · 14.7 KB
/
build_maclinux.sh
File metadata and controls
382 lines (327 loc) · 14.7 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash
set -e
# Set minimum macOS version to 10.15 (Catalina)
# We use -weak_framework for UniformTypeIdentifiers to allow running on 10.15
export MACOSX_DEPLOYMENT_TARGET=10.15
# Ensure Go build cache is writable in this workspace (sandbox-safe)
export GOCACHE="${PWD}/.gocache"
mkdir -p "$GOCACHE"
APP_NAME="MaClaw"
# Read version from build_number if exists, else default
if [ -f "build_number" ]; then
BUILD_NUM=$(cat build_number)
VERSION="3.5.0.${BUILD_NUM}"
else
BUILD_NUM="1"
VERSION="3.5.0.1"
fi
# Sync version to frontend
echo "Syncing version $VERSION to frontend..."
sed -i '' "s/const APP_VERSION = \".*\";/const APP_VERSION = \"$VERSION\";/" gui/frontend/src/App.tsx
cat > gui/frontend/src/version.ts <<VEOF
export const buildNumber = "$BUILD_NUM";
export const appVersion = "$VERSION";
VEOF
IDENTIFIER="com.wails.MaClaw"
OUTPUT_DIR="dist"
BIN_DIR="build/bin"
# Check for Go
if ! command -v go &> /dev/null; then
echo "Error: 'go' command not found in PATH."
echo "Please ensure Go is installed and available."
exit 1
fi
echo "Starting build process for version $VERSION..."
# Clean previous build
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
mkdir -p "$BIN_DIR"
# Build Frontend
echo "[1/4] Building Frontend..."
cd gui/frontend
npm install --cache ./.npm_cache
npm run build
cd ../..
# Build Binaries
echo "[2/4] Compiling Go Binaries..."
# Build AMD64
echo " - Building for amd64..."
CGO_ENABLED=1 CGO_LDFLAGS="-weak_framework UniformTypeIdentifiers" GOOS=darwin GOARCH=amd64 go build -tags desktop,production -o "${BIN_DIR}/${APP_NAME}_amd64" ./gui/
# Build ARM64
echo " - Building for arm64..."
CGO_ENABLED=1 CGO_LDFLAGS="-weak_framework UniformTypeIdentifiers" GOOS=darwin GOARCH=arm64 go build -tags desktop,production -o "${BIN_DIR}/${APP_NAME}_arm64" ./gui/
# Generate Windows Resources
echo " - Generating Windows Resources..."
RSRC_TOOL=$(go env GOPATH)/bin/rsrc
if [ ! -x "$RSRC_TOOL" ]; then
RSRC_TOOL=rsrc
fi
if command -v "$RSRC_TOOL" &> /dev/null; then
# Create temporary manifest with substituted values
# Replace template variables with actual values to prevent "Side-by-side configuration is incorrect" error
sed -e "s/{{.Name}}/$APP_NAME/g" \
-e "s/{{.Info.ProductVersion}}.0/$VERSION/g" \
build/windows/wails.exe.manifest > build/windows/wails.exe.manifest.tmp
"$RSRC_TOOL" -manifest build/windows/wails.exe.manifest.tmp -ico build/windows/icon.ico -arch amd64 -o gui/resource_windows_amd64.syso
"$RSRC_TOOL" -manifest build/windows/wails.exe.manifest.tmp -ico build/windows/icon.ico -arch arm64 -o gui/resource_windows_arm64.syso
rm build/windows/wails.exe.manifest.tmp
else
echo "Warning: rsrc tool not found. Windows executables will not have icons."
fi
# Build Windows AMD64
echo " - Building for Windows amd64..."
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags desktop,production -ldflags "-s -w -H windowsgui" -o "${BIN_DIR}/${APP_NAME}_amd64.exe" ./gui/
# Build Windows ARM64
echo " - Building for Windows arm64..."
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -tags desktop,production -ldflags "-s -w -H windowsgui" -o "${BIN_DIR}/${APP_NAME}_arm64.exe" ./gui/
# Cleanup Windows Resources
rm -f gui/resource_windows_amd64.syso gui/resource_windows_arm64.syso
# Build TUI/CLI Binaries
echo " - Building TUI/CLI binaries..."
TUI_LDFLAGS="-s -w -X main.version=${VERSION}"
for TUI_ARCH in amd64 arm64; do
# macOS TUI
CGO_ENABLED=0 GOOS=darwin GOARCH=$TUI_ARCH go build -ldflags "$TUI_LDFLAGS" -o "${BIN_DIR}/maclaw-tui_${TUI_ARCH}_darwin" ./tui/
# Windows TUI
CGO_ENABLED=0 GOOS=windows GOARCH=$TUI_ARCH go build -ldflags "$TUI_LDFLAGS" -o "${BIN_DIR}/maclaw-tui_${TUI_ARCH}.exe" ./tui/
# Linux TUI
CGO_ENABLED=0 GOOS=linux GOARCH=$TUI_ARCH go build -ldflags "$TUI_LDFLAGS" -o "${BIN_DIR}/maclaw-tui_${TUI_ARCH}_linux" ./tui/
# maclaw-tool
CGO_ENABLED=0 GOOS=darwin GOARCH=$TUI_ARCH go build -ldflags "$TUI_LDFLAGS" -o "${BIN_DIR}/maclaw-tool_${TUI_ARCH}_darwin" ./cmd/maclaw-tool/
CGO_ENABLED=0 GOOS=windows GOARCH=$TUI_ARCH go build -ldflags "$TUI_LDFLAGS" -o "${BIN_DIR}/maclaw-tool_${TUI_ARCH}.exe" ./cmd/maclaw-tool/
CGO_ENABLED=0 GOOS=linux GOARCH=$TUI_ARCH go build -ldflags "$TUI_LDFLAGS" -o "${BIN_DIR}/maclaw-tool_${TUI_ARCH}_linux" ./cmd/maclaw-tool/
done
echo " TUI/CLI binaries built for all platforms."
# Export PATH for nfpm
export PATH=$PATH:$(go env GOPATH)/bin
# Build Linux
build_linux() {
ARCH=$1
echo " - Building for Linux $ARCH..."
# Check for cross-compiler if on macOS
CC_CMD=""
if [ "$(uname)" == "Darwin" ]; then
if [ "$ARCH" == "amd64" ]; then
if command -v x86_64-linux-gnu-gcc &> /dev/null; then
CC_CMD="CC=x86_64-linux-gnu-gcc"
else
echo " Skipping Linux $ARCH build: x86_64-linux-gnu-gcc not found."
return
fi
elif [ "$ARCH" == "arm64" ]; then
if command -v aarch64-linux-gnu-gcc &> /dev/null; then
CC_CMD="CC=aarch64-linux-gnu-gcc"
else
echo " Skipping Linux $ARCH build: aarch64-linux-gnu-gcc not found."
return
fi
fi
fi
# Build binary
# Note: On Linux/macOS cross-compile, CGO is required for Wails.
if [ -n "$CC_CMD" ]; then
eval $CC_CMD CGO_ENABLED=1 GOOS=linux GOARCH=$ARCH go build -tags desktop,production -o "${BIN_DIR}/${APP_NAME}_${ARCH}_linux" ./gui/
elif [ "$(uname)" == "Linux" ]; then
CGO_ENABLED=1 GOOS=linux GOARCH=$ARCH go build -tags desktop,production -o "${BIN_DIR}/${APP_NAME}_${ARCH}_linux" ./gui/
fi
# Package
if [ -f "${BIN_DIR}/${APP_NAME}_${ARCH}_linux" ]; then
APP_DIR="build/linux/AppDir_${ARCH}"
rm -rf "$APP_DIR"
mkdir -p "$APP_DIR/usr/bin"
mkdir -p "$APP_DIR/usr/share/icons/hicolor/512x512/apps"
# Copy binary
cp "${BIN_DIR}/${APP_NAME}_${ARCH}_linux" "$APP_DIR/usr/bin/maclaw"
# Copy desktop file
cp "build/linux/maclaw.desktop" "$APP_DIR/"
# Copy icon
cp "build/appicon.png" "$APP_DIR/maclaw.png"
cp "build/appicon.png" "$APP_DIR/.DirIcon"
# Create AppRun
cat > "$APP_DIR/AppRun" <<EOF
#!/bin/bash
HERE="\$(dirname "\$(readlink -f "\${0}")")"
export PATH="\${HERE}/usr/bin:\${PATH}"
exec maclaw "\$@"
EOF
chmod +x "$APP_DIR/AppRun"
# Check and setup appimagetool
if ! command -v appimagetool &> /dev/null; then
if [ "$(uname)" == "Linux" ]; then
echo " appimagetool not found. Downloading..."
wget -q -O appimagetool "https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-x86_64.AppImage"
chmod +x appimagetool
export PATH="$(pwd):$PATH"
fi
fi
if command -v appimagetool &> /dev/null; then
echo " Generating AppImage for Linux $ARCH..."
# appimagetool requires ARCH variable to be set correctly
AI_ARCH=$ARCH
if [ "$ARCH" == "amd64" ]; then AI_ARCH="x86_64"; fi
if [ "$ARCH" == "arm64" ]; then AI_ARCH="aarch64"; fi
# Try running normally, if fails (no FUSE), try extract-and-run
if ! ARCH=$AI_ARCH appimagetool "$APP_DIR" "${OUTPUT_DIR}/MaClaw-${VERSION}-${AI_ARCH}.AppImage"; then
echo " Standard run failed (likely no FUSE), trying --appimage-extract-and-run..."
ARCH=$AI_ARCH appimagetool --appimage-extract-and-run "$APP_DIR" "${OUTPUT_DIR}/MaClaw-${VERSION}-${AI_ARCH}.AppImage"
fi
else
echo " Skipping AppImage generation: appimagetool not found (and could not be downloaded/run on this OS)."
echo " AppDir prepared at $APP_DIR"
fi
fi
}
build_linux amd64
build_linux arm64
# Generate ICNS
echo " - Generating .icns file..."
if [ -f "build/appicon.png" ]; then
ICONSET_DIR="build/appicon.iconset"
rm -rf "$ICONSET_DIR"
mkdir -p "$ICONSET_DIR"
# Generate standard sizes
sips -z 16 16 "build/appicon.png" --out "${ICONSET_DIR}/icon_16x16.png" > /dev/null
sips -z 32 32 "build/appicon.png" --out "${ICONSET_DIR}/icon_16x16@2x.png" > /dev/null
sips -z 32 32 "build/appicon.png" --out "${ICONSET_DIR}/icon_32x32.png" > /dev/null
sips -z 64 64 "build/appicon.png" --out "${ICONSET_DIR}/icon_32x32@2x.png" > /dev/null
sips -z 128 128 "build/appicon.png" --out "${ICONSET_DIR}/icon_128x128.png" > /dev/null
sips -z 256 256 "build/appicon.png" --out "${ICONSET_DIR}/icon_128x128@2x.png" > /dev/null
sips -z 256 256 "build/appicon.png" --out "${ICONSET_DIR}/icon_256x256.png" > /dev/null
sips -z 512 512 "build/appicon.png" --out "${ICONSET_DIR}/icon_256x256@2x.png" > /dev/null
sips -z 512 512 "build/appicon.png" --out "${ICONSET_DIR}/icon_512x512.png" > /dev/null
sips -z 1024 1024 "build/appicon.png" --out "${ICONSET_DIR}/icon_512x512@2x.png" > /dev/null
if ! iconutil -c icns "$ICONSET_DIR" -o "build/AppIcon.icns"; then
echo " Warning: iconutil failed. Falling back to existing .icns if available."
if [ -f "build/iconfile.icns" ]; then
cp "build/iconfile.icns" "build/AppIcon.icns"
echo " Fallback icon copied from build/iconfile.icns"
elif [ -f "build/AppIcon.icns" ]; then
echo " Keeping existing build/AppIcon.icns"
else
echo " No .icns fallback found; app bundle will use PNG icon."
fi
fi
rm -rf "$ICONSET_DIR"
echo " Generated build/AppIcon.icns"
fi
# Function to create App Bundle
create_app_bundle() {
ARCH=$1
BINARY_NAME="${APP_NAME}_${ARCH}"
BUNDLE_PATH="${OUTPUT_DIR}/${APP_NAME}_${ARCH}.app"
echo " - Creating App Bundle for $ARCH..."
mkdir -p "${BUNDLE_PATH}/Contents/MacOS"
mkdir -p "${BUNDLE_PATH}/Contents/Resources"
# Copy Binary
cp "${BIN_DIR}/${BINARY_NAME}" "${BUNDLE_PATH}/Contents/MacOS/${APP_NAME}"
chmod +x "${BUNDLE_PATH}/Contents/MacOS/${APP_NAME}"
# Create Info.plist (Clean generation)
cat > "${BUNDLE_PATH}/Contents/Info.plist" <<EOF
<?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>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>${APP_NAME}</string>
<key>CFBundleExecutable</key>
<string>${APP_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${IDENTIFIER}</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundleGetInfoString</key>
<string>MaClaw</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>LSMinimumSystemVersion</key>
<string>10.15.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2026 RapidAI</string>
<key>NSDesktopFolderUsageDescription</key>
<string>MaClaw needs access to your Desktop folder to manage project files.</string>
<key>NSDocumentsFolderUsageDescription</key>
<string>MaClaw needs access to your Documents folder to manage project files.</string>
<key>NSDownloadsFolderUsageDescription</key>
<string>MaClaw needs access to your Downloads folder to install tools and updates.</string>
<key>NSLocalNetworkUsageDescription</key>
<string>MaClaw uses local network to discover and connect to Hub services.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>MaClaw needs photo library access to process screenshots and images.</string>
</dict>
</plist>
EOF
# Copy Icon
if [ -f "build/AppIcon.icns" ]; then
cp "build/AppIcon.icns" "${BUNDLE_PATH}/Contents/Resources/AppIcon.icns"
elif [ -f "build/appicon.png" ]; then
cp "build/appicon.png" "${BUNDLE_PATH}/Contents/Resources/AppIcon.png"
fi
touch "${BUNDLE_PATH}"
}
echo "[3/4] Creating App Bundles..."
create_app_bundle amd64
create_app_bundle arm64
# Create Universal Binary
echo " - Creating Universal Binary..."
UNIVERSAL_BUNDLE="${OUTPUT_DIR}/${APP_NAME}.app"
mkdir -p "${UNIVERSAL_BUNDLE}/Contents/MacOS"
mkdir -p "${UNIVERSAL_BUNDLE}/Contents/Resources"
lipo -create "${BIN_DIR}/${APP_NAME}_amd64" "${BIN_DIR}/${APP_NAME}_arm64" -output "${UNIVERSAL_BUNDLE}/Contents/MacOS/${APP_NAME}"
cp "${OUTPUT_DIR}/${APP_NAME}_arm64.app/Contents/Info.plist" "${UNIVERSAL_BUNDLE}/Contents/Info.plist"
cp -R "${OUTPUT_DIR}/${APP_NAME}_arm64.app/Contents/Resources/" "${UNIVERSAL_BUNDLE}/Contents/Resources/"
touch "${UNIVERSAL_BUNDLE}"
# Function to create PKG
create_pkg() {
ARCH=$1
if [ "$ARCH" == "universal" ]; then
BUNDLE_PATH="${OUTPUT_DIR}/${APP_NAME}.app"
PKG_NAME="${APP_NAME}-Universal.pkg"
else
BUNDLE_PATH="${OUTPUT_DIR}/${APP_NAME}_${ARCH}.app"
PKG_NAME="${APP_NAME}-${ARCH}.pkg"
fi
# Temporary root for pkgbuild
TEMP_ROOT="build/pkg_root_${ARCH}"
rm -rf "$TEMP_ROOT"
mkdir -p "$TEMP_ROOT/Applications"
# Always install as MaClaw.app regardless of arch-specific bundle name
cp -R "$BUNDLE_PATH" "$TEMP_ROOT/Applications/${APP_NAME}.app"
SCRIPTS_DIR="build/scripts_x64"
if [ "$ARCH" == "arm64" ] || [ "$ARCH" == "universal" ]; then
SCRIPTS_DIR="build/scripts_arm64"
fi
echo " - Creating PKG for $ARCH using scripts from $SCRIPTS_DIR..."
# Ensure scripts are executable
chmod +x "$SCRIPTS_DIR/preinstall"
chmod +x "$SCRIPTS_DIR/postinstall"
pkgbuild --root "$TEMP_ROOT" \
--identifier "$IDENTIFIER" \
--version "$VERSION" \
--install-location "/" \
--scripts "$SCRIPTS_DIR" \
"${OUTPUT_DIR}/${PKG_NAME}"
rm -rf "$TEMP_ROOT"
}
echo "[4/4] Creating Packages..."
cp "${BIN_DIR}/${APP_NAME}_amd64.exe" "${OUTPUT_DIR}/"
cp "${BIN_DIR}/${APP_NAME}_arm64.exe" "${OUTPUT_DIR}/"
# Copy TUI/CLI binaries to output
for TUI_ARCH in amd64 arm64; do
cp "${BIN_DIR}/maclaw-tui_${TUI_ARCH}_darwin" "${OUTPUT_DIR}/" 2>/dev/null || true
cp "${BIN_DIR}/maclaw-tui_${TUI_ARCH}.exe" "${OUTPUT_DIR}/" 2>/dev/null || true
cp "${BIN_DIR}/maclaw-tui_${TUI_ARCH}_linux" "${OUTPUT_DIR}/" 2>/dev/null || true
cp "${BIN_DIR}/maclaw-tool_${TUI_ARCH}_darwin" "${OUTPUT_DIR}/" 2>/dev/null || true
cp "${BIN_DIR}/maclaw-tool_${TUI_ARCH}.exe" "${OUTPUT_DIR}/" 2>/dev/null || true
cp "${BIN_DIR}/maclaw-tool_${TUI_ARCH}_linux" "${OUTPUT_DIR}/" 2>/dev/null || true
done
create_pkg amd64
create_pkg arm64
create_pkg universal
echo "Build Complete!"
echo "App Bundles and Packages are in $OUTPUT_DIR"