Skip to content

Commit da3df17

Browse files
HertzDevilCTC97
authored andcommitted
Support OpenSSL on MSYS2 (crystal-lang#15111)
1 parent 53719be commit da3df17

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/openssl/lib_crypto.cr

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% begin %}
22
lib LibCrypto
3-
{% if flag?(:win32) %}
3+
{% if flag?(:msvc) %}
44
{% from_libressl = false %}
55
{% ssl_version = nil %}
66
{% for dir in Crystal::LIBRARY_PATH.split(Crystal::System::Process::HOST_PATH_DELIMITER) %}
@@ -13,10 +13,12 @@
1313
{% end %}
1414
{% ssl_version ||= "0.0.0" %}
1515
{% else %}
16-
{% from_libressl = (`hash pkg-config 2> /dev/null || printf %s false` != "false") &&
17-
(`test -f $(pkg-config --silence-errors --variable=includedir libcrypto)/openssl/opensslv.h || printf %s false` != "false") &&
18-
(`printf "#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER" | ${CC:-cc} $(pkg-config --cflags --silence-errors libcrypto || true) -E -`.chomp.split('\n').last != "LIBRESSL_VERSION_NUMBER") %}
19-
{% ssl_version = `hash pkg-config 2> /dev/null && pkg-config --silence-errors --modversion libcrypto || printf %s 0.0.0`.split.last.gsub(/[^0-9.]/, "") %}
16+
# these have to be wrapped in `sh -c` since for MinGW-w64 the compiler
17+
# passes the command string to `LibC.CreateProcessW`
18+
{% from_libressl = (`sh -c 'hash pkg-config 2> /dev/null || printf %s false'` != "false") &&
19+
(`sh -c 'test -f $(pkg-config --silence-errors --variable=includedir libcrypto)/openssl/opensslv.h || printf %s false'` != "false") &&
20+
(`sh -c 'printf "#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER" | ${CC:-cc} $(pkg-config --cflags --silence-errors libcrypto || true) -E -'`.chomp.split('\n').last != "LIBRESSL_VERSION_NUMBER") %}
21+
{% ssl_version = `sh -c 'hash pkg-config 2> /dev/null && pkg-config --silence-errors --modversion libcrypto || printf %s 0.0.0'`.split.last.gsub(/[^0-9.]/, "") %}
2022
{% end %}
2123

2224
{% if from_libressl %}

src/openssl/lib_ssl.cr

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require "./lib_crypto"
66

77
{% begin %}
88
lib LibSSL
9-
{% if flag?(:win32) %}
9+
{% if flag?(:msvc) %}
1010
{% from_libressl = false %}
1111
{% ssl_version = nil %}
1212
{% for dir in Crystal::LIBRARY_PATH.split(Crystal::System::Process::HOST_PATH_DELIMITER) %}
@@ -19,10 +19,12 @@ require "./lib_crypto"
1919
{% end %}
2020
{% ssl_version ||= "0.0.0" %}
2121
{% else %}
22-
{% from_libressl = (`hash pkg-config 2> /dev/null || printf %s false` != "false") &&
23-
(`test -f $(pkg-config --silence-errors --variable=includedir libssl)/openssl/opensslv.h || printf %s false` != "false") &&
24-
(`printf "#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER" | ${CC:-cc} $(pkg-config --cflags --silence-errors libssl || true) -E -`.chomp.split('\n').last != "LIBRESSL_VERSION_NUMBER") %}
25-
{% ssl_version = `hash pkg-config 2> /dev/null && pkg-config --silence-errors --modversion libssl || printf %s 0.0.0`.split.last.gsub(/[^0-9.]/, "") %}
22+
# these have to be wrapped in `sh -c` since for MinGW-w64 the compiler
23+
# passes the command string to `LibC.CreateProcessW`
24+
{% from_libressl = (`sh -c 'hash pkg-config 2> /dev/null || printf %s false'` != "false") &&
25+
(`sh -c 'test -f $(pkg-config --silence-errors --variable=includedir libssl)/openssl/opensslv.h || printf %s false'` != "false") &&
26+
(`sh -c 'printf "#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER" | ${CC:-cc} $(pkg-config --cflags --silence-errors libssl || true) -E -'`.chomp.split('\n').last != "LIBRESSL_VERSION_NUMBER") %}
27+
{% ssl_version = `sh -c 'hash pkg-config 2> /dev/null && pkg-config --silence-errors --modversion libssl || printf %s 0.0.0'`.split.last.gsub(/[^0-9.]/, "") %}
2628
{% end %}
2729

2830
{% if from_libressl %}

0 commit comments

Comments
 (0)