Skip to content

Commit

Permalink
Support OpenSSL on MSYS2 (crystal-lang#15111)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored and CTC97 committed Nov 9, 2024
1 parent 53719be commit da3df17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/openssl/lib_crypto.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% begin %}
lib LibCrypto
{% if flag?(:win32) %}
{% if flag?(:msvc) %}
{% from_libressl = false %}
{% ssl_version = nil %}
{% for dir in Crystal::LIBRARY_PATH.split(Crystal::System::Process::HOST_PATH_DELIMITER) %}
Expand All @@ -13,10 +13,12 @@
{% end %}
{% ssl_version ||= "0.0.0" %}
{% else %}
{% from_libressl = (`hash pkg-config 2> /dev/null || printf %s false` != "false") &&
(`test -f $(pkg-config --silence-errors --variable=includedir libcrypto)/openssl/opensslv.h || printf %s false` != "false") &&
(`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") %}
{% ssl_version = `hash pkg-config 2> /dev/null && pkg-config --silence-errors --modversion libcrypto || printf %s 0.0.0`.split.last.gsub(/[^0-9.]/, "") %}
# these have to be wrapped in `sh -c` since for MinGW-w64 the compiler
# passes the command string to `LibC.CreateProcessW`
{% from_libressl = (`sh -c 'hash pkg-config 2> /dev/null || printf %s false'` != "false") &&
(`sh -c 'test -f $(pkg-config --silence-errors --variable=includedir libcrypto)/openssl/opensslv.h || printf %s false'` != "false") &&
(`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") %}
{% 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.]/, "") %}
{% end %}

{% if from_libressl %}
Expand Down
12 changes: 7 additions & 5 deletions src/openssl/lib_ssl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "./lib_crypto"

{% begin %}
lib LibSSL
{% if flag?(:win32) %}
{% if flag?(:msvc) %}
{% from_libressl = false %}
{% ssl_version = nil %}
{% for dir in Crystal::LIBRARY_PATH.split(Crystal::System::Process::HOST_PATH_DELIMITER) %}
Expand All @@ -19,10 +19,12 @@ require "./lib_crypto"
{% end %}
{% ssl_version ||= "0.0.0" %}
{% else %}
{% from_libressl = (`hash pkg-config 2> /dev/null || printf %s false` != "false") &&
(`test -f $(pkg-config --silence-errors --variable=includedir libssl)/openssl/opensslv.h || printf %s false` != "false") &&
(`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") %}
{% ssl_version = `hash pkg-config 2> /dev/null && pkg-config --silence-errors --modversion libssl || printf %s 0.0.0`.split.last.gsub(/[^0-9.]/, "") %}
# these have to be wrapped in `sh -c` since for MinGW-w64 the compiler
# passes the command string to `LibC.CreateProcessW`
{% from_libressl = (`sh -c 'hash pkg-config 2> /dev/null || printf %s false'` != "false") &&
(`sh -c 'test -f $(pkg-config --silence-errors --variable=includedir libssl)/openssl/opensslv.h || printf %s false'` != "false") &&
(`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") %}
{% 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.]/, "") %}
{% end %}

{% if from_libressl %}
Expand Down

0 comments on commit da3df17

Please sign in to comment.