Skip to content

Commit c9f512e

Browse files
author
Ashutosh Mishra
committed
fix: rewriting meson build
1 parent c460d5c commit c9f512e

File tree

11 files changed

+610
-2830
lines changed

11 files changed

+610
-2830
lines changed

cross/arm-none-eabi.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
# For more information: http://mesonbuild.com/Cross-compilation.html
44

55
[binaries]
6-
c = '/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc'
7-
cpp = '/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-c++'
6+
c = 'arm-none-eabi-gcc'
7+
cpp = 'arm-none-eabi-c++'
88
# *-gcc-ar is used over *-ar to support LTO flags.
99
# Without -gcc-ar, LTO will generate a linker warning:
1010
# arm-none-eabi-ar: file.o: plugin needed to handle lto object
11-
ar = '/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc-ar'
12-
strip = '/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-strip'
11+
ar = 'arm-none-eabi-gcc-ar'
12+
strip = 'arm-none-eabi-strip'
1313

1414

1515
[properties]
16-
objcopy = '/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-objcopy'
17-
size = '/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-size'
16+
objcopy = 'arm-none-eabi-objcopy'
17+
size = 'arm-none-eabi-size'
1818
# Flags used when checking for supported linker arguments
1919
# Use this property when flag checks fail due to linker errors with ARM GCC
2020
get_supported_link_arg_flags = ['--specs=nosys.specs']

lib/meson.build

Lines changed: 91 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,167 @@
1-
# lib/meson.build
2-
# WolfSSL cryptographic library build configuration
1+
# wolfCrypt library build configuration
2+
# Extracted from main meson.build for modularity
33

4-
# Get build options from parent
4+
# Get configuration from parent
5+
fs = import('fs')
6+
inc_dirs = include_directories('..')
7+
c_args = []
8+
9+
# Re-inherit key configuration values from parent
510
arch = get_option('arch')
6-
target = get_option('target')
711
sign = get_option('sign')
8-
hash = get_option('hash')
9-
encrypt = get_option('encrypt')
10-
debug = get_option('wolfboot_debug')
12+
hash_alg = get_option('hash')
13+
encrypt_enabled = get_option('encrypt')
14+
tpm_enabled = get_option('tpm')
15+
16+
# Math selection flags (inherit from parent logic)
17+
if get_option('spmathall')
18+
c_args += ['-DWOLFSSL_SP_MATH_ALL']
19+
elif get_option('spmath')
20+
if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm')
21+
c_args += ['-DWOLFSSL_SP_ASM', '-DWOLFSSL_SP_ARM_CORTEX_M_ASM']
22+
endif
23+
else
24+
# Fastmath
25+
c_args += ['-DUSE_FAST_MATH']
26+
endif
1127

12-
# Base WolfCrypt sources (matching arch.mk defaults)
28+
# Core wolfCrypt sources (always included)
1329
wolfcrypt_sources = [
1430
'wolfssl/wolfcrypt/src/sha256.c',
1531
'wolfssl/wolfcrypt/src/hash.c',
1632
'wolfssl/wolfcrypt/src/memory.c',
1733
'wolfssl/wolfcrypt/src/wc_port.c',
1834
'wolfssl/wolfcrypt/src/wolfmath.c',
19-
'wolfssl/wolfcrypt/src/asn.c', # From options.mk
20-
'wolfssl/wolfcrypt/src/logging.c', # Debug logging support from arch.mk
35+
'wolfssl/wolfcrypt/src/asn.c',
36+
'wolfssl/wolfcrypt/src/logging.c',
2137
]
2238

23-
# Math library sources
24-
if get_option('spmath')
39+
# Math library selection (matches arch.mk logic)
40+
if get_option('spmathall')
2541
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_int.c']
26-
27-
# Add Cortex-M optimized SP math if building for ARM Cortex-M and assembly is enabled
28-
# Only include when actually cross-compiling for ARM (not on native x86_64)
29-
if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm') and meson.is_cross_build()
30-
cortex_m_targets = (
31-
get_option('cortex_m0')
32-
or get_option('cortex_m3')
33-
or get_option('cortex_m33')
34-
or get_option('cortex_m7')
35-
)
36-
if cortex_m_targets
37-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_cortexm.c']
38-
# Add corresponding compiler flags - these will be handled by parent
39-
# wolfcrypt_c_args += ['-DWOLFSSL_SP_ASM', '-DWOLFSSL_SP_ARM_CORTEX_M_ASM']
40-
# if get_option('cortex_m7')
41-
# wolfcrypt_c_args += ['-DWOLFSSL_ARM_ARCH=7']
42-
# elif get_option('cortex_m3')
43-
# wolfcrypt_c_args += ['-DWOLFSSL_SP_NO_UMAAL', '-DWOLFSSL_ARM_ARCH=7']
44-
# endif
45-
else
46-
# Default to C implementation for other ARM targets
47-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c']
48-
endif
42+
if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm')
43+
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_cortexm.c']
4944
else
50-
# Use C implementation when assembly is disabled or not cross-compiling
51-
if arch == 'ARM' or arch == 'AARCH64'
52-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c']
53-
elif arch == 'x86_64'
54-
# x86_64 specific SP math handling
55-
if get_option('no_asm')
56-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c64.c']
57-
else
58-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_x86_64.c']
59-
endif
60-
else
61-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c64.c']
62-
endif
45+
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c']
46+
endif
47+
elif get_option('spmath')
48+
# SP Math
49+
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_int.c']
50+
if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm')
51+
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_cortexm.c']
52+
else
53+
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c']
6354
endif
6455
else
56+
# Fastmath
6557
wolfcrypt_sources += [
6658
'wolfssl/wolfcrypt/src/integer.c',
6759
'wolfssl/wolfcrypt/src/tfm.c',
6860
]
6961
endif
7062

