| Crates.io | dear-imgui-sys |
| lib.rs | dear-imgui-sys |
| version | 0.8.0 |
| created_at | 2025-09-13 17:16:34.156647+00 |
| updated_at | 2026-01-02 17:50:36.895744+00 |
| description | Low-level FFI bindings to Dear ImGui v1.92.5 (docking branch) via cimgui (C API) |
| homepage | https://github.com/Latias94/dear-imgui-rs |
| repository | https://github.com/Latias94/dear-imgui-rs |
| max_upload_size | |
| id | 1837934 |
| size | 5,846,579 |
Low-level Rust bindings for Dear ImGui via cimgui (C API) + bindgen.
This crate provides unsafe Rust bindings to Dear ImGui v1.92.5 (docking branch) using the cimgui C API. By using cimgui's C interface instead of directly binding to the C++ API, we completely avoid C++ ABI compatibility issues while maintaining full access to Dear ImGui's functionality.
This crate supports multiple build strategies to fit different development workflows:
The fastest way to get started. Use prebuilt static libraries instead of compiling from source:
# Option A: Point to a local directory containing the static library
export IMGUI_SYS_LIB_DIR=/path/to/lib/dir # Contains dear_imgui.lib (Windows) or libdear_imgui.a (Unix)
# Option B: Download from a direct URL
export IMGUI_SYS_PREBUILT_URL=https://example.com/dear_imgui.lib
# Option C: Enable automatic download from GitHub releases
cargo build --features prebuilt
# or
export IMGUI_SYS_USE_PREBUILT=1
Compile Dear ImGui and cimgui from the vendored source code:
# Windows (automatically uses CMake if available)
cargo build -p dear-imgui-sys
# Force CMake on other platforms
export IMGUI_SYS_USE_CMAKE=1
cargo build -p dear-imgui-sys
# Use cc crate (default on non-Windows)
cargo build -p dear-imgui-sys
Requirements by platform:
build-essential, pkg-config, llvm-dev (for bindgen)
sudo apt-get install build-essential pkg-config llvm-dev clang
xcode-select --install
Skip C/C++ compilation for faster Rust-only iteration:
export IMGUI_SYS_SKIP_CC=1
cargo build -p dear-imgui-sys
This uses pregenerated bindings and skips native compilation, useful when working on higher-level Rust code.
This crate supports offline builds and docs.rs compilation through pregenerated bindings:
When building on docs.rs (DOCS_RS=1), the build script:
src/bindings_pregenerated.rs if availableTo refresh the pregenerated bindings file:
# Generate new bindings without C++ compilation
IMGUI_SYS_SKIP_CC=1 cargo build -p dear-imgui-sys
# Copy generated bindings to source tree
cp target/debug/build/dear-imgui-sys-*/out/bindings.rs dear-imgui-sys/src/bindings_pregenerated.rs
Or use the provided update script:
python3 tools/update_submodule_and_bindings.py --branch docking_inter
WebAssembly support for Dear ImGui in this workspace follows the same import-style design used by the high-level dear-imgui-rs crate:
imgui-sys-v0 that provides the cimgui (C API) implementation.wasm32-unknown-unknown and uses wasm-bindgen.imgui-sys-v0) is built once (currently via Emscripten) and contains Dear ImGui + cimgui and, optionally, selected extensions.The dear-imgui-sys crate participates in this flow via its wasm feature, but end users typically interact with it indirectly through:
dear-imgui-rs with the wasm feature enabled.xtask commands (wasm-bindgen, web-demo, build-cimgui-provider) that wire the main module and provider together.For a complete, up-to-date guide (including required tools, commands, and troubleshooting), see:
docs/WASM.md in this repository.examples-wasm crate (examples-wasm/dear-imgui-web-demo), which demonstrates the web demo setup.This is a low-level sys crate providing unsafe FFI bindings. Most users should use the higher-level dear-imgui-rs crate instead, which provides safe Rust wrappers.
[dependencies]
dear-imgui-sys = "0.7"
# Enable features as needed
dear-imgui-sys = { version = "0.7", features = ["freetype", "wasm"] }
use dear_imgui_sys::*;
unsafe {
let ctx = igCreateContext(std::ptr::null_mut());
igSetCurrentContext(ctx);
// Configure ImGui...
let io = igGetIO();
(*io).DisplaySize = ImVec2 { x: 800.0, y: 600.0 };
// Main loop
igNewFrame();
igText(b"Hello from Dear ImGui!\0".as_ptr() as *const std::os::raw::c_char);
igRender();
// Clean up
igDestroyContext(ctx);
}
This crate uses cimgui as the C API layer:
ig* naming convention (e.g., igText, igButton)Control build behavior with these environment variables:
| Variable | Description |
|---|---|
IMGUI_SYS_LIB_DIR |
Path to directory containing prebuilt static library |
IMGUI_SYS_PREBUILT_URL |
Direct URL to download prebuilt library |
IMGUI_SYS_USE_PREBUILT |
Enable automatic download from GitHub releases (1) |
IMGUI_SYS_USE_CMAKE |
Force CMake build instead of cc crate (1) |
IMGUI_SYS_SKIP_CC |
Skip C/C++ compilation, use pregenerated bindings only (1) |
IMGUI_SYS_FORCE_BUILD |
Force build from source, ignore prebuilt options (1) |
This crate is part of the dear-imgui-rs ecosystem:
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.