Skip to content

Commit b5a1fec

Browse files
committed
Enhance build scripts and documentation for cross-platform support with Ruff
- Updated `build-with-ruff.sh` to include Windows support, bundling Pyright only (no Ruff). - Modified Node.js download logic to accommodate Windows platform. - Improved cleanup process for both Windows and Unix builds. - Enhanced README.md to clarify Ruff support for Linux/macOS and Pyright-only builds for Windows. - Updated GitHub Actions workflow to build for all platforms, including Windows.
1 parent f1125de commit b5a1fec

File tree

3 files changed

+198
-35
lines changed

3 files changed

+198
-35
lines changed

.github/workflows/build-with-ruff.yml

Lines changed: 120 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build with Ruff Support
1+
name: Build with Ruff Support (All Platforms)
22

33
on:
44
push:
@@ -12,6 +12,12 @@ env:
1212
NODE_VERSION: 'v20.11.0'
1313
RUFF_VERSION: '0.14.3'
1414

15+
# This workflow builds for all platforms:
16+
# - Linux x64 with Ruff
17+
# - macOS x64 with Ruff
18+
# - macOS arm64 with Ruff
19+
# - Windows x64 (Pyright only - no Ruff)
20+
1521
jobs:
1622
linux:
1723
runs-on: ubuntu-latest
@@ -213,10 +219,101 @@ jobs:
213219
name: darwin-${{ matrix.arch }}
214220
path: output/darwin-${{ matrix.arch }}.tar.gz
215221

222+
windows:
223+
runs-on: windows-latest
224+
steps:
225+
- uses: actions/checkout@v4
226+
227+
- uses: actions/setup-node@v4
228+
with:
229+
node-version: '20'
230+
231+
- name: Install dependencies
232+
run: npm install
233+
234+
- name: Build for win32-x64 (Pyright only)
235+
shell: bash
236+
run: |
237+
PLATFORM="win32-x64"
238+
NODE_DOWNLOAD_ARCH="win-x64"
239+
240+
mkdir -p output/${PLATFORM}
241+
242+
# Bundle TypeScript with esbuild
243+
npx esbuild index.ts \
244+
--bundle \
245+
--platform=node \
246+
--target=node18 \
247+
--format=esm \
248+
--outfile=output/${PLATFORM}/bundle.js \
249+
--external:ws \
250+
--external:vscode-ws-jsonrpc \
251+
--external:vscode-jsonrpc \
252+
--external:dotenv
253+
254+
# Download Node.js runtime (Windows uses 'win-x64' not 'win32-x64')
255+
NODE_PKG="node-${NODE_VERSION}-${NODE_DOWNLOAD_ARCH}"
256+
NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.zip"
257+
echo "Downloading: ${NODE_URL}"
258+
curl -fsSL "${NODE_URL}" -o "${NODE_PKG}.zip"
259+
unzip -q "${NODE_PKG}.zip" -d "output/${PLATFORM}/"
260+
mv "output/${PLATFORM}/${NODE_PKG}" "output/${PLATFORM}/node"
261+
rm -f "${NODE_PKG}.zip"
262+
263+
# Strip unnecessary files from Node.js
264+
cd output/${PLATFORM}/node
265+
rm -rf lib/node_modules/npm lib/node_modules/corepack node_modules/npm node_modules/corepack
266+
rm -f npm npm.cmd npx npx.cmd corepack corepack.cmd
267+
rm -f README.md CHANGELOG.md LICENSE *.md
268+
cd ../../..
269+
270+
# Note: Ruff is NOT bundled for Windows builds
271+
echo "Windows build: Pyright only (no Ruff bundling)"
272+
273+
# Install production dependencies
274+
cp package.json output/${PLATFORM}/
275+
cd output/${PLATFORM}
276+
npm install --production --no-optional
277+
rm package-lock.json
278+
echo '{"type":"module"}' > package.json
279+
280+
# Prune unnecessary files from node_modules
281+
find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true
282+
find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true
283+
find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true
284+
find node_modules -type f -name "*.md" -delete 2>/dev/null || true
285+
find node_modules -type f -name "*.ts" ! -name "*.d.ts" -delete 2>/dev/null || true
286+
find node_modules -type f -name "*.map" -delete 2>/dev/null || true
287+
cd ../..
288+
289+
# Copy config template
290+
cp pyrightconfig.json output/${PLATFORM}/
291+
292+
# Create start script (without RUFF_PATH)
293+
cat > output/${PLATFORM}/start.bat << 'EOF'
294+
@echo off
295+
REM Pyright LSP WebSocket Bridge (Pyright only - no Ruff bundled)
296+
REM Usage: start.bat --port <PORT> --bot-root <BOT_ROOT> --jesse-root <JESSE_ROOT>
297+
298+
set DIR=%~dp0
299+
"%DIR%node\node.exe" "%DIR%bundle.js" %*
300+
EOF
301+
302+
# Create compressed archive
303+
cd output
304+
powershell Compress-Archive -Path ${PLATFORM} -DestinationPath ${PLATFORM}.zip
305+
cd ..
306+
307+
- name: Upload artifact
308+
uses: actions/upload-artifact@v4
309+
with:
310+
name: win32-x64
311+
path: output/win32-x64.zip
312+
216313
release:
217314
name: Create GitHub Release
218315
runs-on: ubuntu-latest
219-
needs: [linux, macos]
316+
needs: [linux, macos, windows]
220317
if: startsWith(github.ref, 'refs/tags/v')
221318

