-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·142 lines (126 loc) · 4.99 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·142 lines (126 loc) · 4.99 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
#!/bin/bash
# build.sh — Cross-platform build script for Scribble
# Usage:
# ./build.sh # Build for current platform
# ./build.sh macos # Build macOS DMG
# ./build.sh windows # Build Windows NSIS installer (requires Windows or cross-compile)
set -e
ROOT="$(cd "$(dirname "$0")" && pwd)"
SIDECAR_DIR="$ROOT/src-python"
BINARIES_DIR="$ROOT/src-tauri/binaries"
PLATFORM="${1:-auto}"
if [ "$PLATFORM" = "auto" ]; then
case "$(uname -s)" in
Darwin*) PLATFORM="macos" ;;
MINGW*|MSYS*|CYGWIN*) PLATFORM="windows" ;;
Linux*) PLATFORM="linux" ;;
esac
fi
echo "🔨 Building Scribble for: $PLATFORM"
# ── Step 1: Build Python sidecar (AV-optimized: no UPX, excludes, version info) ──
echo ""
echo "📦 Building Python sidecar..."
cd "$SIDECAR_DIR"
# Activate venv if exists, otherwise use system python3
if [ -f "$SIDECAR_DIR/.venv/bin/activate" ]; then
source "$SIDECAR_DIR/.venv/bin/activate"
fi
PYTHON_CMD="${PYTHON_CMD:-python3}"
$PYTHON_CMD -m PyInstaller scribble-sidecar.spec --noconfirm --clean
# ── onedir: copy entire directory to binaries + create launcher shim ──
SIDECAR_DIST="$SIDECAR_DIR/dist/scribble-sidecar"
if [ ! -d "$SIDECAR_DIST" ]; then
echo "❌ onedir output not found at $SIDECAR_DIST"
exit 1
fi
# Clean old sidecar files
rm -rf "$BINARIES_DIR"/scribble-sidecar-*
rm -rf "$BINARIES_DIR"/sidecar-dist
# ── Strip unnecessary files before compression ──
echo "🗑️ Stripping sidecar-dist..."
DIST_INT="$SIDECAR_DIST/_internal"
rm -rf "$DIST_INT/grpc_tools" 2>/dev/null || true
find "$DIST_INT" -name "tests" -type d -exec rm -rf {} + 2>/dev/null || true
find "$DIST_INT" -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
find "$DIST_INT" -name "*.pyc" -delete 2>/dev/null || true
# NOTE: do NOT strip *.dist-info — transformers (Tier A nemotron MLX) reads
# package metadata at runtime via importlib.metadata (e.g. tqdm>=4.27). Removing
# dist-info breaks "No package metadata was found for tqdm" → nemotron won't load.
# ── Compress into tar.zst (fast decompress at first launch) ──
echo "📦 Compressing sidecar-dist..."
STRIPPED_SIZE=$(du -sh "$SIDECAR_DIST" | cut -f1)
echo " Uncompressed: $STRIPPED_SIZE"
# Strip macOS xattrs first, then tar with COPYFILE_DISABLE=1 so macOS does NOT
# embed AppleDouble `._*` companion files. The Rust extractor (tar crate) does
# not understand AppleDouble and would extract them as literal files — e.g.
# transformers/models/._foo.py — which transformers' import scanner then reads
# as UTF-8 source and crashes ("can't decode byte 0xa3"). Breaks Tier A nemotron.
xattr -cr "$SIDECAR_DIST" 2>/dev/null || true
COPYFILE_DISABLE=1 tar --zstd -cf "$BINARIES_DIR/sidecar-dist.tar.zst" -C "$SIDECAR_DIR/dist" scribble-sidecar
COMPRESSED_SIZE=$(du -sh "$BINARIES_DIR/sidecar-dist.tar.zst" | cut -f1)
echo " Compressed: $COMPRESSED_SIZE"
# Clean raw directory — only ship compressed
rm -rf "$BINARIES_DIR/sidecar-dist"
# Create thin launcher script that Tauri can execute as externalBin
if [ "$PLATFORM" = "windows" ]; then
SIDECAR_NAME="scribble-sidecar-x86_64-pc-windows-msvc.exe"
# Windows: create batch launcher
cat > "$BINARIES_DIR/$SIDECAR_NAME" << 'WINEOF'
@echo off
"%~dp0sidecar-dist\scribble-sidecar.exe" %*
WINEOF
elif [ "$PLATFORM" = "macos" ]; then
ARCH="$(uname -m)"
if [ "$ARCH" = "arm64" ]; then
SIDECAR_NAME="scribble-sidecar-aarch64-apple-darwin"
else
SIDECAR_NAME="scribble-sidecar-x86_64-apple-darwin"
fi
# macOS/Linux: create shell launcher that checks multiple locations
cat > "$BINARIES_DIR/$SIDECAR_NAME" << 'SHEOF'
#!/bin/bash
DIR="$(cd "$(dirname "$0")" && pwd)"
# Check: same dir (dev), then Resources (macOS .app bundle)
for candidate in \
"$DIR/sidecar-dist/scribble-sidecar" \
"$DIR/../Resources/sidecar-dist/scribble-sidecar"; do
if [ -x "$candidate" ]; then
exec "$candidate" "$@"
fi
done
echo "[sidecar-launcher] ERROR: scribble-sidecar not found" >&2
exit 1
SHEOF
chmod +x "$BINARIES_DIR/$SIDECAR_NAME"
elif [ "$PLATFORM" = "linux" ]; then
SIDECAR_NAME="scribble-sidecar-x86_64-unknown-linux-gnu"
cat > "$BINARIES_DIR/$SIDECAR_NAME" << 'SHEOF'
#!/bin/bash
DIR="$(cd "$(dirname "$0")" && pwd)"
for candidate in \
"$DIR/sidecar-dist/scribble-sidecar" \
"$DIR/../Resources/sidecar-dist/scribble-sidecar"; do
if [ -x "$candidate" ]; then
exec "$candidate" "$@"
fi
done
echo "[sidecar-launcher] ERROR: scribble-sidecar not found" >&2
exit 1
SHEOF
chmod +x "$BINARIES_DIR/$SIDECAR_NAME"
fi
echo "✅ Sidecar built (onedir): $SIDECAR_NAME + sidecar-dist/"
# ── Step 2: Build Tauri app ──
echo ""
echo "🏗️ Building Tauri app..."
cd "$ROOT"
if [ "$PLATFORM" = "macos" ]; then
npx tauri build -b dmg --verbose
elif [ "$PLATFORM" = "windows" ]; then
npx tauri build -b nsis --verbose
elif [ "$PLATFORM" = "linux" ]; then
npx tauri build -b deb --verbose
fi
echo ""
echo "🎉 Build complete!"
echo " Output: src-tauri/target/release/bundle/"