Skip to main content
The prepare command builds production-ready, optimized binaries for specific platforms. Unlike fire, which is designed for development, prepare creates fully optimized builds for distribution.

Usage

fern prepare <platform>

Arguments

platform
string
required
Target platform: web or linux

Examples

Build for Web

fern prepare web
Building for Web
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Found Fern project at: /home/user/my_app
Found Fern source for web build at: ~/.fern/src/cpp
Using cached Fern web library
Compiling with Emscripten...

Web build successful!
Output: web/build/index.html

Files generated:
 web/build/index.html
 web/build/index.js
 web/build/index.wasm

To serve locally:
  cd web/build
  python3 -m http.server 8000
  Open: http://localhost:8000/index.html

Build for Linux

fern prepare linux
Building for Linux
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Found Fern project at: /home/user/my_app
Compiling for Linux...

Linux build successful!
Output: linux/build/my_app
Size: 423.2 KB

To run:
  linux/build/my_app

To distribute:
  cp linux/build/my_app /path/to/distribution/

Platforms

Web Platform

Production web builds with maximum optimization:
  • Compiler: Emscripten (emcc)
  • Optimization: -O3 (maximum)
  • Output: web/build/index.html, index.js, index.wasm
  • WASM Features: WebGL2, memory growth enabled
  • Custom Template: Uses web/template.html if present
Build artifacts are ready for deployment to any static web host.

Linux Platform

Optimized native Linux binaries:
  • Compiler: g++
  • Optimization: -O3 -DNDEBUG
  • Output: linux/build/<project_name>
  • Permissions: Automatically set to executable (755)
  • Dependencies: Linked statically where possible
Binary is ready for distribution on Linux systems.

Build Comparison

Featurefern firefern prepare
PurposeDevelopmentProduction
Optimization-O2 (debug)-O3 (release)
Build TimeFastSlower
Binary SizeLargerSmaller
PerformanceGoodBest
Output Directorybuild/<platform>/build/

Project Structure Requirements

To use prepare, your project must have:
my_app/
├── lib/
│   └── main.cpp       # Required: Entry point
├── fern.yaml          # Required: Configuration
└── web/               # Optional: Platform directory
    └── template.html  # Optional: Custom HTML template

Output Structure

Web Build

web/build/
├── index.html         # Entry point
├── index.js           # JavaScript loader
└── index.wasm         # WebAssembly binary

Linux Build

linux/build/
└── my_app             # Executable binary

Deployment

Deploy Web Build

1

Build for web

fern prepare web
2

Test locally

cd web/build
python3 -m http.server 8000
# Visit http://localhost:8000/index.html
3

Deploy to hosting

Upload web/build/ contents to:
  • Netlify
  • Vercel
  • GitHub Pages
  • Any static host

Deploy Linux Build

1

Build for Linux

fern prepare linux
2

Test locally

./linux/build/my_app
3

Create distribution package

mkdir -p dist
cp linux/build/my_app dist/
cp -r assets dist/  # If you have assets
tar czf my_app-linux.tar.gz dist/

Optimization Levels

Debug (Development)

Used by fern fire:
  • Optimization: -O2
  • Debug symbols: Included
  • Assertions: Enabled
  • Build time: Fast
  • File size: Large

Release (Production)

Used by fern prepare:
  • Optimization: -O3
  • Debug symbols: Stripped
  • Assertions: Disabled (-DNDEBUG)
  • Build time: Slower
  • File size: Minimal

Web Build Details

Emscripten Flags

Production web builds use:
-std=c++17          # C++17 standard
-O3                 # Maximum optimization
-s WASM=1           # WebAssembly output
-s ALLOW_MEMORY_GROWTH=1
-s USE_WEBGL2=1
-s EXPORTED_FUNCTIONS=['_main']
-s EXPORTED_RUNTIME_METHODS=['ccall','cwrap']

Custom Templates

To customize the HTML wrapper:
  1. Create web/template.html in your project
  2. Use {{{ SCRIPT }}} placeholder for the generated code
  3. Run fern prepare web
Example template:
<!doctype html>
<html>
<head>
    <title>My App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body { 
            margin: 0; 
            background: #000; 
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        canvas { 
            max-width: 100%; 
            max-height: 100%; 
        }
    </style>
</head>
<body>
    <canvas id="canvas"></canvas>
    <script>
        var Module = { canvas: document.getElementById('canvas') };
    </script>
    {{{ SCRIPT }}}
</body>
</html>

Linux Build Details

Compiler Flags

Production Linux builds use:
-std=c++17          # C++17 standard
-O3                 # Maximum optimization
-DNDEBUG            # Disable assertions
-I/usr/local/include # Fern headers
-L/usr/local/lib    # Fern libraries
-lfern              # Link Fern library
-lX11 -lXext        # X11 libraries
-lfontconfig        # Font support
-lfreetype          # Font rendering

Common Issues

fern prepare web
# Error: Not in a Fern project directory
Solution: Navigate to a Fern project root (directory with fern.yaml).
fern prepare linux
# Error: No main.cpp found in lib directory
Solution: Ensure lib/main.cpp exists in your project.
fern prepare web
# Error: Emscripten not found
Solution: Install Emscripten:
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
fern prepare linux
# Error: Fern C++ library is not installed globally
Solution: Install Fern:
cd /path/to/fern
./install.sh

Performance Benchmarks

Typical build times and sizes for a medium-sized Fern project:
PlatformBuild TimeBinary SizeOptimized
Linux (debug)3s850 KBNo
Linux (release)8s420 KBYes
Web (debug)10s1.2 MBNo
Web (release)25s650 KBYes

Build docs developers (and LLMs) love