222319
steps:
@@ -236,34 +333,45 @@ jobs:
236333
body: |
237334
## Pyright LSP Bridge with Ruff Formatting Support
238335
239-
This release includes Ruff formatter bundled with the language server.
336+
This release includes Ruff formatter bundled with Unix builds (Linux/macOS).
240337
241338
### Platform Support
242-
- ✅ Linux x64 with Ruff
243-
- ✅ macOS Intel (x64) with Ruff
244-
- ✅ macOS Apple Silicon (arm64) with Ruff
339+
- ✅ **Linux x64** (~46 MB) - Includes Ruff formatter
340+
- ✅ **macOS Intel (x64)** (~44 MB) - Includes Ruff formatter
341+
- ✅ **macOS Apple Silicon (arm64)** (~44 MB) - Includes Ruff formatter
342+
- ✅ **Windows x64** (~34 MB) - Pyright only (no Ruff)
343+
344+
> **Note:** Ruff formatting is only bundled for Unix-based systems (Linux/macOS). Windows builds include Pyright language server capabilities only.
245345
246346
### Features
247-
- Python language server (Pyright)
248-
- Code formatting (Ruff)
249-
- Cross-platform support
250-
- Bundled Node.js runtime
347+
- ✅ Python language server (Pyright) - All platforms
348+
- ✅ Code formatting (Ruff) - Linux/macOS only
349+
- ✅ Cross-platform support
350+
- ✅ Bundled Node.js runtime
351+
- ✅ WebSocket-based communication
251352
252353
### Installation
253354
254355
**Linux:**
255356
```bash
256-
tar -xzf linux-x64-with-ruff.tar.gz
357+
tar -xzf linux-x64.tar.gz
257358
cd linux-x64
258359
./start.sh --port 9011 --bot-root /path/to/bot --jesse-root /path/to/jesse
259360
```
260361
261362
**macOS:**
262363
```bash
263-
tar -xzf darwin-arm64-with-ruff.tar.gz # or darwin-x64-with-ruff.tar.gz
364+
tar -xzf darwin-arm64.tar.gz # or darwin-x64.tar.gz for Intel Macs
264365
cd darwin-arm64 # or darwin-x64
265366
./start.sh --port 9011 --bot-root /path/to/bot --jesse-root /path/to/jesse
266367
```
368+
369+
**Windows:**
370+
```cmd
371+
REM Extract win32-x64.zip
372+
cd win32-x64
373+
start.bat --port 9011 --bot-root C:\path\to\bot --jesse-root C:\path\to\jesse
374+
```
267375
env:
268376
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
269377

README.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ This repository delivers:
99
- **Bundled Runtime** - Includes Node.js, eliminating system dependencies
1010
- **Cross-Platform Support** - Works on Linux, macOS, and Windows
1111
- **Optimized Builds** - ~70% size reduction with production-only dependencies
12+
- **Ruff Formatting** - Built-in Python code formatting (Linux/macOS only)
1213

1314
## Technology Stack
1415

1516
- **TypeScript** - Main language for the bridge implementation
1617
- **Node.js** - Runtime environment
1718
- **Pyright** - Microsoft's static type checker for Python
19+
- **Ruff** - Fast Python linter and formatter (Unix builds only)
1820
- **WebSocket (ws)** - WebSocket communication
1921
- **vscode-ws-jsonrpc** - JSON-RPC over WebSocket
2022
- **esbuild** - Fast JavaScript bundler
@@ -41,20 +43,30 @@ npm start -- \
4143

4244
## Build
4345

