-
Notifications
You must be signed in to change notification settings - Fork 202
/
meson.build
140 lines (120 loc) · 4.35 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
project('mbedtls', 'c', version: '3.6.0')
cc = meson.get_compiler('c')
host_has_glibc = cc.get_define('__GLIBC__', prefix: '#include <features.h>') != ''
pkgconfig = import('pkgconfig')
mbedtls_libs_output = [
'libmbedcrypto_gramine.so.16',
'libmbedcrypto_gramine.so',
'libmbedtls_gramine.so.21',
'libmbedtls_gramine.so',
'libmbedx509_gramine.so.7',
'libmbedx509_gramine.so',
'libmbedcrypto_gramine.a',
'libmbedtls_gramine.a',
'libmbedx509_gramine.a',
]
# TODO: This is custom_target, because we need to patch mbedtls before compiling.
# PR for patch support in wraps: https://github.com/mesonbuild/meson/pull/4570
mbedtls_libs = custom_target('mbedtls',
command: [
find_program('compile-gramine.sh'),
'@CURRENT_SOURCE_DIR@',
'@CURRENT_SOURCE_DIR@/mbedtls-3.6.0',
meson.current_build_dir(),
'@PRIVATE_DIR@',
'@OUTPUT@',
'--',
'SUFFIX=_gramine',
'SHARED=1',
],
input: ['mbedtls-3.6.0/Makefile', 'gramine.patch'],
# NOTE we need real sonames here (.so.N, not .so), please keep synced with
# mbedtls/library/Makefile, variables SOEXT_{TLS,X509,CRYPTO}
output: mbedtls_libs_output,
install: true,
install_dir: get_option('libdir'),
)
pkgconfig.generate(
name: 'mbedtls_gramine',
filebase: 'mbedtls_gramine',
description: 'A version of mbedtls patched for Gramine',
subdirs: 'gramine',
libraries: [
'-L${libdir}',
'-Wl,-rpath,${libdir}',
'-Wl,--start-group',
'-lmbedcrypto_gramine',
'-lmbedtls_gramine',
'-lmbedx509_gramine',
'-Wl,--end-group',
],
)
if get_option('libc') == 'glibc' and host_has_glibc
foreach output : mbedtls_libs_output
meson.add_install_script('/bin/sh', '-c',
('mkdir -p "$MESON_INSTALL_DESTDIR_PREFIX"/@1@/gramine/runtime/@2@/i && ' +
'ln -sf ../../../@0@ ' +
'"$MESON_INSTALL_DESTDIR_PREFIX"/@1@/gramine/runtime/@2@/').format(
output, get_option('libdir'), get_option('libc')))
endforeach
endif
# We rely on the fact that for `mbedtls_gramine` package, we don't need any changes in the default
# mbedTLS headers
install_subdir('mbedtls-3.6.0/include/mbedtls', install_dir: get_option('includedir') / 'gramine')
install_subdir('mbedtls-3.6.0/include/psa', install_dir: get_option('includedir') / 'gramine')
mbedtls_pal_libs = custom_target('mbedtls_pal',
command: [
find_program('compile-pal.sh'),
'@CURRENT_SOURCE_DIR@',
'@CURRENT_SOURCE_DIR@/mbedtls-3.6.0',
meson.current_build_dir(),
'@PRIVATE_DIR@',
'@OUTPUT@',
'--',
'SUFFIX=_pal',
],
input: ['mbedtls-3.6.0/Makefile', 'gramine.patch'],
output: [
'libmbedcrypto_pal.a',
'libmbedtls_pal.a',
'libmbedx509_pal.a',
],
build_by_default: true,
)
mbedtls_curl_libs = custom_target('mbedtls_curl',
command: [
find_program('compile-curl.sh'),
'@CURRENT_SOURCE_DIR@',
'@CURRENT_SOURCE_DIR@/mbedtls-3.6.0',
meson.current_build_dir(),
'@PRIVATE_DIR@',
meson.build_root() / 'subprojects',
'@OUTPUT@',
],
input: ['mbedtls-3.6.0/Makefile', 'gramine.patch'],
output: [
'libmbedcrypto.a',
'libmbedtls.a',
'libmbedx509.a',
],
build_by_default: true,
)
mbedtls_inc = include_directories('include', 'mbedtls-3.6.0/include')
mbedtls_static_dep = declare_dependency(
link_with: [mbedtls_libs[6], mbedtls_libs[7], mbedtls_libs[8]],
include_directories: mbedtls_inc,
)
mbedtls_pal_dep = declare_dependency(
# HACK: Apparently Meson considers the `mbedtls_pal_libs` to be "not linkable", because it has
# multiple outputs; however, it allows picking the outputs one by one.
link_with: [mbedtls_pal_libs[0], mbedtls_pal_libs[1], mbedtls_pal_libs[2]],
include_directories: mbedtls_inc,
compile_args: '-DMBEDTLS_CONFIG_FILE="mbedtls/config-pal.h"',
)
mbedtls_curl_dep = declare_dependency(
# HACK: Apparently Meson considers the `mbedtls_curl_libs` to be "not linkable", because it has
# multiple outputs; however, it allows picking the outputs one by one.
link_with: [mbedtls_curl_libs[0], mbedtls_curl_libs[1], mbedtls_curl_libs[2]],
include_directories: mbedtls_inc,
compile_args: '-DMBEDTLS_CONFIG_FILE="mbedtls/config-pal.h"',
)