# Building Precompiled Binaries

This package supports precompiled binaries to avoid requiring `node-gyp` on client machines.

## Directory Structure

Precompiled binaries are stored in:
```
prebuilds/
  ├── win32-x64/
  │   └── HypertubeNodejsRuntimeAddon.node
  ├── win32-arm64/
  │   └── HypertubeNodejsRuntimeAddon.node
  ├── linux-x64/
  │   └── HypertubeNodejsRuntimeAddon.node
  ├── linux-arm64/
  │   └── HypertubeNodejsRuntimeAddon.node
  ├── darwin-x64/
  │   └── HypertubeNodejsRuntimeAddon.node
  └── darwin-arm64/
      └── HypertubeNodejsRuntimeAddon.node
```

## Building for Azure Pipeline

### Option 1: Using the Azure Pipeline YAML

1. Use the azure-pipelines-nodejs-binaries.yml pipeline
2. The pipeline will build for all platforms in parallel
3. Artifacts will be published for each platform
4. Combine artifacts in a final job to create a complete package

### Option 2: Manual Build Scripts

#### Windows (PowerShell)
```powershell
# Build for Windows x64
npm run build:win32
npm run package:prebuild win32 x64

# Build for Windows ARM64 (if supported)
npm run build:win32:arm64
npm run package:prebuild win32 arm64
```

#### Linux (Bash)
```bash
# Build for Linux x64
npm run build:linux
npm run package:prebuild linux x64

# Build for Linux ARM64
npm run build:linux:arm64
npm run package:prebuild linux arm64
```

#### macOS (Bash)
```bash
# Build for macOS x64
npm run build:darwin
npm run package:prebuild darwin x64

# Build for macOS ARM64 (Apple Silicon)
npm run build:darwin:arm64
npm run package:prebuild darwin arm64
```

## Client Installation

When clients install the package:

1. **If precompiled binary exists**: The install script will detect it and skip building
2. **If no precompiled binary**: The install script will attempt to build using `node-gyp` (if available)
3. **If node-gyp is not available**: Installation will fail with clear error message

### For Production

To ensure clients don't need `node-gyp`:
1. Precompile binaries for all target platforms
2. Include the `prebuilds/` directory in your npm package
3. Clients will automatically use the precompiled binary for their platform

## Testing Precompiled Binaries

To test that precompiled binaries work:

1. Build and package for your platform:
   ```bash
   npm run prebuild
   npm run package:prebuild
   ```

2. Remove the build directory:
   ```bash
   rm -rf build/
   ```

3. Test loading:
   ```bash
   node -e "console.log(require('./index.js'))"
   ```

The module should load successfully from the `prebuilds/` directory.

