Skip to content

Commit 5c7e9bc

Browse files
committed
Remove absolute paths from binaries which point to build directories
There are several absolute paths built into the binary. For instance fallback path to `pg_service.conf` or the fallback path to kerberos ccache file or the rpath included into the libpq or C-ext files. They can be avoided or fixed by disabling rpaths and by using `DESTDIR` instead of `--prefix` configure option. Fixes ged#666 The remaining rpath to libruby will probably be fixed by: rake-compiler/rake-compiler-dock#165 Also fix the `MAKEFLAGS` option. `MAKEOPTS` was wrong.
1 parent 2d950d4 commit 5c7e9bc

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ CrossLibraries.each do |xlib|
141141
bundle install --local &&
142142
#{ "rake install_darwin_mig[__arm64__]" if platform =~ /arm64-darwin/ }
143143
#{ "rake install_darwin_mig[__x86_64__]" if platform =~ /x86_64-darwin/ }
144-
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKEOPTS=-j`nproc` RUBY_CC_VERSION=#{RakeCompilerDock.ruby_cc_version("~>2.7", "~>3.0")}
144+
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKEFLAGS="-j`nproc` V=1" RUBY_CC_VERSION=#{RakeCompilerDock.ruby_cc_version("~>2.7", "~>3.0")}
145145
EOT
146146
end
147147
desc "Build the native binary gems"

ext/extconf.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def port_path
4949
"#{target}/#{RUBY_PLATFORM}"
5050
end
5151

52+
# Add "--prefix=/", to avoid our actual build install path compiled into the binary.
53+
# Instead use DESTDIR variable of make to set our install path.
54+
def configure_prefix
55+
"--prefix="
56+
end
57+
5258
def cook_and_activate
5359
checkpoint = File.join(self.target, "#{self.name}-#{self.version}-#{RUBY_PLATFORM}.installed")
5460
unless File.exist?(checkpoint)
@@ -70,13 +76,13 @@ def configure
7076
envs = []
7177
envs << "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /mingw|mswin/
7278
envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /linux|darwin/
73-
execute('configure', ['env', *envs, "./Configure", openssl_platform, "threads", "-static", "CROSS_COMPILE=#{host}-", configure_prefix], altlog: "config.log")
79+
execute('configure', ['env', *envs, "./Configure", openssl_platform, "threads", "-static", "CROSS_COMPILE=#{host}-", "--prefix=/"], altlog: "config.log")
7480
end
7581
def compile
7682
execute('compile', "#{make_cmd} build_libs")
7783
end
7884
def install
79-
execute('install', "#{make_cmd} install_dev")
85+
execute('install', "#{make_cmd} install_dev DESTDIR=#{path}")
8086
end
8187
end
8288

@@ -104,6 +110,9 @@ def configure
104110
end
105111
super
106112
end
113+
def install
114+
execute('install', "#{make_cmd} install DESTDIR=#{path}")
115+
end
107116
end
108117
# We specify -fcommon to get around duplicate definition errors in recent gcc.
109118
# See https://github.com/cockroachdb/cockroach/issues/49734
@@ -112,6 +121,7 @@ def configure
112121
recipe.configure_options << "--without-keyutils"
113122
recipe.configure_options << "--disable-nls"
114123
recipe.configure_options << "--disable-silent-rules"
124+
recipe.configure_options << "--disable-rpath"
115125
recipe.configure_options << "--without-system-verto"
116126
recipe.configure_options << "krb5_cv_attr_constructor_destructor=yes"
117127
recipe.configure_options << "ac_cv_func_regcomp=yes"
@@ -146,12 +156,13 @@ def configure_defaults
146156
'--without-zlib',
147157
'--without-icu',
148158
'--without-readline',
159+
'--disable-rpath',
149160
'ac_cv_search_gss_store_cred_into=',
150161
]
151162
end
152163
def compile
153-
execute 'compile include', "#{make_cmd} -C src/include install"
154-
execute 'compile interfaces', "#{make_cmd} -C src/interfaces install"
164+
execute 'compile include', "#{make_cmd} -C src/include install DESTDIR=#{path}"
165+
execute 'compile interfaces', "#{make_cmd} -C src/interfaces install DESTDIR=#{path}"
155166
end
156167
def install
157168
end
@@ -169,15 +180,16 @@ def install
169180
# Use our own library name for libpq to avoid loading of system libpq by accident.
170181
FileUtils.ln_sf File.join(postgresql_recipe.port_path, "lib/#{libpq_orig}"),
171182
File.join(postgresql_recipe.port_path, "lib/#{libpq_rubypg}")
183+
# Link to libpq_rubypg in our ports directory without adding it as rpath (like dir_config does)
184+
$CFLAGS << " -I#{postgresql_recipe.path}/include"
185+
$LDFLAGS << " -L#{postgresql_recipe.path}/lib"
172186
# Avoid dependency to external libgcc.dll on x86-mingw32
173187
$LDFLAGS << " -static-libgcc" if RUBY_PLATFORM =~ /mingw|mswin/
174188
# Avoid: "libpq.so: undefined reference to `dlopen'" in cross-ruby-2.7.8
175189
$LDFLAGS << " -Wl,--no-as-needed" if RUBY_PLATFORM !~ /aarch64|arm64|darwin/
176190
# Find libpq in the ports directory coming from lib/3.x
177191
# It is shared between all compiled ruby versions.
178192
$LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{gem_platform}/lib'" if RUBY_PLATFORM =~ /linux/
179-
# Don't use pg_config for cross build, but --with-pg-* path options
180-
dir_config('pg', "#{postgresql_recipe.path}/include", "#{postgresql_recipe.path}/lib")
181193

182194
$defs.push( "-DPG_IS_BINARY_GEM")
183195
else

0 commit comments

Comments
 (0)