@@ -69,7 +69,7 @@ class << recipe
6969 def configure
7070 envs = [ ]
7171 envs << "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /mingw|mswin/
72- envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /linux/
72+ envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /linux|darwin /
7373 execute ( 'configure' , [ 'env' , *envs , "./Configure" , openssl_platform , "threads" , "-static" , "CROSS_COMPILE=#{ host } -" , configure_prefix ] , altlog : "config.log" )
7474 end
7575 def compile
@@ -85,17 +85,34 @@ def install
8585 recipe . cook_and_activate
8686 end
8787
88- if RUBY_PLATFORM =~ /linux/
88+ if RUBY_PLATFORM =~ /linux|darwin /
8989 krb5_recipe = BuildRecipe . new ( "krb5" , KRB5_VERSION , [ KRB5_SOURCE_URI ] ) . tap do |recipe |
9090 class << recipe
9191 def work_path
9292 File . join ( super , "src" )
9393 end
94+ def configure
95+ if RUBY_PLATFORM =~/darwin/
96+ ENV [ "CC" ] = host [ /^.*[^\. \d ]/ ] + "-clang"
97+ ENV [ "CXX" ] = host [ /^.*[^\. \d ]/ ] + "-c++"
98+
99+ # Manually set the correct values for configure checks that libkrb5 won't be
100+ # able to perform because we're cross-compiling.
101+ ENV [ "krb5_cv_attr_constructor_destructor" ] = "yes"
102+ ENV [ "ac_cv_func_regcomp" ] = "yes"
103+ ENV [ "ac_cv_printf_positional" ] = "yes"
104+ end
105+ super
106+ end
94107 end
95108 # We specify -fcommon to get around duplicate definition errors in recent gcc.
96109 # See https://github.com/cockroachdb/cockroach/issues/49734
97110 recipe . configure_options << "CFLAGS=-fcommon#{ " -fPIC" if RUBY_PLATFORM =~ /linux/ } "
111+ recipe . configure_options << "LDFLAGS=-framework Kerberos" if RUBY_PLATFORM =~ /darwin/
98112 recipe . configure_options << "--without-keyutils"
113+ recipe . configure_options << "--disable-nls"
114+ recipe . configure_options << "--disable-silent-rules"
115+ recipe . configure_options << "--without-system-verto"
99116 recipe . configure_options << "krb5_cv_attr_constructor_destructor=yes"
100117 recipe . configure_options << "ac_cv_func_regcomp=yes"
101118 recipe . configure_options << "ac_cv_printf_positional=yes"
@@ -104,14 +121,28 @@ def work_path
104121 end
105122 end
106123
124+ # We build a libpq library file which static links OpenSSL and krb5.
125+ # Our builtin libpq is referenced in different ways depending on the OS:
126+ # - Window: Add the ports directory at runtime per RubyInstaller::Runtime.add_dll_directory
127+ # The file is called "libpq.dll"
128+ # - Linux: Add a rpath to pg_ext.so which references the ports directory.
129+ # The file is called "libpq-ruby-pg.so.1" to avoid loading of system libpq by accident.
130+ # - Macos: Add a reference with relative path in pg_ext.so to the ports directory.
131+ # The file is called "libpq-ruby-pg.1.dylib" to avoid loading of other libpq by accident.
132+ libpq_orig , libpq_rubypg = case RUBY_PLATFORM
133+ when /linux/ then [ "libpq.so.5" , "libpq-ruby-pg.so.1" ]
134+ when /darwin/ then [ "libpq.5.dylib" , "libpq-ruby-pg.1.dylib" ]
135+ # when /mingw/ then ["libpq.dll", "libpq.dll"] # renaming not needed
136+ end
137+
107138 postgresql_recipe = BuildRecipe . new ( "postgresql" , POSTGRESQL_VERSION , [ POSTGRESQL_SOURCE_URI ] ) . tap do |recipe |
108139 class << recipe
109140 def configure_defaults
110141 [
111142 "--target=#{ host } " ,
112143 "--host=#{ host } " ,
113144 '--with-openssl' ,
114- *( RUBY_PLATFORM =~/linux/ ? [ '--with-gssapi' ] : [ ] ) ,
145+ *( RUBY_PLATFORM =~/linux|darwin / ? [ '--with-gssapi' ] : [ ] ) ,
115146 '--without-zlib' ,
116147 '--without-icu' ,
117148 '--without-readline' ,
@@ -127,24 +158,24 @@ def install
127158 end
128159
129160 recipe . host = toolchain
130- recipe . configure_options << "CFLAGS=#{ " -fPIC" if RUBY_PLATFORM =~ /linux/ } "
131- recipe . configure_options << "LDFLAGS=-L#{ openssl_recipe . path } /lib -L#{ openssl_recipe . path } /lib64 -L#{ openssl_recipe . path } /lib-arm64 #{ "-Wl,-soname,libpq-ruby-pg.so.1 -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support" if RUBY_PLATFORM =~ /linux / } "
161+ recipe . configure_options << "CFLAGS=#{ " -fPIC" if RUBY_PLATFORM =~ /linux|darwin / } "
162+ recipe . configure_options << "LDFLAGS=-L#{ openssl_recipe . path } /lib -L#{ openssl_recipe . path } /lib64 -L#{ openssl_recipe . path } /lib-arm64 #{ "-Wl,-soname,#{ libpq_rubypg } -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support" if RUBY_PLATFORM =~ /linux/ } #{ "-Wl,-install_name,@loader_path/../../ports/ #{ gem_platform } /lib/ #{ libpq_rubypg } -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support -lresolv -framework Kerberos " if RUBY_PLATFORM =~ /darwin / } "
132163 recipe . configure_options << "LIBS=-lkrb5 -lcom_err -lk5crypto -lkrb5support -lresolv" if RUBY_PLATFORM =~ /linux/
133164 recipe . configure_options << "LIBS=-lssl -lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/
134165 recipe . configure_options << "CPPFLAGS=-I#{ openssl_recipe . path } /include"
135166 recipe . cook_and_activate
136167 end
137168
138169 # Use our own library name for libpq to avoid loading of system libpq by accident.
139- FileUtils . ln_sf File . join ( postgresql_recipe . port_path , "lib/libpq.so.5 " ) ,
140- File . join ( postgresql_recipe . port_path , "lib/libpq-ruby-pg.so.1 " )
170+ FileUtils . ln_sf File . join ( postgresql_recipe . port_path , "lib/#{ libpq_orig } " ) ,
171+ File . join ( postgresql_recipe . port_path , "lib/#{ libpq_rubypg } " )
141172 # Avoid dependency to external libgcc.dll on x86-mingw32
142- $LDFLAGS << " -static-libgcc"
173+ $LDFLAGS << " -static-libgcc" if RUBY_PLATFORM =~ /mingw|mswin/
143174 # Avoid: "libpq.so: undefined reference to `dlopen'" in cross-ruby-2.7.8
144- $LDFLAGS << " -Wl,--no-as-needed" if RUBY_PLATFORM !~ /aarch64/
145- # Find libpq in the ports directory coming from lib/3.3
175+ $LDFLAGS << " -Wl,--no-as-needed" if RUBY_PLATFORM !~ /aarch64|arm64|darwin /
176+ # Find libpq in the ports directory coming from lib/3.x
146177 # It is shared between all compiled ruby versions.
147- $LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{ gem_platform } /lib'"
178+ $LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{ gem_platform } /lib'" if RUBY_PLATFORM =~ /linux/
148179 # Don't use pg_config for cross build, but --with-pg-* path options
149180 dir_config ( 'pg' , "#{ postgresql_recipe . path } /include" , "#{ postgresql_recipe . path } /lib" )
150181
0 commit comments