Skip to content

Commit

Permalink
openresty: bundle openssl and debug formula (#244)
Browse files Browse the repository at this point in the history
* add formulas (openresty, openresty-openssl and openresty-debug) 
* fix problems detected by `brew audit --strict --online`
  • Loading branch information
moonming authored and denji committed Jan 12, 2017
1 parent e25a12a commit ba25901
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 55 deletions.
92 changes: 92 additions & 0 deletions Formula/openresty-debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
class OpenrestyDebug < Formula
desc "Scalable Web Platform by Extending NGINX with Lua"
homepage "http://openresty.org"
VERSION = "1.11.2.2".freeze
url "https://openresty.org/download/openresty-#{VERSION}.tar.gz"
sha256 "7f9ca62cfa1e4aedf29df9169aed0395fd1b90de254139996e554367db4d5a01"

depends_on "pcre"
depends_on "homebrew/nginx/openresty-openssl"
depends_on "geoip"

skip_clean "site"
skip_clean "pod"
skip_clean "nginx"
skip_clean "luajit"

def install
# Configure
cc_opt = "-I#{HOMEBREW_PREFIX}/include -I#{Formula["pcre"].opt_include} -I#{Formula["openresty-openssl"].opt_include}"
ld_opt = "-L#{HOMEBREW_PREFIX}/lib -L#{Formula["pcre"].opt_lib} -L#{Formula["openresty-openssl"].opt_lib}"

args = %W[
--prefix=#{prefix}
--with-debug
--with-cc-opt=#{cc_opt}
--with-ld-opt=#{ld_opt}
--with-pcre-jit
--without-http_rds_json_module
--without-http_rds_csv_module
--without-lua_rds_parser
--with-ipv6
--with-stream
--with-stream_ssl_module
--with-http_v2_module
--without-mail_pop3_module
--without-mail_imap_module
--without-mail_smtp_module
--with-http_stub_status_module
--with-http_realip_module
--with-http_addition_module
--with-http_auth_request_module
--with-http_secure_link_module
--with-http_random_index_module
--with-http_geoip_module
--with-http_gzip_static_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-threads
--with-luajit-xcflags=-DLUAJIT_NUMMODE=2\ -DLUAJIT_ENABLE_LUA52COMPAT
--with-dtrace-probes
]

system "./configure", *args

# Install
system "make"
system "make", "install"
end

plist_options :manual => "openresty"

def plist; <<-EOS.undent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>#{opt_prefix}/bin/openresty</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>WorkingDirectory</key>
<string>#{HOMEBREW_PREFIX}</string>
</dict>
</plist>
EOS
end

test do
system "#{bin}/openresty", "-V"
end
end
64 changes: 64 additions & 0 deletions Formula/openresty-openssl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class OpenrestyOpenssl < Formula
desc "This OpenSSL library build is specifically for OpenResty uses"
homepage "https://www.openssl.org/"
VERSION = "1.0.2j".freeze

stable do
url "https://www.openssl.org/source/openssl-#{VERSION}.tar.gz"
mirror "https://dl.bintray.com/homebrew/mirror/openssl-1#{VERSION}.tar.gz"
mirror "https://www.mirrorservice.org/sites/ftp.openssl.org/source/openssl-#{VERSION}.tar.gz"
sha256 "e7aff292be21c259c6af26469c7a9b3ba26e9abaaffd325e3dccc9785256c431"

patch do
url "https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-1.0.2h-sess_set_get_cb_yield.patch"
sha256 "6d6e02c21769784b106b62a146bfbfeac54884e23520c8dd29b74f3e1348d4a1"
end
end

def install
# OpenSSL will prefer the PERL environment variable if set over $PATH
# which can cause some odd edge cases & isn't intended. Unset for safety.
ENV.delete("PERL")

# Load zlib from an explicit path instead of relying on dyld's fallback
# path, which is empty in a SIP context. This patch will be unnecessary
# when we begin building openssl with no-comp to disable TLS compression.
# https://langui.sh/2015/11/27/sip-and-dlopen
inreplace "crypto/comp/c_zlib.c",
'zlib_dso = DSO_load(NULL, "z", NULL, 0);',
'zlib_dso = DSO_load(NULL, "/usr/lib/libz.dylib", NULL, DSO_FLAG_NO_NAME_TRANSLATION);'

args = [
"no-threads",
"shared",
"zlib",
"-g",
"--openssldir=#{prefix}",
"--libdir=lib",
]

if MacOS.prefer_64_bit?
args << "darwin64-x86_64-cc"
args << "enable-ec_nistp_64_gcc_128"
else
args << "darwin-i386-cc"
end

system "./Configure", *args

# Install
system "make"
system "make", "install", "MANDIR=#{man}"
end

test do
# Check OpenSSL itself functions as expected.
(testpath/"testfile.txt").write("This is a test file")
expected_checksum = "e2d0fe1585a63ec6009c8016ff8dda8b17719a637405a4e23c0ff81339148249"
system "#{bin}/openssl", "dgst", "-sha256", "-out", "checksum.txt", "testfile.txt"
open("checksum.txt") do |f|
checksum = f.read(100).split("=").last.strip
assert_equal checksum, expected_checksum
end
end
end
102 changes: 47 additions & 55 deletions Formula/openresty.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,61 @@
class Openresty < Formula
desc "Scalable Web Platform by Extending NGINX with Lua"
homepage "http://openresty.org"
url "https://openresty.org/download/openresty-1.11.2.2.tar.gz"
VERSION = "1.11.2.2".freeze
url "https://openresty.org/download/openresty-#{VERSION}.tar.gz"
sha256 "7f9ca62cfa1e4aedf29df9169aed0395fd1b90de254139996e554367db4d5a01"

# nginx options
option "without-luajit", "Compile *without* support for the Lua Just-In-Time Compiler"
option "with-postgresql", "Compile with support for direct communication with PostgreSQL database servers"
option "with-iconv", "Compile with support for converting character encodings"
option "with-debug", "Compile with support for debug logging but without proper gdb debugging symbols"
option "without-ipv6", "Compile *without* support for IPv6"

# nginx options
option "with-webdav", "Compile with ngx_http_dav_module"
option "with-gunzip", "Compile with ngx_http_gunzip_module"
option "with-geoip", "Compile with ngx_http_geoip_module"
option "with-stub_status", "Compile with ngx_http_stub_status_module"
option "with-slice", "Compile with ngx_http_slice_module"

depends_on "pcre"
depends_on "openssl"
depends_on "postgresql" => :optional
depends_on "geoip" => :optional
depends_on "homebrew/nginx/openresty-openssl"
depends_on "geoip"

skip_clean "site"
skip_clean "pod"
skip_clean "nginx"
skip_clean "luajit"

def install
# Configure
cc_opt = "-I#{HOMEBREW_PREFIX}/include -I#{Formula["pcre"].opt_include}"
ld_opt = "-L#{HOMEBREW_PREFIX}/lib -L#{Formula["pcre"].opt_lib}"
args = [
"--prefix=#{prefix}",
"--pid-path=#{var}/run/openresty.pid",
"--lock-path=#{var}/run/openresty.lock",
"--conf-path=#{etc}/openresty/nginx.conf",
"--http-log-path=#{var}/log/nginx/access.log",
"--error-log-path=#{var}/log/nginx/error.log",
"--with-pcre",
"--with-pcre-jit",
"--with-cc-opt=#{cc_opt}",
"--with-ld-opt=#{ld_opt}",
]
cc_opt = "-I#{HOMEBREW_PREFIX}/include -I#{Formula["pcre"].opt_include} -I#{Formula["openresty-openssl"].opt_include}"
ld_opt = "-L#{HOMEBREW_PREFIX}/lib -L#{Formula["pcre"].opt_lib} -L#{Formula["openresty-openssl"].opt_lib}"

# OpenResty options
args << "--with-lua51" if build.without? "luajit"
args << "--with-http_dav_module" if build.with? "webdav"
args << "--with-http_gunzip_module" if build.with? "gunzip"
args << "--with-http_geoip_module" if build.with? "geoip"
args << "--with-http_stub_status_module" if build.with? "stub_status"
args << "--with-http_postgres_module" if build.with? "postgresql"
args << "--with-http_iconv_module" if build.with? "iconv"
args << "--with-http_slice_module" if build.with? "slice"
args << "--with-ipv6" if build.with? "ipv6"
args = %W[
--prefix=#{prefix}
--with-cc-opt=#{cc_opt}
--with-ld-opt=#{ld_opt}
--with-pcre-jit
--without-http_rds_json_module
--without-http_rds_csv_module
--without-lua_rds_parser
--with-ipv6
--with-stream
--with-stream_ssl_module
--with-http_v2_module
--without-mail_pop3_module
--without-mail_imap_module
--without-mail_smtp_module
--with-http_stub_status_module
--with-http_realip_module
--with-http_addition_module
--with-http_auth_request_module
--with-http_secure_link_module
--with-http_random_index_module
--with-http_geoip_module
--with-http_gzip_static_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-threads
--with-luajit-xcflags=-DLUAJIT_NUMMODE=2\ -DLUAJIT_ENABLE_LUA52COMPAT
--with-dtrace-probes
]

# Debugging mode, unfortunately without debugging symbols
if build.with? "debug"
args << "--with-debug"
args << "--with-dtrace-probes"
args << "--with-no-pool-patch"

# this allows setting of `debug.sethook` in luajit
if build.with? "luajit"
args << "--with-luajit-xcflags=-DLUAJIT_ENABLE_CHECKHOOK"
end

opoo "Openresty will be built --with-debug option, but without debugging symbols."\
"For debugging symbols you have to compile it by hand."
end

system "./configure", *args
Expand All @@ -73,10 +65,6 @@ def install
system "make", "install"
end

test do
system "#{bin}/openresty", '-V'
end

plist_options :manual => "openresty"

def plist; <<-EOS.undent
Expand All @@ -102,4 +90,8 @@ def plist; <<-EOS.undent
</plist>
EOS
end

test do
system "#{bin}/openresty", "-V"
end
end

0 comments on commit ba25901

Please sign in to comment.