What Programming Languages Is JSAR Built With? A Deep Dive into the Polyglot Architecture

JSAR is built with four primary languages: Rust for the core engine, C/C++ for native system integration, TypeScript/JavaScript for the Web API surface, and CMake for build orchestration.

The JSAR runtime—developed under the m-creativelab/jsar-runtime repository—is a polyglot 3D rendering engine designed to run both natively and in browsers. Understanding what programming languages JSAR is built with reveals how the project balances memory safety, performance, and cross-platform accessibility.

The Polyglot Stack: Four Languages Powering JSAR

Rust: The Core Engine and Memory-Safe Runtime

Rust forms the foundation of JSAR's architecture. The language handles the low-level graphics pipeline, memory-safe bindings, and the workspace that builds the native runtime.

In Cargo.toml, the workspace definition declares crates such as jsbindings and runtime_apis. The file crates/jsbindings/src/lib.rs exposes Rust functions to other languages via C-ABI, enabling safe interoperability with C++ and JavaScript environments.

Rust's zero-cost abstractions and ownership model make it ideal for real-time graphics where memory safety cannot compromise performance.

C and C++: Native Glue and System Integration

C and C++ provide the native glue code that connects Rust's core engine to system APIs like OpenGL and Vulkan. These languages appear in test harnesses and direct system integrations where stable ABIs are required.

The file tests/runtime.cpp demonstrates how C++ programs link against the Rust-generated library. This test harness validates that compiled binaries behave correctly across Linux, macOS, and Windows by calling exported functions like jsar_initialize().

TypeScript and JavaScript: The Web API Surface

TypeScript and JavaScript implement the high-level Web API surface that developers interact with when running JSAR in browsers or Node.js environments. This layer presents the runtime as a familiar Web API, handling worker infrastructure and network requests.

The lib/ directory contains the TypeScript implementation, including lib/webworkers/worker.ts which defines the WorkerImpl class for spawning rendering workers. Additional files like lib/xhr.ts provide fetch-like wrappers that route requests through the native runtime.

CMake: Orchestrating the Build System

CMake serves as the build scripting language that orchestrates compilation of C/C++ components and their integration with Rust. While not a runtime language, CMake is essential for the polyglot build process.

The CMakeLists.txt file coordinates the compilation of C++ sources and links them against Rust artifacts generated by Cargo. This ensures that native binaries are built consistently across different target platforms.

How JSAR's Languages Interact: A Technical Overview

JSAR's architecture follows a layered approach where each language handles specific concerns:

  1. Rust core manages the rendering engine, memory management, and native bindings.
  2. C/C++ layer provides a stable ABI for system integration and testing.
  3. TypeScript façade exposes Web APIs that run in browsers or Node.js, forwarding calls to the native runtime through WebAssembly or native addons.
  4. Build system uses CMake and Cargo to produce cross-platform binaries.

This polyglot approach enables JSAR to run natively via Rust/C++ binaries while also executing in the browser through compiled WebAssembly and TypeScript APIs.

Working with JSAR: Code Examples by Language

TypeScript: Initializing a Web Worker

When working with JSAR in a browser environment, you interact with the TypeScript API to spawn workers and manage scenes:

import { WorkerImpl } from 'jsar-runtime/lib/webworkers/worker';

const worker = new WorkerImpl({
  baseURI: location.origin,
  requestUrl: '/scripts/scene.js',
});

worker.onmessage = (event) => {
  console.log('JSAR message:', event.data);
};

worker.postMessage({ action: 'loadScene', url: 'scene.glb' });

Source: lib/webworkers/worker.ts

C++: Calling Rust Functions from Native Code

For native applications, C++ code links against the Rust library to bootstrap the runtime:

extern "C" {
    // Function exported by the Rust library
    void jsar_initialize();
}

int main() {
    jsar_initialize();          // bootstrap the runtime
    // ... set up rendering loop, load assets, etc.
    return 0;
}

Source: tests/runtime.cpp

Rust: Building the Core Runtime

To compile the Rust components of JSAR:


# From the repository root

cargo build --release   # compiles the Rust core and generates the native library

Source: Cargo.toml

Key Files and Their Languages

Understanding the repository structure helps identify which language handles specific functionality:

  • Cargo.toml (Rust) — Declares the workspace, dependencies, and builds the core runtime.
  • crates/jsbindings/src/lib.rs (Rust) — Exposes Rust functions to other languages via C-ABI.
  • tests/runtime.cpp (C++) — Validates that the compiled native library works as expected.
  • lib/webworkers/worker.ts (TypeScript) — Implements the high-level worker API used by client code.
  • lib/xhr.ts (TypeScript) — Provides a fetch-like wrapper that routes requests through the runtime.
  • CMakeLists.txt (CMake) — Coordinates the compilation of C/C++ and integration with Rust.
  • package.json (JavaScript metadata) — Defines the npm package, entry points, and build scripts.

Summary

  • JSAR is built with Rust, C/C++, TypeScript/JavaScript, and CMake, each serving distinct architectural roles.
  • Rust powers the core rendering engine and memory-safe bindings in Cargo.toml and crates/jsbindings/src/lib.rs.
  • C/C++ provides native glue code and testing infrastructure in tests/runtime.cpp.
  • TypeScript implements the Web API surface in lib/webworkers/worker.ts and lib/xhr.ts for browser and Node.js environments.
  • CMake orchestrates the polyglot build process via CMakeLists.txt, ensuring cross-platform compatibility.

Frequently Asked Questions

Is JSAR primarily a Rust project?

While Rust forms the core engine and memory management layer, JSAR is fundamentally a polyglot project. The Rust workspace in Cargo.toml handles low-level graphics and bindings, but significant portions of the codebase are TypeScript (Web APIs) and C++ (native testing). Rust is the foundation, not the entirety.

Can I use JSAR without knowing C or C++?

Yes. Most developers interact with JSAR through the TypeScript/JavaScript API exposed in lib/webworkers/worker.ts. The C/C++ layer primarily serves as internal glue and test infrastructure in tests/runtime.cpp. Unless you are modifying the native runtime or building custom native integrations, TypeScript knowledge is sufficient.

How does JSAR achieve cross-platform compatibility?

JSAR uses a combination of Rust's inherent cross-platform capabilities and CMake's build orchestration. The Cargo.toml workspace compiles Rust code to target Linux, macOS, and Windows, while CMakeLists.txt coordinates C/C++ compilation across these platforms. The TypeScript layer (lib/) runs anywhere JavaScript executes, including browsers and Node.js.

What role does WebAssembly play in JSAR's architecture?

While the source analysis emphasizes native compilation, JSAR's TypeScript façade in lib/webworkers/worker.ts is designed to interface with the runtime through WebAssembly or native addons. The Rust core can be compiled to WebAssembly (via the same Cargo.toml workspace) allowing the engine to execute in browsers without native plugins, while the TypeScript API provides the ergonomic wrapper for web developers.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →