mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 13:02:15 +00:00
fix(tui): externalize koffi from bun binary builds
Changed koffi import from top-level to dynamic require in enableWindowsVTInput() and added --external koffi to bun build. This prevents embedding all 18 platform .node files (~74MB) into every compiled binary. For Windows builds, only the win32_x64 koffi.node is shipped alongside the binary. Binary size reduction: darwin-arm64 142MB -> 67MB, archive 43MB -> 28MB.
This commit is contained in:
parent
3a3e37d390
commit
8386a807ff
4 changed files with 26 additions and 3 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Externalized koffi from bun binary builds, reducing archive sizes by ~15MB per platform (e.g. darwin-arm64: 43MB -> 28MB). Koffi's Windows-only `.node` file is now shipped alongside the Windows binary only.
|
||||||
|
|
||||||
## [0.54.0] - 2026-02-19
|
## [0.54.0] - 2026-02-19
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Changed koffi import from top-level to dynamic require in `enableWindowsVTInput()` to prevent bun from embedding all 18 platform `.node` files (~74MB) into every compiled binary. Koffi is only needed on Windows.
|
||||||
|
|
||||||
## [0.54.0] - 2026-02-19
|
## [0.54.0] - 2026-02-19
|
||||||
|
|
||||||
## [0.53.1] - 2026-02-19
|
## [0.53.1] - 2026-02-19
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import koffi from "koffi";
|
|
||||||
import { setKittyProtocolActive } from "./keys.js";
|
import { setKittyProtocolActive } from "./keys.js";
|
||||||
import { StdinBuffer } from "./stdin-buffer.js";
|
import { StdinBuffer } from "./stdin-buffer.js";
|
||||||
|
|
||||||
|
|
@ -174,6 +173,10 @@ export class ProcessTerminal implements Terminal {
|
||||||
private enableWindowsVTInput(): void {
|
private enableWindowsVTInput(): void {
|
||||||
if (process.platform !== "win32") return;
|
if (process.platform !== "win32") return;
|
||||||
try {
|
try {
|
||||||
|
// Dynamic require to avoid bundling koffi's 74MB of cross-platform
|
||||||
|
// native binaries into every compiled binary. Koffi is only needed
|
||||||
|
// on Windows for VT input support.
|
||||||
|
const koffi = require("koffi");
|
||||||
const k32 = koffi.load("kernel32.dll");
|
const k32 = koffi.load("kernel32.dll");
|
||||||
const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)");
|
const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)");
|
||||||
const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)");
|
const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)");
|
||||||
|
|
|
||||||
|
|
@ -102,10 +102,14 @@ fi
|
||||||
|
|
||||||
for platform in "${PLATFORMS[@]}"; do
|
for platform in "${PLATFORMS[@]}"; do
|
||||||
echo "Building for $platform..."
|
echo "Building for $platform..."
|
||||||
|
# Externalize koffi to avoid embedding all 18 platform .node files (~74MB)
|
||||||
|
# into every binary. Koffi is only used on Windows for VT input and the
|
||||||
|
# call site has a try/catch fallback. For Windows builds, we copy the
|
||||||
|
# appropriate .node file alongside the binary below.
|
||||||
if [[ "$platform" == "windows-x64" ]]; then
|
if [[ "$platform" == "windows-x64" ]]; then
|
||||||
bun build --compile --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi.exe
|
bun build --compile --external koffi --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi.exe
|
||||||
else
|
else
|
||||||
bun build --compile --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi
|
bun build --compile --external koffi --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -122,6 +126,14 @@ for platform in "${PLATFORMS[@]}"; do
|
||||||
cp -r dist/core/export-html binaries/$platform/
|
cp -r dist/core/export-html binaries/$platform/
|
||||||
cp -r docs binaries/$platform/
|
cp -r docs binaries/$platform/
|
||||||
cp -r examples binaries/$platform/
|
cp -r examples binaries/$platform/
|
||||||
|
|
||||||
|
# Copy koffi native module for Windows (needed for VT input support)
|
||||||
|
if [[ "$platform" == "windows-x64" ]]; then
|
||||||
|
mkdir -p binaries/$platform/node_modules/koffi/build/koffi/win32_x64
|
||||||
|
cp ../../node_modules/koffi/index.js binaries/$platform/node_modules/koffi/
|
||||||
|
cp ../../node_modules/koffi/package.json binaries/$platform/node_modules/koffi/
|
||||||
|
cp ../../node_modules/koffi/build/koffi/win32_x64/koffi.node binaries/$platform/node_modules/koffi/build/koffi/win32_x64/
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Create archives
|
# Create archives
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue