Skip to content

Commit

Permalink
openssl: Make it build with MSVC
Browse files Browse the repository at this point in the history
MSVC needs a way of knowing which symbols are supposed to be exported,
otherwise it does not create a DLL. This means the wrap was previously
unusable as a shared library.

The OpenSSL build process does that by passing a `.def` file to the
linker. This reimplements OpenSSL's `util/mkdef.pl` script to make the
meson build do the same as the normal build process.

Fixes mesonbuild#181.
  • Loading branch information
hrxi authored and neheb committed Nov 22, 2023
1 parent a2a6bdf commit 779a7d5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,7 @@
"openssl"
],
"versions": [
"3.0.8-2",
"3.0.8-1",
"3.0.7-2",
"3.0.7-1",
Expand Down
53 changes: 53 additions & 0 deletions subprojects/packagefiles/openssl/generate_def.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sys

EXTRA_CRYPTO = """\
WPACKET_allocate_bytes
WPACKET_cleanup
WPACKET_close
WPACKET_fill_lengths
WPACKET_finish
WPACKET_get_curr
WPACKET_get_length
WPACKET_get_total_written
WPACKET_init
WPACKET_init_static_len
WPACKET_memcpy
WPACKET_memset
WPACKET_put_bytes__
WPACKET_reserve_bytes
WPACKET_set_flags
WPACKET_start_sub_packet
WPACKET_start_sub_packet_len__
WPACKET_sub_allocate_bytes__
WPACKET_sub_memcpy__
WPACKET_sub_reserve_bytes__
ssl3_cbc_digest_record
ssl3_cbc_remove_padding_and_mac
tls1_cbc_remove_padding_and_mac
""".splitlines()

def main():
import argparse
p = argparse.ArgumentParser(description="Convert OpenSSL .num files into .def files")
p.add_argument("--fixup-crypto", action="store_true", help="crypto.dll-specific fixups")
args = p.parse_args()

input = sys.stdin.read()
lines = [line.split() for line in input.splitlines()]
data = [tuple([name, ordinal] + tags.split(":")) for name, ordinal, _, tags in lines]

print("EXPORTS")
for name, ordinal, exists, system, _, tags, *_ in data:
if exists != "EXIST":
continue
if system and not system.startswith("!"):
continue
if any(tag in "COMP CRYPTO_MDEBUG DGRAM EC_NISTP_64_GCC_128 EGD MD2 RC5 SSL3_METHOD UNIT_TEST".split() for tag in tags.split(",")):
continue
print(" {} @{}".format(name, ordinal))
if args.fixup_crypto:
for name in EXTRA_CRYPTO:
print(" {}".format(name))

if __name__ == "__main__":
sys.exit(main())
3 changes: 3 additions & 0 deletions subprojects/packagefiles/openssl/generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set -e

cd "$(dirname "${BASH_SOURCE[0]}")"

python3 generate_def.py --fixup-crypto < util/libcrypto.num > crypto.def
python3 generate_def.py < util/libssl.num > ssl.def

# Node.js version should bundle OpenSSL of matching version to one specified in wrap file
node_version=v19.7.0
openssl_version="$OPENSSL_VERSION"
Expand Down
2 changes: 2 additions & 0 deletions subprojects/packagefiles/openssl/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ libcrypto_lib = library(
sources: libcrypto_sources,
include_directories: include_directories,
c_args: c_args,
vs_module_defs: 'crypto.def',
install: true,
)

Expand All @@ -356,6 +357,7 @@ libssl_lib = library(
sources: libssl_sources,
include_directories: include_directories,
c_args: c_args,
vs_module_defs: 'ssl.def',
install: true,
)

Expand Down
1 change: 1 addition & 0 deletions tools/sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'bn_conf.h',
'dso_conf.h',
'buildinf.h',
'generate_def.py',
'generate_gypi.pl.patch',
'meson.build.tmpl',
'README.md',
Expand Down

0 comments on commit 779a7d5

Please sign in to comment.