---
title: "Cross-Compilation"
description: "Build binaries for a different platform than your build machine."
---

> Documentation Index
> Fetch the complete documentation index at: https://ramonmalcolm10.github.io/next-bun-compile/llms.txt
> Use this file to discover all available pages before exploring further.

# Cross-Compilation

Set `NBC_TARGET` when building to cross-compile for a different
platform:

### Linux x86_64

```bash
NBC_TARGET=bun-linux-x64 next build
```
### Linux ARM64

```bash
NBC_TARGET=bun-linux-arm64 next build
```
### macOS Apple Silicon

```bash
NBC_TARGET=bun-darwin-arm64 next build
```
### macOS Intel

```bash
NBC_TARGET=bun-darwin-x64 next build
```
### Windows

```bash
NBC_TARGET=bun-windows-x64 next build
```

You can wire this into the build script:

```json
{
  "scripts": {
"build:linux": "next build && NBC_TARGET=bun-linux-x64 next build",
"build:mac": "next build && NBC_TARGET=bun-darwin-arm64 next build"
  }
}
```

See the [Bun cross-compilation docs](https://bun.sh/docs/bundler/executables#cross-compile)
for the complete target list and caveats.

## Native dependencies + cross-compile

If your app uses native deps like `sharp`, the binary embeds the
native bindings that were installed for your **build platform**.
Cross-compiling to a different OS/arch without re-installing the
deps for that platform means those bindings won't load at runtime.

**The reliable approach.** Build inside a container matching your
deploy platform:

```bash
docker run --rm -v "$PWD":/app -w /app oven/bun:1.3.14 bash -c "
  bun install &&
  bun run build
"
```

Or build in CI on a Linux runner if you're deploying to Linux —
that's what most setups end up doing.

Source: https://ramonmalcolm10.github.io/next-bun-compile/guides/cross-compilation/index.mdx