71-
# Signature algorithm specific sources (matching options.mk)
72-
if sign == 'ECC256' or sign == 'ECC384' or sign == 'ECC521'
63+
# Signature algorithm sources
64+
if sign in ['ECC256', 'ECC384', 'ECC521']
65+
# Elliptic Curve Cryptography
7366
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/ecc.c']
7467
elif sign == 'ED25519'
68+
# Edwards-curve Digital Signature Algorithm (25519)
7569
wolfcrypt_sources += [
70+
'wolfssl/wolfcrypt/src/sha512.c',
7671
'wolfssl/wolfcrypt/src/ed25519.c',
7772
'wolfssl/wolfcrypt/src/ge_low_mem.c',
7873
'wolfssl/wolfcrypt/src/fe_low_mem.c',
79-
'wolfssl/wolfcrypt/src/sha512.c',
8074
]
8175
elif sign == 'ED448'
76+
# Edwards-curve Digital Signature Algorithm (448)
8277
wolfcrypt_sources += [
8378
'wolfssl/wolfcrypt/src/ed448.c',
8479
'wolfssl/wolfcrypt/src/ge_low_mem.c',
8580
'wolfssl/wolfcrypt/src/ge_448.c',
8681
'wolfssl/wolfcrypt/src/fe_448.c',
8782
'wolfssl/wolfcrypt/src/fe_low_mem.c',
8883
]
89-
# ED448 adds SHA3 if HASH is not already SHA3 (from options.mk)
90-
if hash != 'SHA3'
84+
if hash_alg != 'SHA3'
9185
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha3.c']
9286
endif
9387
elif sign.startswith('RSA')
88+
# RSA signature algorithm
9489
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/rsa.c']
9590
elif sign == 'LMS'
91+
# Leighton-Micali Signatures
9692
wolfcrypt_sources += [
9793
'wolfssl/wolfcrypt/src/wc_lms.c',
9894
'wolfssl/wolfcrypt/src/wc_lms_impl.c',
9995
]
10096
elif sign == 'XMSS'
97+
# eXtended Merkle Signature Scheme
10198
wolfcrypt_sources += [
10299
'wolfssl/wolfcrypt/src/wc_xmss.c',
103100
'wolfssl/wolfcrypt/src/wc_xmss_impl.c',
104101
]
105102
elif sign == 'ML_DSA'
106-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/dilithium.c']
107-
# ML_DSA adds SHA3 if HASH is not already SHA3 (from options.mk)
108-
if hash != 'SHA3'
103+
# Module-Lattice-Based Digital Signature Algorithm (Dilithium)
104+
wolfcrypt_sources += [
105+
'wolfssl/wolfcrypt/src/dilithium.c',
106+
]
107+
if hash_alg != 'SHA3'
109108
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha3.c']
110109
endif
111110
endif
112111

113-
# Hash algorithm specific sources
114-
if hash == 'SHA384'
112+
# Hash algorithm sources
113+
if hash_alg == 'SHA384'
115114
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha512.c']
116-
elif hash == 'SHA3'
115+
elif hash_alg == 'SHA3'
117116
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha3.c']
118117
endif
119118

120-
# Encryption sources
121-
if encrypt
122-
if get_option('encrypt_with_chacha')
123-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/chacha.c']
124-
elif get_option('encrypt_with_aes128') or get_option('encrypt_with_aes256')
119+
# Encryption algorithm sources
120+
if encrypt_enabled
121+
if get_option('encrypt_with_aes128') or get_option('encrypt_with_aes256')
122+
# AES encryption (128-bit or 256-bit keys)
125123
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/aes.c']
124+
else
125+
# ChaCha20 stream cipher (default for encryption)
126+
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/chacha.c']
126127
endif
127128
endif
128129

