-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·139 lines (118 loc) · 3.44 KB
/
build.sh
File metadata and controls
executable file
·139 lines (118 loc) · 3.44 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
#!/bin/bash
# Exit on any error
set -e
# Function to check if a command exists
command_exists () {
command -v "$1" >/dev/null 2>&1
}
# Default mode is release for smaller, production-ready builds
MODE=${1:-release}
# Validate mode
if [[ "$MODE" != "debug" && "$MODE" != "release" ]]; then
echo "Error: Invalid mode. Use 'debug' or 'release'."
exit 1
fi
# Check dependencies
missing_deps=0
# Check for Python
if ! command_exists python3; then
missing_deps=1
echo "❌ Python 3 is not installed."
echo ""
echo "To install Python, visit the official download page:"
echo "👉 https://www.python.org/downloads/"
echo ""
echo "Or install it using a package manager:"
echo ""
echo "🔹 macOS (Homebrew):"
echo " brew install python3"
echo ""
echo "🔹 Ubuntu/Debian:"
echo " sudo apt-get install -y python3 python3-pip"
echo ""
echo "🔹 Arch Linux:"
echo " sudo pacman -S python"
echo ""
fi
# Check for uv
if ! command_exists uv; then
missing_deps=1
echo "❌ uv is not installed."
echo ""
echo "To install uv:"
echo "👉 curl -LsSf https://astral.sh/uv/install.sh | sh"
echo "Or with Homebrew:"
echo "👉 brew install uv"
echo ""
fi
# Exit with a bad exit code if any dependencies are missing
if [ "$missing_deps" -ne 0 ]; then
echo "Install the missing dependencies and ensure they are on your path. Then run this command again."
exit 1
fi
# Check if pyproject.toml exists
if [ ! -f "pyproject.toml" ]; then
echo "Error: No pyproject.toml found. Please run this script in the Python project directory."
exit 1
fi
# Check if wit directory exists
if [ ! -d "wit" ]; then
echo "Error: No wit directory found. Please ensure the WIT interface definitions are present."
exit 1
fi
# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
echo "Creating virtual environment with uv..."
uv venv
fi
# Install Python dependencies using uv sync
echo "Installing Python dependencies..."
uv sync
# Fetch WIT dependencies using wkg
echo "Fetching WIT dependencies..."
wkg wit fetch
# Extract world name from WIT file
echo "Extracting world name from WIT files..."
WORLD_NAME=$(grep -h "^world " wit/*.wit 2>/dev/null | head -1 | sed 's/^world \([a-zA-Z0-9_-]*\).*/\1/')
if [ -z "$WORLD_NAME" ]; then
echo "Error: Could not extract world name from WIT files"
exit 1
fi
echo "Found world: $WORLD_NAME"
# Clean up old bindings if they exist
if [ -d "wit_world" ]; then
echo "Cleaning old Python bindings..."
rm -rf wit_world
fi
# Generate Python bindings from WIT
echo "Generating Python bindings..."
uv run componentize-py -d wit/ -w "$WORLD_NAME" bindings .
# Build the Python component to WASM
echo "Building Python component to WASM..."
# Create dist directory if it doesn't exist
mkdir -p dist
# Build the component
# Note: Replace 'app' with your main module name if different
if [ "$MODE" = "release" ]; then
echo "Building in release mode..."
uv run componentize-py \
-d wit/ \
-w "$WORLD_NAME" \
componentize \
app \
-o dist/plugin.wasm
else
echo "Building in debug mode..."
uv run componentize-py \
-d wit/ \
-w "$WORLD_NAME" \
componentize \
app \
-o dist/plugin.wasm
fi
# Check if the generated .wasm file exists
if [ ! -f "dist/plugin.wasm" ]; then
echo "Error: WASM file generation failed"
exit 1
fi
echo "✓ Build complete. WASM file created at dist/plugin.wasm"