44-
### Single Platform (Linux x64)
46+
### Build with Ruff Support (Recommended)
4547
```bash
46-
./build.sh
48+
./build-with-ruff.sh
4749
```
48-
Output: `output/linux-x64.tar.gz` (~34 MB)
50+
This builds for all platforms with Ruff formatting support included in Linux/macOS builds:
51+
- `linux-x64.tar.gz` (~46 MB) - **Includes Ruff**
52+
- `darwin-x64.tar.gz` (~44 MB) - **Includes Ruff**
53+
- `darwin-arm64.tar.gz` (~44 MB) - **Includes Ruff**
54+
- `win32-x64.zip` (~34 MB) - Pyright only (no Ruff)
55+
56+
**Note:** Ruff is only bundled for Unix-based systems (Linux/macOS). Windows builds include Pyright only.
4957

50-
### All Platforms
58+
### Build without Ruff (Legacy)
5159
```bash
60+
# Single platform (Linux x64 only)
61+
./build.sh
62+
63+
# All platforms (no Ruff bundled)
5264
./build-all.sh
5365
```
5466
Outputs:
55-
- `linux-x64.tar.gz` / `linux-arm64.tar.gz`
56-
- `darwin-x64.tar.gz` / `darwin-arm64.tar.gz`
57-
- `win32-x64.zip`
67+
- `linux-x64.tar.gz` / `linux-arm64.tar.gz` (~34 MB each)
68+
- `darwin-x64.tar.gz` / `darwin-arm64.tar.gz` (~34 MB each)
69+
- `win32-x64.zip` (~34 MB)
5870

5971
## Deployment & Usage
6072

@@ -92,6 +104,16 @@ The Pyright language server is configured via `pyrightconfig.json`. The bridge a
92104
- ✅ Production-ready dependencies only
93105
- ✅ WebSocket-based communication
94106
- ✅ Full Pyright LSP capabilities
107+
- ✅ Ruff code formatting (Linux/macOS builds)
108+
109+
### Ruff Formatting Support
110+
111+
Ruff is a fast Python linter and formatter written in Rust. When using builds from `build-with-ruff.sh`:
112+
113+
- **Linux/macOS**: Ruff binary is bundled and intercepts LSP formatting requests
114+
- **Windows**: Pyright only (no Ruff bundling)
115+
116+
Formatting is automatically handled when you trigger "Format Document" in your IDE. The bridge intercepts `textDocument/formatting` requests and processes them with Ruff for Unix-based systems.
95117

96118
## Architecture
97119

@@ -107,10 +129,13 @@ Messages are translated between WebSocket and the Language Server Protocol, enab
107129

108130
- `index.ts` - Entry point and CLI argument handling
109131
- `pyright-bridge.ts` - WebSocket bridge implementation
132+
- `formatting.ts` - Ruff formatting handler
110133
- `pyrightconfig.json` - Pyright configuration
111134
- `package.json` - Node.js project configuration
112-
- `build.sh` - Build script for Linux x64
113-
- `build-all.sh` - Build script for all platforms
135+
- `build.sh` - Build script for Linux x64 (no Ruff)
136+
- `build-all.sh` - Build script for all platforms (no Ruff)
137+
- `build-with-ruff.sh` - Build script with Ruff support (Linux/macOS/Windows)
138+
- `build-windows.sh` - Build script for Windows only (with Ruff)
114139
- `output/` - Build output directory (generated)
115140

116141
## License

build-with-ruff.sh

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/bin/bash
22

33
# Build script with Ruff support for Linux and macOS
4-
# Downloads platform-specific Ruff binaries and bundles them
4+
# Windows build included but without Ruff (Pyright only)
5+
# Note: Ruff is only bundled for Unix-based systems (Linux/macOS)
56

67
set -e
78

89
NODE_VERSION="v20.11.0"
910
RUFF_VERSION="0.14.3"
1011

