blob: 15245c649a3ac70275df523ab21ff9e2aae08b41 [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
46@@ -0,0 +1,94 @@
47+cc_binary(
48+ name = "swtpm",
49+ deps = [
50+ "@libtpms//:libtpms_tpm2",
51+ "@glib//glib",
52+ ],
53+ srcs = glob([
54+ "src/swtpm/*.h",
55+ "src/swtpm/*.c",
56+ "src/utils/*.h",
57+ "src/utils/*.c",
58+ "include/*.h",
59+ "include/swtpm/*.h",
60+ ], [
61+ # No CUSE support.
62+ "src/swtpm/cuse_tpm.c",
63+ # Only used in utils.
64+ "src/utils/swtpm_utils.c",
65+ ]),
66+ copts = [
67+ "-Iexternal/swtpm/include",
68+ "-Iexternal/swtpm/include/swtpm",
69+ "-Iexternal/swtpm/src/utils",
70+ ],
71+ visibility = [
72+ "//visibility:public",
73+ ],
74+)
75+
76+cc_binary(
77+ name = "swtpm_localca",
78+ deps = [
79+ "@libtpms//:libtpms_tpm2",
80+ "@glib//glib",
81+ ],
82+ srcs = glob([
83+ "src/swtpm_localca/*.h",
84+ "src/swtpm_localca/*.c",
85+ "include/*.h",
86+ "include/swtpm/*.h",
87+ "src/utils/*.h",
88+ "src/utils/*.c",
89+ ], []),
90+ copts = [
91+ "-Iexternal/swtpm/include",
92+ "-Iexternal/swtpm/include/swtpm",
93+ "-Iexternal/swtpm/src/utils",
94+ ],
95+ visibility = [
96+ "//visibility:public",
97+ ],
98+)
99+
100+cc_binary(
101+ name = "swtpm_setup",
102+ deps = [
103+ "@libtpms//:libtpms_tpm2",
104+ "@glib//glib",
105+ ],
106+ srcs = glob([
107+ "src/swtpm_setup/*.h",
108+ "src/swtpm_setup/*.c",
109+ "include/*.h",
110+ "include/swtpm/*.h",
111+ "src/utils/*.h",
112+ "src/utils/*.c",
113+ ], []),
114+ copts = [
115+ "-Iexternal/swtpm/include",
116+ "-Iexternal/swtpm/include/swtpm",
117+ "-Iexternal/swtpm/src/utils",
118+ ],
119+ visibility = [
120+ "//visibility:public",
121+ ],
122+)
123+
124+cc_binary(
125+ name = "swtpm_cert",
126+ deps = [
127+ "@boringssl//:ssl",
128+ ],
129+ srcs = glob([
130+ "src/swtpm_cert/*.h",
131+ "src/swtpm_cert/*.c",
132+ "include/*.h",
133+ ], []),
134+ copts = [
135+ "-Iexternal/swtpm/include",
136+ ],
137+ visibility = [
138+ "//visibility:public",
139+ ],
140+)
141diff --git a/WORKSPACE b/WORKSPACE
142new file mode 100644
143index 0000000..e69de29
144diff --git a/include/config.h b/include/config.h
145new file mode 100644
146index 0000000..d3829d6
147--- /dev/null
148+++ b/include/config.h
149@@ -0,0 +1,8 @@
150+#pragma once
151+#define _GNU_SOURCE
152+
153+#define VERSION "0.8.2-monogon"
154+
155+// A bunch of files in swtpm depend on stdint types but never include them.
156+// Just inject them through here.
157+#include <stdint.h>
158diff --git a/include/swtpm.h b/include/swtpm.h
159new file mode 100644
160index 0000000..2eddeec
161--- /dev/null
162+++ b/include/swtpm.h
163@@ -0,0 +1,5 @@
164+#pragma once
165+
166+#define SWTPM_VER_MAJOR 0
167+#define SWTPM_VER_MINOR 8
168+#define SWTPM_VER_MICRO 2
169diff --git a/src/swtpm/main.c b/src/swtpm/main.c
170index 4864e85..633ca33 100644
171--- a/src/swtpm/main.c
172+++ b/src/swtpm/main.c
173@@ -83,7 +83,7 @@ int main(int argc, char **argv)
174 } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
175 usage(stdout, argv[0]);
176 } else if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
177- fprintf(stdout, "TPM emulator version %d.%d.%d, "
178+ fprintf(stdout, "TPM emulator version %d.%d.%d-monogon, "
179 "Copyright (c) 2014-2022 IBM Corp. and others\n",
180 SWTPM_VER_MAJOR,
181 SWTPM_VER_MINOR,
182diff --git a/src/utils/swtpm_conf.h b/src/utils/swtpm_conf.h
183new file mode 100644
184index 0000000..de8afdb
185--- /dev/null
186+++ b/src/utils/swtpm_conf.h
187@@ -0,0 +1,22 @@
188+/* SPDX-License-Identifier: BSD-3-Clause */
189+/*
190+ * swtpm_conf.h: Compile-time constants
191+ *
192+ * Author: Stefan Berger, stefanb@linux.ibm.com
193+ *
194+ * Copyright (c) IBM Corporation, 2021,2023
195+ */
196+
197+#ifndef SWTPM_SETUP_CONF_H
198+#define SWTPM_SETUP_CONF_H
199+
200+#define SWTPM_VER_MAJOR 0
201+#define SWTPM_VER_MINOR 8
202+#define SWTPM_VER_MICRO 2
203+
204+#define SYSCONFDIR "/unused"
205+#define BINDIR "/unused"
206+
207+#define DEFAULT_PCR_BANKS "sha256"
208+
209+#endif /* SWTPM_SETUP_CONF_H */
210--
2112.42.0
212