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
Replaced homebrew specific hacks with pkg-config
  • Loading branch information
lvmbdv committed Mar 24, 2018
commit eb71557663f67f9225c66094a7529477545a3b06
3 changes: 2 additions & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ prepare_build() {

on_linux docker pull "jhass/crystal-build-$ARCH"

on_osx brew install crystal-lang
on_osx brew install crystal-lang pkg-config

# Make sure binaries from llvm are available in PATH
on_osx brew install jq
Expand Down Expand Up @@ -123,6 +123,7 @@ with_build_env() {
on_osx sudo systemsetup -settimezone $TZ
on_osx PATH="/usr/local/opt/llvm/bin:\$PATH" \
CRYSTAL_CACHE_DIR="/tmp/crystal" \
PKG_CONFIG_PATH="$(brew --prefix)/opt/openssl/lib/pkgconfig:$PKG_CONFIG_PATH" \
/bin/sh -c "'$command'"

}
Expand Down
22 changes: 5 additions & 17 deletions src/openssl/lib_crypto.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
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)`.
# On newer OS X systems, the OpenSSL/LibreSSL library supplied by the system may be newer than homebrew ones. If you wish to use them, set the compilation flag OPENSSL_NOBREW.
# Also on OS X, set the compilation flag LIBRESSL_BREW to use the libressl provided by homebrew.
LIBRESSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER\" | " + (env("CC") || "cc") +
((flag?(:darwin) && !flag?(:OPENSSL_NOBREW)) ? (" -I" + system("command -v brew > /dev/null && brew --prefix " + (flag?(:LIBRESSL_BREW) ? "libressl" : "openssl")).chomp.stringify + "/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) && !flag?(:OPENSSL_NOBREW)) ? (" -I" + system("command -v brew > /dev/null && brew --prefix " + (flag?(:LIBRESSL_BREW) ? "libressl" : "openssl")).chomp.stringify + "/include") : "") +
" -E -").chomp.split('\n').last.split('L').first.id }}
LIBRESSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nLIBRESSL_VERSION_NUMBER\" | " +
(env("CC") || "cc") + " " + `pkg-config --cflags --silence-errors libssl || true`.chomp.stringify + " -E -").chomp.split('\n').last.split('L').first.id + "0" }}
OPENSSL_VERSION = {{ system("echo \"#include <openssl/opensslv.h>\nOPENSSL_VERSION_NUMBER\" | " +
(env("CC") || "cc") + " " + `pkg-config --cflags --silence-errors libssl || true`.chomp.stringify + " -E -").chomp.split('\n').last.split('L').first.id }}
end
{% end %}

Expand All @@ -21,15 +17,7 @@
end
{% end %}

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

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