Skip to main content
QuickJS-ng supports cross-compilation to various target platforms. This guide covers the configuration and best practices for cross-compiling the library and tools.

Overview

Cross-compilation is the process of building QuickJS-ng on one platform (the host) to run on a different platform (the target). This is commonly used for:
  • Building for embedded systems
  • Creating ARM binaries on x86 machines
  • Compiling for mobile platforms (iOS, Android)
  • WebAssembly builds
  • Windows builds from Linux

Build System Support

Meson

Recommended for cross-compilation with excellent toolchain support and automatic handling of native builds

CMake

Supported via toolchain files, requires manual configuration of cross-compilation settings

Meson Cross-Compilation

Meson provides the best cross-compilation experience with automatic handling of native vs. target builds.

Native vs. Target Builds

When cross-compiling, Meson automatically builds two versions of certain tools:
  • Native tools: Built for the host machine (e.g., qjsc to compile JavaScript to bytecode)
  • Target binaries: Built for the target platform (e.g., qjs runtime for ARM)
This is necessary because the bytecode compiler (qjsc) needs to run on the build machine during compilation.

Cross-Compilation File

Create a cross-compilation file describing your target platform:

Building with Cross-Compilation

How Meson Handles Native Builds

When cross-compiling, Meson automatically:
  1. Detects that a native qjsc is needed to compile JavaScript files
  2. Builds a native version of qjsc and qjs for the host machine
  3. Uses the native tools during the build process
  4. Builds the target binaries for the cross-compilation target
From meson.build:342-401:

CMake Cross-Compilation

Toolchain Files

CMake uses toolchain files for cross-compilation:

Building with Toolchain File

When cross-compiling with CMake, you may need to build a native version of qjsc separately if you’re building from source (not using pre-generated files).

Platform-Specific Cross-Compilation

Android (NDK)

QuickJS-ng supports Android NDK 26.0.10792818 or later.

iOS

iOS cross-compilation is typically done on macOS using Xcode toolchains.
CLI tools (qjs, qjsc) are not installed for iOS, tvOS, or watchOS builds. Only the library is built.

WebAssembly (WASI)

WASI is the WebAssembly System Interface standard.

Emscripten

Emscripten compiles C/C++ to WebAssembly for web browsers.

MinGW (Windows on Linux)

MinGW builds automatically link statically with libgcc when QJS_BUILD_CLI_STATIC is enabled.

Common Issues and Solutions

Issue: qjsc Not Found During Cross-Compilation

Problem: Native qjsc is needed to compile JavaScript files during build. Solution:
Meson handles this automatically. No action needed.

Issue: Thread Library Not Found

Problem: Cross-compilation toolchain doesn’t provide pthread library. Solution: WASI builds automatically skip thread library:

Issue: Module Loading on Windows

Problem: Windows cannot resolve symbols at runtime like Unix systems. Solution: QuickJS-ng automatically links modules to the main library on Windows:

Issue: Static vs. Shared Libraries

Problem: Binary modules with static qjs on Windows can cause runtime errors. Solution: Use shared library builds on Windows when loading binary modules:

Testing Cross-Compiled Binaries

Using QEMU

Test ARM binaries on x86 using QEMU:

Using Wine

Test Windows binaries on Linux:

Using wasmtime

Test WASI binaries:

Advanced Configuration

Custom Sysroot

Specify a custom sysroot for cross-compilation:

Cross-Compiling with Dependencies

When using mimalloc or other dependencies:

Multi-Architecture Builds

Build for multiple architectures:

Best Practices

  1. Use Meson for cross-compilation - Better automatic handling of native vs. target builds
  2. Test early and often - Use emulators (QEMU, Wine) to test cross-compiled binaries
  3. Static linking for distribution - Use static builds when distributing to avoid dependency issues
  4. Verify toolchain - Ensure cross-compilation toolchain matches target platform exactly
  5. Check platform features - Some platforms have limited features (no threads on WASI)
  6. Use shared libs carefully - Static libraries are safer for cross-compilation

Toolchain Installation

Ubuntu/Debian

macOS