Skip to main content
Compile JavaScript or TypeScript to standalone native executables using Porffor’s 2c (Wasm → C) compiler.
2c is Porffor’s experimental WebAssembly to C compiler. While functional, it’s still in development.

Usage

porf native [flags] input.js output[.exe]

Examples

porf native script.js myapp
./myapp

Arguments

input.js
string
required
JavaScript or TypeScript source file
output
string
required
Output executable file path (.exe on Windows)

Compiler Options

--compiler
string
default:"clang"
C compiler to use: clang, gcc, or zig
porf native --compiler=gcc script.js output
porf native --compiler=zig script.js output
  • clang: Default, good optimization and performance
  • gcc: Alternative, widely available
  • zig: Experimental, cross-compilation support
--cO
string
default:"Ofast"
C compiler optimization level: Ofast, O3, O2, O1, or O0
porf native --cO=O3 script.js output
porf native --cO=O0 script.js debug_output
  • Ofast: Maximum optimization (default), may break strict compliance
  • O3: Aggressive optimization
  • O2: Moderate optimization, good balance
  • O1: Basic optimization
  • O0: No C compiler optimization, fastest compilation

JavaScript Compilation Flags

All standard optimization flags apply:
-On
flag
Porffor optimization level (0-3)
porf native -O3 --cO=Ofast script.js output
-d
flag
Debug mode - disables stripping, includes debug symbols
porf native -d script.js debug_output
--parse-types
flag
Enable TypeScript parsing
--opt-types
flag
Optimize using type annotations

Compilation Process

The native compilation involves multiple stages:
  1. JavaScript → Wasm: Porffor compiles JS to WebAssembly
  2. Wasm → C: 2c translates Wasm bytecode to C source
  3. C → Native: C compiler produces native executable
  4. Strip: Symbols removed (unless -d flag used)
$ porf native script.js myapp
compiled in 203.45ms

Output Binary Details

By default, output binaries are:
  • Fully optimized with -Ofast
  • Stripped of debug symbols
  • Statically linked where possible
  • Platform-specific native code
porf native -O3 --cO=Ofast script.js myapp
# Smallest, fastest binary

Platform Support

# Default clang
porf native script.js myapp

# Using gcc
porf native --compiler=gcc script.js myapp

# Using zig for cross-compilation
porf native --compiler=zig script.js myapp

Performance Tuning

Maximum Performance

porf native -O3 --cO=Ofast --opt-types --parse-types script.ts myapp
Combines:
  • JavaScript optimizations (-O3)
  • Aggressive C optimization (--cO=Ofast)
  • Type-based optimization (--opt-types)

Debug Performance

porf native -d -O0 --cO=O0 script.js myapp_debug
Use for:
  • Debugging crashes
  • Profiling with external tools
  • Understanding generated code

Balanced Build

porf native -O2 --cO=O2 script.js myapp
Good for:
  • Development iteration
  • Reasonable performance
  • Faster compile times

Compiler-Specific Features

porf native --compiler=clang script.js myapp
  • Modern optimization techniques
  • Good error messages
  • Fast compilation
  • Recommended for most use cases

Binary Size Comparison

porf native -O3 --cO=Ofast script.js myapp
strip myapp
# Already stripped by default
Binaries include no runtime dependencies - Porffor has zero constant runtime/preluded code.

Debugging Native Binaries

# Compile with debug info
porf native -d script.js myapp_debug

# Use with debugger
gdb ./myapp_debug
lldb ./myapp_debug

Environment Variables

CC
string
Override C compiler (alternative to --compiler)
CC=gcc porf native script.js myapp
CC=clang-15 porf native script.js myapp

Troubleshooting

Compiler Not Found

# Install clang
sudo apt install clang      # Debian/Ubuntu
brew install llvm           # macOS

# Or use gcc
porf native --compiler=gcc script.js myapp

Runtime Errors

# Build with debug info
porf native -d script.js myapp_debug

# Run to see detailed errors
./myapp_debug

Large Binary Size

# Use maximum optimization
porf native -O3 --cO=Ofast script.js myapp

# Already stripped by default
# Manual strip if needed:
strip myapp

Slow Compilation

# Reduce Porffor optimization
porf native -O1 --cO=O2 script.js myapp

# Or disable all optimization for testing
porf native -O0 --cO=O0 script.js myapp

Cross-Compilation

While Porffor itself is platform-independent, native compilation produces platform-specific binaries.
# Using zig for cross-compilation (experimental)
porf native --compiler=zig script.js myapp

Comparison with Other Approaches

FeatureNativeWasmRun
Startup TimeFastestFastFast
Binary SizeSmallSmallerN/A
PerformanceBestExcellentVery Good
PortabilityPlatform-specificCross-platformRequires Porffor
DistributionSingle binaryRequires runtimeSource code

Next Steps

C Output

View generated C source code

Profile

Optimize before compiling

Lambda

Deploy as serverless function

Run Command

Test before compiling

Build docs developers (and LLMs) love