Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed OpenSSL bindings to recognize LibreSSL #5676

Merged
merged 7 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed OpenSSL linking on OS X
  • Loading branch information
lvmbdv committed Mar 24, 2018
commit 4c106f5a8d4707f41c14968d2d4a2774f7e36d02
12 changes: 10 additions & 2 deletions src/openssl/lib_crypto.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
lib LibCrypto
# An extra zero is appended to the output of LIBRESSL_VERSION to make it 0 when LibreSSL does not exist on the system.
# Any comparisons to it should be affixed with an extra zero as well e.g. `(LIBRESSL_VERSION_NUMBER >= 0x2050500F0)`.
LIBRESSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER\" | " + (env("CC") || "cc") + (flag?(:darwin) ? " -I/usr/local/opt/openssl/include" : "") + " -E -").chomp.split('\n').last.split('L').first.id + "0" }}
OPENSSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nOPENSSL_VERSION_NUMBER\" | " + (env("CC") || "cc") + (flag?(:darwin) ? " -I/usr/local/opt/openssl/include" : "") + " -E -").chomp.split('\n').last.split('L').first.id }}
LIBRESSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER\" | " + (env("CC") || "cc") +
(flag?(:darwin) ? (" -I" + `command -v brew > /dev/null && brew --prefix || echo '/usr/local'`.chomp.stringify + "/opt/openssl/include") : "") +
" -E -").chomp.split('\n').last.split('L').first.id + "0" }}
OPENSSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nOPENSSL_VERSION_NUMBER\" | " + (env("CC") || "cc") +
(flag?(:darwin) ? (" -I" + `command -v brew > /dev/null && brew --prefix || echo '/usr/local'`.chomp.stringify + "/opt/openssl/include") : "") +
" -E -").chomp.split('\n').last.split('L').first.id }}
end
{% end %}

Expand All @@ -14,6 +18,10 @@
end
{% end %}

# Check for brew's openssl libs on OS X
{% if flag?(:darwin) %}
@[Link(ldflags: "`(echo '-L'; command -v brew > /dev/null && brew --prefix || echo '/usr/local'; echo '/opt/openssl/lib') | tr -d '\n'`")]
{% end %}
@[Link(ldflags: "`command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'`")]
lib LibCrypto
alias Char = LibC::Char
Expand Down
4 changes: 4 additions & 0 deletions src/openssl/lib_ssl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ require "./lib_crypto"
end
{% end %}

# Check for brew's openssl libs on OS X
{% if flag?(:darwin) %}
@[Link(ldflags: "`(echo '-L'; command -v brew > /dev/null && brew --prefix || echo '/usr/local'; echo '/opt/openssl/lib') | tr -d '\n'`")]
{% end %}
@[Link(ldflags: "`command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'`")]
lib LibSSL
alias Int = LibC::Int
Expand Down