onemkl-sys 0.3.0

Raw FFI bindings to the C interface of Intel oneAPI Math Kernel Library (oneMKL).
Documentation
//! Raw FFI bindings to the C interface of Intel oneAPI Math Kernel Library
//! (oneMKL).
//!
//! These bindings are auto-generated by `bindgen` from the official `mkl.h`
//! umbrella header, plus any opt-in MPI-dependent headers (`mkl_blacs.h`,
//! `mkl_pblas.h`, `mkl_scalapack.h`, `mkl_cluster_sparse_solver.h`,
//! `mkl_cdft.h`) selected via Cargo features.
//!
//! # Safety
//!
//! Every item exported from this crate is a raw C function or type. Callers
//! must uphold the invariants documented by Intel's MKL reference. For a safe,
//! idiomatic Rust API, use the `onemkl` crate instead.
//!
//! # Feature flags
//!
//! Exactly one feature must be selected from each of the following groups:
//!
//! - **Interface layer:** `lp64` (default) or `ilp64`
//! - **Threading layer:** `threading-sequential` (default), `threading-intel-openmp`, or `threading-tbb`
//! - **Linkage:** `link-dynamic` (default) or `link-static`
//!
//! Opt-in MPI-dependent domains: `cluster-sparse-solver`, `cdft`, `scalapack`,
//! `blacs`, `pblas` (which implies `blacs`).
//!
//! # Locating the MKL install
//!
//! The build script searches in this order:
//!
//! 1. `MKLROOT` environment variable
//! 2. `ONEMKL_SYS_INCLUDE_DIR` / `ONEMKL_SYS_LIB_DIR` (explicit override)
//! 3. `ONEAPI_ROOT/mkl/latest`
//! 4. Platform-standard install paths (`C:\Program Files (x86)\Intel\oneAPI`
//!    on Windows, `/opt/intel/oneapi` elsewhere)

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

// Linux dynamic builds: the layered MKL shared libraries do not record
// each other in DT_NEEDED, and rustc links with `--as-needed`, so a
// final artifact that references only `mkl_intel_*` symbols loses
// `mkl_core` and the threading layer, then dies at load with
// `undefined symbol: mkl_blas_dgemm` (issue #3). `cargo:rustc-link-arg`
// cannot fix this for downstream crates (it only reaches the emitting
// crate's own artifacts) and the `as-needed` link modifier is
// nightly-only. So reference one symbol from each library here: a
// real symbol reference survives `--as-needed` and travels with the
// rlib to every dependent.
#[cfg(all(target_os = "linux", feature = "link-dynamic"))]
mod keep_layers_needed {
    unsafe extern "C" {
        // Exported only by `libmkl_core` (backs the public `MKL_CBWR_Get`).
        fn mkl_serv_cbwr_get();
        // Exported by whichever threading layer is linked
        // (`mkl_sequential`, `mkl_intel_thread` or `mkl_tbb_thread`).
        fn mkl_serv_get_max_threads();
    }

    #[used]
    static KEEP: [unsafe extern "C" fn(); 2] =
        [mkl_serv_cbwr_get, mkl_serv_get_max_threads];
}

// `MKL_INT`, `MKL_UINT`, and `MKL_LONG` are preprocessor `#define`s in
// `mkl_types.h`, so bindgen inlines their expansions rather than emitting
// Rust type aliases. We expose them here so downstream crates can refer to
// the chosen interface width by name.

/// Signed integer type used for sizes and increments throughout the MKL C
/// interface. 32-bit under `lp64` (default), 64-bit under `ilp64`.
#[cfg(feature = "ilp64")]
pub type MKL_INT = ::core::ffi::c_longlong;
/// Signed integer type used for sizes and increments throughout the MKL C
/// interface. 32-bit under `lp64` (default), 64-bit under `ilp64`.
#[cfg(not(feature = "ilp64"))]
pub type MKL_INT = ::core::ffi::c_int;

/// Unsigned counterpart of [`MKL_INT`].
#[cfg(feature = "ilp64")]
pub type MKL_UINT = ::core::ffi::c_ulonglong;
/// Unsigned counterpart of [`MKL_INT`].
#[cfg(not(feature = "ilp64"))]
pub type MKL_UINT = ::core::ffi::c_uint;

/// 64-bit signed integer type used in select MKL routines (CDFT, sparse
/// solver `_64` variants, etc.). Always 64 bits regardless of interface
/// layer.
pub type MKL_INT64 = ::core::ffi::c_longlong;

/// 64-bit unsigned integer type used in select MKL routines.
pub type MKL_UINT64 = ::core::ffi::c_ulonglong;

/// Long-width integer type. Differs by platform: `c_long` on Linux/macOS
/// (8 bytes), `c_longlong` on Windows under ILP64, `c_long` (4 bytes) on
/// Windows under LP64.
#[cfg(all(windows, not(feature = "ilp64")))]
pub type MKL_LONG = ::core::ffi::c_long;
#[cfg(all(windows, feature = "ilp64"))]
pub type MKL_LONG = ::core::ffi::c_longlong;
#[cfg(not(windows))]
pub type MKL_LONG = ::core::ffi::c_long;

/// Width of [`MKL_INT`] in bytes for the selected interface layer.
///
/// 4 with the default `lp64` feature, 8 with `ilp64`.
pub const MKL_INT_SIZE: usize = core::mem::size_of::<MKL_INT>();