Skip to main content
QAROS Rust API Dev (main) · versions: Dev (main) · Developer Guide

qaros_sys/
lib.rs

1//! Raw bindings to the QAROS streaming C API (`qar_streaming.h`).
2//!
3//! The header's public `qar_*` functions are `static inline` wrappers that
4//! forward to the exported `qar_impl_*` symbols, so these bindings target the
5//! `qar_impl_*` symbols directly. All of them are reached through a
6//! [`QarApi`] function table, which comes from one of two loading modes:
7//!
8//! - [`QarApi::load_default`] (default): finds `qar-streaming-c.dll` with the runtime lookup
9//!   every QAROS binding follows (already loaded, beside the binding, the runtime of the QAROS
10//!   instance `QAR_INSTANCE` names, the installed QAROS, `PATH`), opens it at runtime and
11//!   resolves every symbol up front.
12//!   [`QarApi::load`] opens one given file instead. A missing symbol is a [`LoadError`] listing
13//!   all missing names, instead of the header's `abort()` at the first call.
14//! - `QarApi::linked` (feature `link`): the symbols are declared
15//!   `extern "C"` and resolved by the import library `qar-streaming-c.lib`;
16//!   the DLL must be present at process start.
17//!
18//! The header's `qar_*_default()` initializers are also `static inline` and
19//! absent from the binary; [`defaults`] ports them, including the
20//! `QarStructureHeader` stamping every init structure needs.
21//!
22//! Bindings are generated per target by `cargo xtask bindgen` and committed:
23//! `x86_64-pc-windows-msvc` (the runtime's platform, with the D3D11 types as
24//! opaque structs), `x86_64-unknown-linux-gnu` (`libqar-streaming-c.so`), and
25//! one development target without a runtime, for building and testing against
26//! `qaros-stub` (`aarch64-apple-darwin`, used on every macOS host), which carries the D3D11
27//! types and functions too so that the stub can emulate the D3D11 render sender.
28//! `cargo xtask bindgen <target>` and a
29//! `cfg` entry below add another target.
30
31#![allow(
32    non_camel_case_types,
33    non_snake_case,
34    non_upper_case_globals,
35    clippy::doc_markdown,
36    clippy::doc_lazy_continuation,
37    clippy::pub_underscore_fields,
38    clippy::unreadable_literal,
39    clippy::too_many_arguments,
40    clippy::struct_field_names,
41    clippy::missing_safety_doc,
42    rustdoc::invalid_html_tags
43)]
44
45#[cfg(all(target_os = "windows", target_arch = "x86_64", target_env = "msvc"))]
46#[path = "generated/x86_64_pc_windows_msvc/types.rs"]
47mod types;
48#[cfg(all(target_os = "windows", target_arch = "x86_64", target_env = "msvc"))]
49#[macro_use]
50#[path = "generated/x86_64_pc_windows_msvc/functions.rs"]
51mod function_list;
52
53#[cfg(all(target_os = "linux", target_arch = "x86_64", target_env = "gnu"))]
54#[path = "generated/x86_64_unknown_linux_gnu/types.rs"]
55mod types;
56#[cfg(all(target_os = "linux", target_arch = "x86_64", target_env = "gnu"))]
57#[macro_use]
58#[path = "generated/x86_64_unknown_linux_gnu/functions.rs"]
59mod function_list;
60
61#[cfg(target_os = "macos")]
62#[path = "generated/aarch64_apple_darwin/types.rs"]
63mod types;
64#[cfg(target_os = "macos")]
65#[macro_use]
66#[path = "generated/aarch64_apple_darwin/functions.rs"]
67mod function_list;
68
69#[cfg(not(any(
70    all(target_os = "windows", target_arch = "x86_64", target_env = "msvc"),
71    all(target_os = "linux", target_arch = "x86_64", target_env = "gnu"),
72    target_os = "macos"
73)))]
74compile_error!(
75    "qaros-sys has no committed bindings for this target; run `cargo xtask bindgen <target>` and add it to src/lib.rs"
76);
77
78pub mod defaults;
79mod loader;
80mod lookup;
81mod platform;
82
83pub use loader::{LoadError, QarApi, SYMBOL_NAMES, open_package_library};
84pub use lookup::{
85    DEFAULT_INSTANCE_NAME, INSTALL_FOLDER_VALUE, INSTALL_REGISTRY_KEY, INSTANCE_NAME_MAX_LENGTH,
86    INSTANCE_RUNTIME_FOLDER_VALUE, INSTANCE_VARIABLE, INSTANCES_REGISTRY_KEY, LookupAttempt,
87    LookupOutcome, LookupStep, is_valid_instance_name,
88};
89pub use platform::{installed_bin_folder, instance_runtime_folder, requested_instance};
90pub use types::*;
91
92/// File name of the C API library inside the binary package's `bin/`.
93pub const LIBRARY_FILE_NAME: &str = if cfg!(target_os = "windows") {
94    "qar-streaming-c.dll"
95} else if cfg!(target_os = "macos") {
96    "libqar-streaming-c.dylib"
97} else {
98    "libqar-streaming-c.so"
99};