blob: b37ea69d96b75df2f9ea6fe8a057b51878361d72 [file] [log] [blame]
Serge Bazanski72c1f2b2024-06-04 13:42:48 +00001From 3b2ea39444bf97d7847fdb1a3ca70f9d58ffe22a Mon Sep 17 00:00:00 2001
2From: Serge Bazanski <serge@monogon.tech>
3Date: Tue, 4 Jun 2024 15:10:02 +0200
4Subject: [PATCH 4/4] bazel support: implement
5
6---
7 .gitignore | 2 -
8 BUILD.bazel | 94 ++++++++++++++++++++++++++++++++++++++++++
9 WORKSPACE | 0
10 include/config.h | 8 ++++
11 include/swtpm.h | 5 +++
12 src/swtpm/main.c | 2 +-
13 src/utils/swtpm_conf.h | 22 ++++++++++
14 7 files changed, 130 insertions(+), 3 deletions(-)
15 create mode 100644 BUILD.bazel
16 create mode 100644 WORKSPACE
17 create mode 100644 include/config.h
18 create mode 100644 include/swtpm.h
19 create mode 100644 src/utils/swtpm_conf.h
20
21diff --git a/.gitignore b/.gitignore
22index c669f06..9982dd0 100644
23--- a/.gitignore
24+++ b/.gitignore
25@@ -35,7 +35,6 @@ Makefile
26 /m4/*
27 /.pc/*
28 /patches/*
29-/include/swtpm.h
30 /man/man3/*.3
31 /man/man5/*.5
32 /man/man8/*.8
33@@ -60,7 +59,6 @@ Makefile
34 /src/swtpm_ioctl/swtpm_ioctl
35 /src/swtpm_localca/swtpm_localca
36 /src/swtpm_setup/swtpm_setup
37-/src/utils/swtpm_conf.h
38 /test-driver
39 tests/*.log
40 tests/*.trs
41diff --git a/BUILD.bazel b/BUILD.bazel
42new file mode 100644
43index 0000000..acddc0e
44--- /dev/null
45+++ b/BUILD.bazel
Tim Windelschmidt0de92122024-09-24 06:37:30 +020046@@ -0,0 +1,100 @@
47+filegroup(
48+ name = "all",
49+ srcs = glob(["**"]),
50+ visibility = ["//visibility:public"],
51+)
52+
Serge Bazanski72c1f2b2024-06-04 13:42:48 +000053+cc_binary(
54+ name = "swtpm",
55+ deps = [
Tim Windelschmidte1420ab2024-08-27 01:53:16 +020056+ "@@//third_party/libtpms:libtpms_tpm2",
57+ "@@//third_party/glib",
Serge Bazanski72c1f2b2024-06-04 13:42:48 +000058+ ],
59+ srcs = glob([
60+ "src/swtpm/*.h",
61+ "src/swtpm/*.c",
62+ "src/utils/*.h",
63+ "src/utils/*.c",
64+ "include/*.h",
65+ "include/swtpm/*.h",
66+ ], [
67+ # No CUSE support.
68+ "src/swtpm/cuse_tpm.c",
69+ # Only used in utils.
70+ "src/utils/swtpm_utils.c",
71+ ]),
72+ copts = [
Tim Windelschmidt0de92122024-09-24 06:37:30 +020073+ "-I{path}/include".format(path = package_relative_label(":all").workspace_root),
74+ "-I{path}/include/swtpm".format(path = package_relative_label(":all").workspace_root),
75+ "-I{path}/src/utils".format(path = package_relative_label(":all").workspace_root),
Serge Bazanski72c1f2b2024-06-04 13:42:48 +000076+ ],
77+ visibility = [
78+ "//visibility:public",
79+ ],
80+)
81+
82+cc_binary(
83+ name = "swtpm_localca",
84+ deps = [
Tim Windelschmidte1420ab2024-08-27 01:53:16 +020085+ "@@//third_party/libtpms:libtpms_tpm2",
86+ "@@//third_party/glib",
Serge Bazanski72c1f2b2024-06-04 13:42:48 +000087+ ],
88+ srcs = glob([
89+ "src/swtpm_localca/*.h",
90+ "src/swtpm_localca/*.c",
91+ "include/*.h",
92+ "include/swtpm/*.h",
93+ "src/utils/*.h",
94+ "src/utils/*.c",
95+ ], []),
96+ copts = [
Tim Windelschmidt0de92122024-09-24 06:37:30 +020097+ "-I{path}/include".format(path = package_relative_label(":all").workspace_root),
98+ "-I{path}/include/swtpm".format(path = package_relative_label(":all").workspace_root),
99+ "-I{path}/src/utils".format(path = package_relative_label(":all").workspace_root),
Serge Bazanski72c1f2b2024-06-04 13:42:48 +0000100+ ],
101+ visibility = [
102+ "//visibility:public",
103+ ],
104+)
105+
106+cc_binary(
107+ name = "swtpm_setup",
108+ deps = [
Tim Windelschmidte1420ab2024-08-27 01:53:16 +0200109+ "@@//third_party/libtpms:libtpms_tpm2",
110+ "@@//third_party/glib",
Serge Bazanski72c1f2b2024-06-04 13:42:48 +0000111+ ],
112+ srcs = glob([
113+ "src/swtpm_setup/*.h",
114+ "src/swtpm_setup/*.c",
115+ "include/*.h",
116+ "include/swtpm/*.h",
117+ "src/utils/*.h",
118+ "src/utils/*.c",
119+ ], []),
120+ copts = [
Tim Windelschmidt0de92122024-09-24 06:37:30 +0200121+ "-I{path}/include".format(path = package_relative_label(":all").workspace_root),
122+ "-I{path}/include/swtpm".format(path = package_relative_label(":all").workspace_root),
123+ "-I{path}/src/utils".format(path = package_relative_label(":all").workspace_root),
Serge Bazanski72c1f2b2024-06-04 13:42:48 +0000124+ ],
125+ visibility = [
126+ "//visibility:public",
127+ ],
128+)
129+
130+cc_binary(
131+ name = "swtpm_cert",
132+ deps = [
133+ "@boringssl//:ssl",
134+ ],
135+ srcs = glob([
136+ "src/swtpm_cert/*.h",
137+ "src/swtpm_cert/*.c",
138+ "include/*.h",
139+ ], []),
140+ copts = [
Tim Windelschmidt0de92122024-09-24 06:37:30 +0200141+ "-I{path}/include".format(path = package_relative_label(":all").workspace_root),
Serge Bazanski72c1f2b2024-06-04 13:42:48 +0000142+ ],
143+ visibility = [
144+ "//visibility:public",
145+ ],
146+)
147diff --git a/WORKSPACE b/WORKSPACE
148new file mode 100644
149index 0000000..e69de29
150diff --git a/include/config.h b/include/config.h
151new file mode 100644
152index 0000000..d3829d6
153--- /dev/null
154+++ b/include/config.h
155@@ -0,0 +1,8 @@
156+#pragma once
157+#define _GNU_SOURCE
158+
159+#define VERSION "0.8.2-monogon"
160+
161+// A bunch of files in swtpm depend on stdint types but never include them.
162+// Just inject them through here.
163+#include <stdint.h>
164diff --git a/include/swtpm.h b/include/swtpm.h
165new file mode 100644
166index 0000000..2eddeec
167--- /dev/null
168+++ b/include/swtpm.h
169@@ -0,0 +1,5 @@
170+#pragma once
171+
172+#define SWTPM_VER_MAJOR 0
173+#define SWTPM_VER_MINOR 8
174+#define SWTPM_VER_MICRO 2
175diff --git a/src/swtpm/main.c b/src/swtpm/main.c
176index 4864e85..633ca33 100644
177--- a/src/swtpm/main.c
178+++ b/src/swtpm/main.c
179@@ -83,7 +83,7 @@ int main(int argc, char **argv)
180 } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
181 usage(stdout, argv[0]);
182 } else if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
183- fprintf(stdout, "TPM emulator version %d.%d.%d, "
184+ fprintf(stdout, "TPM emulator version %d.%d.%d-monogon, "
185 "Copyright (c) 2014-2022 IBM Corp. and others\n",
186 SWTPM_VER_MAJOR,
187 SWTPM_VER_MINOR,
188diff --git a/src/utils/swtpm_conf.h b/src/utils/swtpm_conf.h
189new file mode 100644
190index 0000000..de8afdb
191--- /dev/null
192+++ b/src/utils/swtpm_conf.h
193@@ -0,0 +1,22 @@
194+/* SPDX-License-Identifier: BSD-3-Clause */
195+/*
196+ * swtpm_conf.h: Compile-time constants
197+ *
198+ * Author: Stefan Berger, stefanb@linux.ibm.com
199+ *
200+ * Copyright (c) IBM Corporation, 2021,2023
201+ */
202+
203+#ifndef SWTPM_SETUP_CONF_H
204+#define SWTPM_SETUP_CONF_H
205+
206+#define SWTPM_VER_MAJOR 0
207+#define SWTPM_VER_MINOR 8
208+#define SWTPM_VER_MICRO 2
209+
210+#define SYSCONFDIR "/unused"
211+#define BINDIR "/unused"
212+
213+#define DEFAULT_PCR_BANKS "sha256"
214+
215+#endif /* SWTPM_SETUP_CONF_H */
216--
2172.42.0
218