Skip to content

Commit a47c19c

Browse files
committed
feat: optionally ignore prerelease info from tss version, could be git-dirty, the rest of the version still has to match
1 parent e86099b commit a47c19c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

tss-esapi/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# TPM2 Software Stack Rust Wrapper
1+
# TPM2 Software Stack Rust Wrapper
22

33
<p align="center">
44
<a href="https://crates.io/crates/tss-esapi"><img alt="Crates.io" src="https://img.shields.io/crates/v/tss-esapi"></a>
55
<a href="https://docs.rs/tss-esapi"><img src="https://docs.rs/tss-esapi/badge.svg" alt="Code documentation"/></a>
66
<a href="https://codecov.io/gh/parallaxsecond/rust-tss-esapi"><img src="https://codecov.io/gh/parallaxsecond/rust-tss-esapi/branch/main/graph/badge.svg?token=5T7SVCHWFE"/></a>
77
</p>
88

9-
This is the high-level, Rust idiomatic wrapper crate that exposes an interface
9+
This is the high-level, Rust idiomatic wrapper crate that exposes an interface
1010
to [TSS](https://github.com/tpm2-software/tpm2-tss).
1111

1212
This crate depends on the [`tss-esapi-sys`](../tss-esapi-sys/) crate for its
1313
FFI interface. By default, pre-generated bindings are used. If you'd like the
14-
bindings to be generated at build time, please enable either the
14+
bindings to be generated at build time, please enable either the
1515
`generate-bindings` feature - the FFI bindings will then be generated at build
1616
time using the headers identified on the system.
1717

@@ -31,7 +31,7 @@ The crate currently offers the following features:
3131
* `abstraction` (enabled by default) - provides a set of abstracted primitives
3232
on top of the basic Rust-native ESAPI API provided by the crate. This feature
3333
can be turned off to reduce the number of dependencies built.
34-
* `serde` - enable serde `Serialize`/`Deserialize` traits for types.
34+
* `serde` - enable serde `Serialize`/`Deserialize` traits for types.
3535
* `rustcrypto-full` (disabled by default) - provides conversion from all
3636
supported elliptic curves, rsa or hashes.
3737
Support for individual hash, rsa or curves can be pulled individually.
@@ -45,4 +45,11 @@ The crate currently offers the following features:
4545

4646
For more information on cross-compiling the `tss-esapi` crate, please see the README of the `tss-esapi-sys` crate.
4747

48+
## Building against libtss2
49+
50+
The [TSS](https://github.com/tpm2-software/tpm2-tss) library can be installed from Debian, RPM, or other packaging manager.
51+
It will install a pkg-config definition to indicate how to compile and link against the library.
52+
When it is installed via source, and/or if it has been edited (such as to debug things), then the version number will be marked with the git commit (and dirty flag). The resulting version string is unfortunately not compatible with the semver parser/comparing mechanism, and it can be rejected.
53+
Setting the environment variable TPM2\_TSS\_VERSION\_IGNORE\]_PRERELEASE to a non-empty string will cause the build system to ignore this pre-release information.
54+
4855
*Copyright 2021 Contributors to the Parsec project.*

tss-esapi/build.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright 2021 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
3-
use semver::{Version, VersionReq};
3+
use semver::{Version, VersionReq, Prerelease};
44

55
const TPM2_TSS_MINIMUM_VERSION: Version = Version::new(4, 1, 3);
6+
const TPM2_TSS_VERSION_IGNORE_PRERELEASE: &str = "TPM2_TSS_VERSION_IGNORE_PRERELEASE";
67

78
fn main() {
89
println!("cargo:rustc-check-cfg=cfg(hierarchy_is_esys_tr)");
@@ -20,15 +21,22 @@ fn main() {
2021
.expect("Failed to parse ENV variable DEP_TSS2_ESYS_VERSION as string");
2122

2223
Version::parse(&tss_version_string)
23-
.expect("Failed to parse the DEP_TSS2_ESYS_VERSION variable as a semver version")
24+
.map(|mut v| {
25+
if std::env::var(TPM2_TSS_VERSION_IGNORE_PRERELEASE).is_ok() {
26+
v.pre = Prerelease::EMPTY;
27+
}
28+
v
29+
})
30+
.expect("Failed to parse the DEP_TSS2_ESYS_VERSION variable {tss_version_string} as a semver version")
2431
};
2532

2633
let supported_tss_version =
2734
VersionReq::parse("<5.0.0, >=2.3.3").expect("Failed to parse supported TSS version");
2835

36+
//eprintln!("tss version: {} / {:?}", supported_tss_version, tss_version);
2937
assert!(
3038
supported_tss_version.matches(&tss_version),
31-
"Unsupported TSS version {tss_version}"
39+
"Unsupported TSS version {tss_version}, maybe try {TPM2_TSS_VERSION_IGNORE_PRERELEASE}=true"
3240
);
3341

3442
let hierarchy_is_esys_tr_req = VersionReq::parse(">=3.0.0").unwrap();

0 commit comments

Comments
 (0)