1112
# Function to get ruff download info for a platform
13+
# Returns empty string for Windows (no Ruff bundling)
1214
get_ruff_info() {
1315
local os=$1
1416
local arch=$2
@@ -27,6 +29,7 @@ get_ruff_info() {
2729
echo "ruff-aarch64-apple-darwin.tar.gz|ruff"
2830
;;
2931
*)
32+
# Windows and other platforms: no Ruff bundling
3033
echo ""
3134
;;
3235
esac
@@ -46,6 +49,9 @@ build_platform() {
4649

4750
# Get Node.js architecture name
4851
local node_arch="${os}-${arch}"
52+
if [ "${os}" = "win32" ]; then
53+
node_arch="win-${arch}" # Node.js uses "win-x64" for Windows
54+
fi
4955

5056
# Step 1: Bundle TypeScript
5157
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@@ -74,8 +80,14 @@ build_platform() {
7480
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
7581

7682
NODE_PKG="node-${NODE_VERSION}-${node_arch}"
77-
NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz"
78-
NODE_FILE="/tmp/${NODE_PKG}.tar.gz"
83+
84+
if [ "${os}" = "win32" ]; then
85+
NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.zip"
86+
NODE_FILE="/tmp/${NODE_PKG}.zip"
87+
else
88+
NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/${NODE_PKG}.tar.gz"
89+
NODE_FILE="/tmp/${NODE_PKG}.tar.gz"
90+
fi
7991

8092
if [ ! -f "${NODE_FILE}" ]; then
8193
curl -L "${NODE_URL}" -o "${NODE_FILE}" || {
@@ -87,20 +99,34 @@ build_platform() {
8799
fi
88100

89101
echo "📂 Extracting Node.js..."
90-
tar -xzf "${NODE_FILE}" -C /tmp/
102+
if [ "${os}" = "win32" ]; then
103+
unzip -q "${NODE_FILE}" -d /tmp/
104+
else
105+
tar -xzf "${NODE_FILE}" -C /tmp/
106+
fi
91107
mv "/tmp/${NODE_PKG}" "output/${platform}/node"
92108

93109
# Strip unnecessary files from Node.js
94110
echo "🧹 Stripping unnecessary files from Node.js..."
95111
cd "output/${platform}/node"
96-
rm -rf lib/node_modules/npm 2>/dev/null || true
97-
rm -rf lib/node_modules/corepack 2>/dev/null || true
98-
rm -f bin/npm bin/npx bin/corepack 2>/dev/null || true
99-
rm -rf share/doc share/man share/systemtap include 2>/dev/null || true
100-
rm -f README.md CHANGELOG.md LICENSE *.md 2>/dev/null || true
101112

102-
if command -v strip &> /dev/null && [ "${os}" != "darwin" ]; then
103-
strip bin/node 2>/dev/null || true
113+
if [ "${os}" = "win32" ]; then
114+
# Windows cleanup
115+
rm -rf node_modules/npm 2>/dev/null || true
116+
rm -rf node_modules/corepack 2>/dev/null || true
117+
rm -f npm npm.cmd npx npx.cmd corepack corepack.cmd 2>/dev/null || true
118+
rm -f *.md LICENSE 2>/dev/null || true
119+
else
120+
# Unix cleanup
121+
rm -rf lib/node_modules/npm 2>/dev/null || true
122+
rm -rf lib/node_modules/corepack 2>/dev/null || true
123+
rm -f bin/npm bin/npx bin/corepack 2>/dev/null || true
124+
rm -rf share/doc share/man share/systemtap include 2>/dev/null || true
125+
rm -f README.md CHANGELOG.md LICENSE *.md 2>/dev/null || true
126+
127+
if command -v strip &> /dev/null && [ "${os}" != "darwin" ]; then
128+
strip bin/node 2>/dev/null || true
129+
fi
104130
fi
105131

106132
cd ../../..
@@ -177,8 +203,10 @@ build_platform() {
177203
if [ "${os}" = "win32" ]; then
178204
cat > "output/${platform}/start.bat" << 'EOF'
179205
@echo off
206+
REM Pyright LSP WebSocket Bridge (Pyright only - no Ruff bundled)
207+
REM Usage: start.bat --port <PORT> --bot-root <BOT_ROOT> --jesse-root <JESSE_ROOT>
208+
180209
set DIR=%~dp0
181-
set RUFF_PATH=%DIR%bin\ruff.exe
182210
"%DIR%node\node.exe" "%DIR%bundle.js" %*
183211
EOF
184212
echo "✓ Created start.bat"
@@ -221,6 +249,7 @@ EOF
221249
# Main script
222250
echo "╔════════════════════════════════════════════════════════╗"
223251
echo "║ Building Pyright LSP with Ruff Support ║"
252+
echo "║ (Ruff bundled for Linux/macOS only) ║"
224253
echo "╚════════════════════════════════════════════════════════╝"
225254
echo ""
226255

@@ -232,8 +261,9 @@ echo ""
232261

233262
# Build for specified platforms or all
234263
if [ $# -eq 0 ]; then
235-
# Build for Linux and macOS by default
236-
PLATFORMS=("linux:x64" "darwin:x64" "darwin:arm64")
264+
# Build for Linux, macOS, and Windows by default
265+
# Note: Ruff is only bundled for Linux and macOS
266+
PLATFORMS=("linux:x64" "darwin:x64" "darwin:arm64" "win32:x64")
237267
else
238268
PLATFORMS=("$@")
239269
fi

0 commit comments

Comments
 (0)