Implementation:Google deepmind Mujoco WASM Bindings Template
| Knowledge Sources | |
|---|---|
| Domains | WebAssembly, Code Generation, Template |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Provides the C++ template file used as the base for generating the WASM Embind bindings, containing hand-written binding code and insertion points for generated code.
Description
bindings.cc (in the templates directory) serves as the skeleton for the auto-generated bindings file. It contains the same Emscripten includes, namespace setup, and MJMODEL_ACCESSORS macro definitions as the generated output, but with placeholder sections where the code generator inserts auto-generated struct wrappers, function wrappers, and enum bindings. The template includes hand-written utility code such as the accessor macros for all MuJoCo object types, custom Embind value type declarations, and any manually maintained binding logic that cannot be auto-generated.
Usage
Used as the input template by the WASM code generation pipeline, which reads this file, inserts generated code at marked locations, and produces the final bindings.cc in the generated directory.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: wasm/codegen/templates/bindings.cc
- Lines: 1-925
Key Functions
namespace mujoco::wasm {
EMSCRIPTEN_DECLARE_VAL_TYPE(NumberOrString);
EMSCRIPTEN_DECLARE_VAL_TYPE(NumberArray);
EMSCRIPTEN_DECLARE_VAL_TYPE(String);
EMSCRIPTEN_DECLARE_VAL_TYPE(StringOrNull);
#define MJMODEL_ACCESSORS \
X_ACCESSOR(ACTUATOR, Actuator, mjOBJ_ACTUATOR, actuator, nu) \
// ... template for all object types
// Insertion points for generated struct/function/enum code
}
Import
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <mujoco/mujoco.h>
#include "wasm/unpack.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Template file | C++ source | Yes | This file serves as the template skeleton for code generation |
Outputs
| Name | Type | Description |
|---|---|---|
| Generated bindings.cc | C++ source | Final auto-generated file with all binding code inserted |