Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tss-esapi-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ rust-version = "1.85.0"

[build-dependencies]
bindgen = { version = "0.72.1", optional = true }
pkg-config = "0.3.33"
target-lexicon = "0.13.5"
cfg-if = "1.0.4"
pkg-config = "0.3.33"
semver = "1.0.27"
autotools = { version = "0.2.7", optional = true }
target-lexicon = "0.13.5"

[target.'cfg(windows)'.build-dependencies]
msbuild = { version = "0.2.1", optional = true }

[target.'cfg(not(windows))'.build-dependencies]
autotools = { version = "0.2.7", optional = true }

[features]
generate-bindings = ["bindgen", "dep:msbuild"]
generate-bindings = ["dep:bindgen", "dep:autotools", "dep:msbuild"]
bundled = ["dep:autotools", "dep:msbuild"]
23 changes: 20 additions & 3 deletions tss-esapi-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ Github during the build. The version to retrieve can be controlled by setting
the `TPM2_TSS_SOURCE_VERSION` environment variable.
[!IMPORTANT]
* The `bundled` feature will make it possible to build the crate without
having to worry about the `tpm2-tss` library dependencies. But it is still
necessary to make the shared libraries available to the executable that uses
the library.
having to worry about the `tpm2-tss` library dependencies.
* The dependencies of `tpm2-tss` need to be installed and discoverable via
`pkg-config` on all platforms except Windows, on Windows this is handled
differently. See the [Windows section](#windows).
Expand Down Expand Up @@ -128,6 +126,25 @@ sudo zypper in \
make
```

## Bundling and Static Linking

When building with the `bundled` feature, the tss-esapi-sys crate makes use of the
[`--enable-nodl`](https://github.com/tpm2-software/tpm2-tss/blob/be602a5/configure.ac#L396) option
in `autoconf`. This configures the library such that TCTIs are directly linked via the bundled
library statically, without any use of `dlopen` to call into these libraries at runtime. As such,
all TCTIs (swtpm, device, mssim) will be linked statically to the resulting tss-esapi-sys crate, as
the symbols will be present in the compiled artefacts and `cargo` will need to see them to
successfully link any TCTI libraries.

This is likely what you want if you want a fully-static bundled installation of the libtss2 library.
If you want to link to TCTIs dynamically, you should first install a compatible version of libtss2
and either set up pkg-config to find it, or configure your `TPM2_TSS_PATH` manually.

**NOTE**: On Windows builds, `msbuild` is used instead of `autotools`, and so these assumptions
should be checked and verified. The `nodl` configuration option should be set to ensure your bundled
library links fully statically, or you should expect that you will need to have the dynamic TCTI
libraries present at runtime as they may be called via `dlopen`.

## Cross compiling

Cross-compilation can be done as long as you have on your build system the TSS
Expand Down
35 changes: 32 additions & 3 deletions tss-esapi-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ pub mod tpm2_tss {
tss2_mu: Library,
#[allow(unused)]
tss2_tcti_tbs: Option<Library>,
#[allow(unused)]
tss2_tcti_device: Option<Library>,
#[allow(unused)]
tss2_tcti_swtpm: Option<Library>,
#[allow(unused)]
tss2_tcti_mssim: Option<Library>,
}

impl Installation {
Expand All @@ -173,6 +179,21 @@ pub mod tpm2_tss {
),
tss2_mu: Library::bundled_required("tss2-mu", &source_path, &version, false),
tss2_tcti_tbs: Library::bundled_optional("tss2-tcti-tbs", &source_path, &version),
tss2_tcti_device: Library::bundled_optional(
"tss2-tcti-device",
&source_path,
&version,
),
tss2_tcti_swtpm: Library::bundled_optional(
"tss2-tcti-swtpm",
&source_path,
&version,
),
tss2_tcti_mssim: Library::bundled_optional(
"tss2-tcti-mssim",
&source_path,
&version,
),
}
}

Expand Down Expand Up @@ -209,6 +230,14 @@ pub mod tpm2_tss {
install_path.as_ref(),
with_header_files,
),
// When dynamically linked, the TCTI library will dlopen these itself.
//
// See: the `--enable-nodl` configuration at
//
// <https://github.com/tpm2-software/tpm2-tss/blob/master/configure.ac#L396>
tss2_tcti_device: None,
tss2_tcti_swtpm: None,
tss2_tcti_mssim: None,
Comment thread
ThatGeoGuy marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -426,9 +455,8 @@ pub mod tpm2_tss {
.expect("Unable to create version file for tpm2-tss");
write!(version_file, "{}", Self::version())
.unwrap_or_else(|e| panic!("Failed to write version file: {e}"));
}
}
else {
}
} else {
let install_path = Self::compile_with_autotools(source_path);

// On some systems the files are installed to the lib64 dir
Expand Down Expand Up @@ -477,6 +505,7 @@ pub mod tpm2_tss {
.reconf("-fiv")
// skip ./configure if no parameter changes are made
.fast_build(true)
.enable("nodl", Some("yes"))
.enable("esys", None)
// Disable fapi as we only use esys
.disable("fapi", None)
Expand Down
Loading