129-
# Disk lock coding helper
130-
if get_option('disk_lock')
131-
wolfcrypt_sources += ['wolfssl/wolfcrypt/src/coding.c']
132-
endif
133-
134-
# TPM sources
135-
tpm_enabled = (
136-
get_option('wolfboot_tpm_verify')
137-
or get_option('measured_boot')
138-
or get_option('wolfboot_tpm_keystore')
139-
or get_option('wolfboot_tpm_seal')
140-
)
141-
142-
if tpm_enabled
143-
# Add additional wolfSSL crypto sources needed for TPM to wolfcrypt
144-
if fs.exists('wolfTPM')
145-
wolfcrypt_sources += [
146-
'wolfssl/wolfcrypt/src/aes.c',
147-
'wolfssl/wolfcrypt/src/hmac.c',
148-
'wolfssl/wolfcrypt/src/random.c',
149-
]
150-
endif
151-
endif
152-
153-
# Get compiler args and include dirs from parent
154-
wolfcrypt_c_args = c_args # Use parent's c_args
155-
wolfcrypt_inc_dirs = inc_dirs # Use parent's inc_dirs
156-
157-
# Add ARM Cortex-M assembly optimization flags (matching CMakeLists.txt behavior)
158-
if arch == 'ARM' and meson.is_cross_build()
159-
cortex_m_targets = (
160-
get_option('cortex_m0')
161-
or get_option('cortex_m3')
162-
or get_option('cortex_m33')
163-
or get_option('cortex_m7')
164-
)
165-
if cortex_m_targets and not get_option('no_asm') and not get_option('no_arm_asm')
166-
wolfcrypt_c_args += ['-DWOLFSSL_SP_ASM', '-DWOLFSSL_SP_ARM_CORTEX_M_ASM']
167-
if get_option('cortex_m7')
168-
wolfcrypt_c_args += ['-DWOLFSSL_ARM_ARCH=7']
169-
elif get_option('cortex_m3')
170-
wolfcrypt_c_args += ['-DWOLFSSL_SP_NO_UMAAL', '-DWOLFSSL_ARM_ARCH=7']
171-
endif
172-
endif
173-
endif
174-
175-
wolfcrypt_build_inc_dirs = []
176-
177-
# WolfSSL include directory
178-
wolfssl_inc = include_directories('wolfssl')
179-
180-
# Build WolfCrypt library (cryptographic functions)
130+
# Build the wolfCrypt static library
181131
libwolfcrypt = static_library(
182132
'wolfcrypt',
183133
wolfcrypt_sources,
184-
include_directories: [wolfcrypt_inc_dirs, wolfcrypt_build_inc_dirs, wolfssl_inc],
185-
c_args: wolfcrypt_c_args + ['-Wno-unused', '-Wno-array-bounds'],
134+
include_directories: inc_dirs,
135+
c_args: c_args + ['-Wno-unused'],
186136
install: false,
187137
)
188138

189-
# WolfTPM library (if TPM support is enabled and not a subproject)
139+
# Optional WolfTPM library (compile from sources if present)
190140
libwolftpm = []
191-
wolftpm_sources = []
192-
if tpm_enabled and fs.exists('wolfTPM') and not meson.is_subproject()
193-
wolftpm_sources = [
194-
'wolfTPM/src/tpm2.c',
195-
'wolfTPM/src/tpm2_packet.c',
196-
'wolfTPM/src/tpm2_tis.c',
197-
'wolfTPM/src/tpm2_wrap.c',
198-
'wolfTPM/src/tpm2_param_enc.c',
199-
]
200-
201-
wolftpm_inc = include_directories('wolfTPM')
202-
141+
if tpm_enabled and fs.exists('wolfTPM')
142+
inc_dirs_tpm = [inc_dirs, include_directories('wolfTPM')]
203143
libwolftpm = static_library(
204144
'wolftpm',
205-
wolftpm_sources,
206-
include_directories: [wolfcrypt_inc_dirs, wolfcrypt_build_inc_dirs, wolfssl_inc, wolftpm_inc],
207-
c_args: wolfcrypt_c_args,
145+
[
146+
'wolfTPM/src/tpm2.c',
147+
'wolfTPM/src/tpm2_packet.c',
148+
'wolfTPM/src/tpm2_tis.c',
149+
'wolfTPM/src/tpm2_wrap.c',
150+
'wolfTPM/src/tpm2_param_enc.c',
151+
],
152+
include_directories: inc_dirs_tpm,
153+
c_args: c_args,
208154
install: false,
209155
)
210156
endif
157+
158+
# Export dependency for parent build system
159+
wolfcrypt_dep = declare_dependency(
160+
include_directories: inc_dirs,
161+
link_with: [libwolfcrypt],
162+
compile_args: c_args,
163+
)
164+
165+
# Export wolfTPM library variable for parent to access
166+
# Note: Set a variable that can be checked by parent
167+
wolfcrypt_has_tpm = libwolftpm != []

0 commit comments

Comments
 (0)