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.
What
wolftpm-src is a build-infrastructure crate. It has no public Rust API.
Its only job is to compile the wolfTPM C library into a static archive
(libwolftpm.a) and expose the paths to the compiled library and its headers
via Cargo's links metadata mechanism, so that wolftpm-sys can link against
it and run bindgen over the headers.
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 is run here.wolftpmowns the safe Rust API.
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.
How to use
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.
wolfTPM source
wolftpm-src needs the wolfTPM C source tree. Two ways to supply it:
Option 1: Environment variable (recommended for development)
Option 2: Bundled submodule
The submodule tracks the upstream wolfSSL/wolfTPM main branch.
wolfSSL dependency
wolfTPM uses wolfSSL/wolfCrypt for RSA, ECC, and hash operations internally. Supply the wolfSSL headers via any of:
| Variable | Description |
|---|---|
WOLFSSL_DIR |
Install prefix — headers at $WOLFSSL_DIR/include |
WOLFSSL_INCLUDE_DIR |
Direct path to the wolfSSL include directory |
WOLFSSL_SRC |
wolfSSL source tree root (vendored build) |
The pre-built wolfSSL must have been compiled with WOLF_CRYPTO_CB enabled.
Features
| 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
Copyright
Copyright (C) 2006-2026 wolfSSL Inc.
wolfTPM is copyright wolfSSL Inc. and its contributors.
License
GPL-3.0-only OR LicenseRef-wolfSSL-commercial
This crate (the Rust build-script wrapper) is available under the GNU General Public License v3.0. For proprietary or commercial use, a commercial license is available from wolfSSL Inc.
wolfTPM itself is also licensed under GPL-2.0-or-later or a commercial wolfSSL license.