Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
wolftpm-src
Build-script crate that compiles wolfTPM
from C source as part of a Cargo build. Used internally by
wolftpm-sys; has no public Rust API.
Why
Cargo cannot compile C libraries on behalf of an arbitrary crate — each
crate that links a C library needs a build.rs that drives the C
compiler. The three-crate split (wolftpm-src → wolftpm-sys →
wolftpm) mirrors the pattern used throughout this
workspace (wolfssl-src,
wolfhsm-src) and separates concerns cleanly:
wolftpm-srcowns the C build; it can be versioned and replaced without touching the FFI or the safe Rust API.wolftpm-sysowns the FFI boundary; bindgen runs there.wolftpmowns the safe Rust API.
Usage
This crate is not intended to be used directly. Add
wolftpm-sys or wolftpm to your
Cargo.toml instead.
If you need to use wolftpm-src directly (e.g. to build a different FFI
crate against the same wolfTPM build), declare it as a regular
[dependency] rather than a [build-dependency] so that Cargo
propagates the DEP_WOLFTPM_SRC_* metadata to your build script:
[]
= "0.2"
The wolfTPM source tree must be available, supplied by either of:
# Option 1: point to a local wolfTPM clone
# Option 2: bundled submodule (tracks upstream wolfSSL/wolfTPM main)
The wolfSSL headers are also required (wolfTPM uses wolfSSL/wolfCrypt internally for RSA, ECC, and hash operations). Supply them via any of:
| Variable | Description |
|---|---|
WOLFSSL_INCLUDE_DIR |
Direct path to the wolfSSL include directory |
WOLFSSL_DIR |
Install prefix — headers at $WOLFSSL_DIR/include |
WOLFSSL_SRC |
wolfSSL source tree root (vendored build) |
Variables are checked in the order listed above. The pre-built wolfSSL
must have been compiled with WOLF_CRYPTO_CB enabled.
How it works
build.rs performs four steps:
- Locate wolfTPM source — checks
WOLFTPM_SRCfirst, then falls back to the bundled git submodule atwolftpm-src/wolftpm/. - Locate wolfSSL headers — checks
WOLFSSL_INCLUDE_DIR,WOLFSSL_DIR, thenWOLFSSL_SRCin that priority order (same as the rest of the workspace). - Generate
wolftpm/options.hinOUT_DIR— wolfTPM's headers unconditionally#include <wolftpm/options.h>. This generated file selects the transport backend based on Cargo features and the target OS. On Linux with no feature selected it defaults toWOLFTPM_LINUX_DEV(the/dev/tpm0kernel driver) so thathal/tpm_io.hmapsTPM2_IoCbtoNULL, which is what the kernel driver path requires. - Compile wolfTPM — uses the
cccrate to compile the core source files (tpm2.c,tpm2_wrap.c,tpm2_packet.c,tpm2_param_enc.c,tpm2_util.c,tpm2_crypto.c) and optional transport files (tpm2_cryptocb.c,tpm2_linux.c,tpm2_swtpm.c,tpm2_tis.c) when present.
The compiled library path and wolfTPM include directory are emitted as
Cargo metadata (DEP_WOLFTPM_SRC_LIB, DEP_WOLFTPM_SRC_INCLUDE) for
consumption by wolftpm-sys.
| Feature | Description |
|---|---|
linux-dev |
Compile wolfTPM with Linux /dev/tpm0 kernel driver transport |
swtpm |
Compile wolfTPM with software TPM socket transport (swtpm, IBM TPM2 simulator) |
If neither feature is selected, the build defaults to
WOLFTPM_LINUX_DEV on Linux. Both features may be enabled
simultaneously.
References
- wolftpm — safe Rust API; use this unless you have a specific reason not to
- wolftpm-sys — raw FFI bindings consumer of this crate
- wolftpm-tss — tpm-rs TSS backend
- wolfTPM repository
- wolfTPM documentation
- wolfTPM manual
- workspace README
Copyright
Copyright (C) 2006-2026 wolfSSL Inc.
wolfTPM is copyright wolfSSL Inc. and its contributors.
License
GPL-3.0-only OR LicenseRef-wolfSSL-commercial.
The underlying wolfTPM C library is licensed under GPL-3.0-or-later with a commercial option available from wolfSSL Inc.