This commit is contained in:
Chris Tate
2026-01-11 03:23:39 -06:00
parent 924eb85e82
commit 6b3bae760b
198 changed files with 411 additions and 521 deletions
+68
View File
@@ -0,0 +1,68 @@
#!/bin/bash
set -e
# Build agent-browser for all platforms using Docker
# Usage: ./scripts/build-all-platforms.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
OUTPUT_DIR="$PROJECT_ROOT/bin"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${YELLOW}Building agent-browser for all platforms...${NC}"
echo ""
# Ensure output directory exists
mkdir -p "$OUTPUT_DIR"
# Build the Docker image if needed
echo -e "${YELLOW}Building Docker cross-compilation image...${NC}"
docker build -t agent-browser-builder -f "$PROJECT_ROOT/docker/Dockerfile.build" "$PROJECT_ROOT"
# Function to build for a target
build_target() {
local target=$1
local output_name=$2
echo -e "${YELLOW}Building for ${target}...${NC}"
docker run --rm \
-v "$PROJECT_ROOT/cli:/build" \
-v "$OUTPUT_DIR:/output" \
agent-browser-builder \
-c "cargo zigbuild --release --target ${target} && cp /build/target/${target}/release/agent-browser* /output/${output_name} && chmod +x /output/${output_name} 2>/dev/null || true"
if [ -f "$OUTPUT_DIR/$output_name" ]; then
echo -e "${GREEN}✓ Built ${output_name}${NC}"
else
echo -e "${RED}✗ Failed to build ${output_name}${NC}"
return 1
fi
}
# Build for each platform
# Linux x64
build_target "x86_64-unknown-linux-gnu" "agent-browser-linux-x64"
# Linux ARM64
build_target "aarch64-unknown-linux-gnu" "agent-browser-linux-arm64"
# Windows x64
build_target "x86_64-pc-windows-gnu" "agent-browser-win32-x64.exe"
# macOS x64 (via zig for cross-compilation)
build_target "x86_64-apple-darwin" "agent-browser-darwin-x64"
# macOS ARM64 (via zig for cross-compilation)
build_target "aarch64-apple-darwin" "agent-browser-darwin-arm64"
echo ""
echo -e "${GREEN}Build complete!${NC}"
echo ""
echo "Binaries are in: $OUTPUT_DIR"
ls -la "$OUTPUT_DIR"/agent-browser-*
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env node
/**
* Copies the compiled Rust binary to bin/ with platform-specific naming
*/
import { copyFileSync, existsSync, mkdirSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { platform, arch } from 'os';
const __dirname = dirname(fileURLToPath(import.meta.url));
const projectRoot = join(__dirname, '..');
const sourcePath = join(projectRoot, 'cli/target/release/agent-browser');
const binDir = join(projectRoot, 'bin');
// Determine platform suffix
const platformKey = `${platform()}-${arch()}`;
const ext = platform() === 'win32' ? '.exe' : '';
const targetName = `agent-browser-${platformKey}${ext}`;
const targetPath = join(binDir, targetName);
if (!existsSync(sourcePath)) {
console.error(`Error: Native binary not found at ${sourcePath}`);
console.error('Run "cargo build --release --manifest-path cli/Cargo.toml" first');
process.exit(1);
}
if (!existsSync(binDir)) {
mkdirSync(binDir, { recursive: true });
}
copyFileSync(sourcePath, targetPath);
console.log(`✓ Copied native binary to ${targetPath}`);
+112 -14
View File
@@ -1,17 +1,115 @@
#!/usr/bin/env node
const message = `
╔═══════════════════════════════════════════════════════════════════════════╗
║ agent-browser was installed successfully! ║
║ Please run the following command to download browser binaries: ║
║ ║
║ npx agent-browser install ║
║ ║
║ On Linux, include system dependencies with: ║
║ ║
║ npx agent-browser install --with-deps ║
║ ║
╚═══════════════════════════════════════════════════════════════════════════╝
`;
/**
* Postinstall script for agent-browser
*
* Downloads the platform-specific native binary if not present.
*/
console.log(message);
import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { platform, arch } from 'os';
import { get } from 'https';
import { execSync } from 'child_process';
const __dirname = dirname(fileURLToPath(import.meta.url));
const projectRoot = join(__dirname, '..');
const binDir = join(projectRoot, 'bin');
// Platform detection
const platformKey = `${platform()}-${arch()}`;
const ext = platform() === 'win32' ? '.exe' : '';
const binaryName = `agent-browser-${platformKey}${ext}`;
const binaryPath = join(binDir, binaryName);
// Package info
const packageJson = JSON.parse(
(await import('fs')).readFileSync(join(projectRoot, 'package.json'), 'utf8')
);
const version = packageJson.version;
// GitHub release URL
const GITHUB_REPO = 'anthropics/agent-browser'; // Update this to your actual repo
const DOWNLOAD_URL = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
async function downloadFile(url, dest) {
return new Promise((resolve, reject) => {
const file = createWriteStream(dest);
const request = (url) => {
get(url, (response) => {
// Handle redirects
if (response.statusCode === 301 || response.statusCode === 302) {
request(response.headers.location);
return;
}
if (response.statusCode !== 200) {
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
return;
}
response.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
}).on('error', (err) => {
unlinkSync(dest);
reject(err);
});
};
request(url);
});
}
async function main() {
// Check if binary already exists
if (existsSync(binaryPath)) {
console.log(`✓ Native binary already exists: ${binaryName}`);
return;
}
// Ensure bin directory exists
if (!existsSync(binDir)) {
mkdirSync(binDir, { recursive: true });
}
console.log(`Downloading native binary for ${platformKey}...`);
console.log(`URL: ${DOWNLOAD_URL}`);
try {
await downloadFile(DOWNLOAD_URL, binaryPath);
// Make executable on Unix
if (platform() !== 'win32') {
chmodSync(binaryPath, 0o755);
}
console.log(`✓ Downloaded native binary: ${binaryName}`);
} catch (err) {
console.log(`⚠ Could not download native binary: ${err.message}`);
console.log(` The CLI will use Node.js fallback (slightly slower startup)`);
console.log('');
console.log('To build the native binary locally:');
console.log(' 1. Install Rust: https://rustup.rs');
console.log(' 2. Run: npm run build:native');
}
// Reminder about Playwright browsers
console.log('');
console.log('╔═══════════════════════════════════════════════════════════════════════════╗');
console.log('║ To download browser binaries, run: ║');
console.log('║ ║');
console.log('║ npx playwright install chromium ║');
console.log('║ ║');
console.log('║ On Linux, include system dependencies with: ║');
console.log('║ ║');
console.log('║ npx playwright install --with-deps chromium ║');
console.log('║ ║');
console.log('╚═══════════════════════════════════════════════════════════════════════════╝');
}
main().catch(console.error);