Skip to content

Commit 8e7f02c

Browse files
SuperhepperFirstyearuglyoldbob
committed
Adds the bundled feature.
The bundled feature is ment to make the process of building and managing the tpm2-tss depedency of the tss-esapi-sys crate much easier by downloading the source code and compiling it automatically. This feature was originally developed in \parallaxsecond#523 and then updated in \parallaxsecond#531. Co-authored-by: William Brown <[email protected]> Co-authored-by: Thomas Epperson <[email protected]> Signed-off-by: Jesper Brynolf <[email protected]>
1 parent 40899e5 commit 8e7f02c

File tree

13 files changed

+730
-105
lines changed

13 files changed

+730
-105
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
steps:
6363
- uses: actions/checkout@v4
6464
- name: Build the container
65-
run: docker build -t ubuntucontainer tss-esapi/tests/ --build-arg TPM2_TSS_VERSION=4.0.1 --file tss-esapi/tests/Dockerfile-ubuntu --target tpm2-tss-install-dir
65+
run: docker build -t ubuntucontainer tss-esapi/tests/ --build-arg TPM2_TSS_VERSION=4.1.3 --file tss-esapi/tests/Dockerfile-ubuntu --target tpm2-tss-install-dir
6666
- name: Run the container
6767
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi ubuntucontainer /tmp/rust-tss-esapi/tss-esapi/tests/all-ubuntu.sh
6868

tss-esapi-sys/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ links = "tss2-esys"
1414
rust-version = "1.74.0"
1515

1616
[build-dependencies]
17-
bindgen = { version = "0.70.1", optional = true }
17+
bindgen = { version = "0.72.0", optional = true }
1818
pkg-config = "0.3.18"
19-
target-lexicon = "0.12.0"
19+
target-lexicon = "0.13.2"
2020
cfg-if = "1.0.0"
2121
semver = "1.0.7"
22+
autotools = { version = "0.2.6", optional = true }
23+
24+
[target.'cfg(windows)'.build-dependencies]
25+
msbuild = { version = "0.2.0", optional = true }
2226

2327
[features]
2428
generate-bindings = ["bindgen"]
29+
bundled = ["dep:autotools", "dep:msbuild"]

tss-esapi-sys/README.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ interface to Rust to [TSS](https://github.com/tpm2-software/tpm2-tss).
1313

1414
This crate exposes an interface for the TSS Enhanced System API and thus
1515
links to libraries that expose this interface. In order to allow proper use
16-
of the ESAPI, this FFI layer includes bindings to TCTI and MU headers, and
16+
of the ESAPI, this FFI layer includes bindings to TCTI and MU headers, and
1717
must therefore link to all of them at build time.
1818

1919
The paths to the libraries are discovered using `pkg-config` - make sure they
20-
are discoverable in this way on your system. Our build script looks for
21-
`tss2-esys`, `tss2-tctildr` and `tss2-mu`. A minimum version of `4.0.1` is
20+
are discoverable in this way on your system. Our build script looks for
21+
`tss2-esys`, `tss2-tctildr` and `tss2-mu`. A minimum version of `4.1.3` is
2222
required for all of them.
2323

2424
Having installed the open-source implementation libraries at `/usr/local/lib` (by default), it
@@ -41,9 +41,72 @@ available, feel free to raise a Pull Request to add it or to use build-time
4141
generation of bindings. All the committed bindings **MUST** be generated from
4242
the library version found under the `vendor` submodule.
4343

44+
## Bundling TPM-TSS
45+
46+
[`tpm-tss`](https://github.com/tpm2-software/tpm2-tss) is used by this
47+
library to communicate with TPMs. If this library is not available on
48+
your system you may optionally bundle (vendor) tpm-tss during builds.
49+
tpm-tss can be provided from a local source path with the
50+
environment variable `TPM_TSS_SOURCE_PATH` or it will be retrieved from
51+
Github during the build. The version to retrieve can be controlled by setting
52+
the `TPM2_TSS_SOURCE_VERSION` environment variable.
53+
[!IMPORTANT]
54+
On windows it might be necessary to manually create the VERSION file
55+
when a local source is being used.
56+
57+
To enable this feature:
58+
59+
```bash
60+
cargo build --features=bundled
61+
```
62+
63+
```bash
64+
TPM2_TSS_VERSION="4.1.3" cargo build --features=bundled
65+
```
66+
67+
```bash
68+
TPM_TSS_SOURCE_PATH=/path/to/tpm-tss cargo build --features=bundled
69+
```
70+
71+
If using this feature from an external project
72+
73+
```
74+
tss-esapi-sys = { version = "...", features = ["bundled"] }
75+
```
76+
77+
### Windows
78+
79+
Compiling for windows requires a bit of setup to work with the bundled feature.
80+
81+
* OpenSSL must be installed to a non-standard location at `C:\OpenSSL-v11-Win64`
82+
* Visual Studio 2019 must be installed with the Clang/C2 experimental component,
83+
and windows sdk 10.0 (Other versions of Visual Studio may work but are untested
84+
at this point).
85+
86+
### MacOS
87+
88+
Compiling on MacOS requires the bundling feature. This requires dependencies
89+
from brew.
90+
91+
```bashbre
92+
brew install autoconf autoconf-archive automake json-c libtool m4 pkg-config
93+
```
94+
95+
Optionally you may require these libraries for certain classes of TPM transport
96+
97+
```
98+
brew install libftdi
99+
```
100+
101+
### OpenSUSE / SUSE
102+
103+
```
104+
sudo zypper in autoconf autoconf-archive automake libjson-c-devel libtool libtpms-devel gawk make
105+
```
106+
44107
## Cross compiling
45108

46-
Cross-compilation can be done as long as you have on your build system the TSS
109+
Cross-compilation can be done as long as you have on your build system the TSS
47110
libraries compiled for your target system of choice. We rely on `pkg-config` to
48111
identify the libraries which we link against. Installing `tpm2-tss` does yield
49112
`.pc` files which can be used for this purpose, but depending on the exact build

0 commit comments

Comments
 (0)