Skip to content

Commit d5172ce

Browse files
committed
(maint) Use packaged libxml to build nokogiri on MacOS
This PR changes the gem install command for the Nokogiri gem. Currently when building nokogiri it uses the system libxml2 and libxslt. We now will pass in an option in the `gem install` command to use the expected libraries. Also on MacOS we now set the 'pkgconfig' path as an env variable when building Nokogiri.
1 parent 71e0463 commit d5172ce

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

configs/components/_base-rubygem.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
pkg.url("https://rubygems.org/downloads/#{name}-#{version}.gem")
3838
pkg.mirror("#{settings[:buildsources_url]}/#{name}-#{version}.gem")
3939

40-
pkg.install do
41-
"#{settings[:gem_install]} #{name}-#{version}.gem"
40+
# If a gem needs more command line options to install set the :gem_install_options
41+
# in its component file rubygem-<compoment>, before the instance_eval of this file.
42+
if settings[:gem_install_options].nil?
43+
pkg.install do
44+
"#{settings[:gem_install]} #{name}-#{version}.gem"
45+
end
46+
else
47+
pkg.install do
48+
"#{settings[:gem_install]} #{name}-#{version}.gem #{settings[:gem_install_options]}"
49+
end
4250
end
51+
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
component 'rubygem-nokogiri' do |pkg, _settings, _platform|
22
pkg.version '1.14.2'
33
pkg.sha256sum 'c765a74aac6cf430a710bb0b6038b8ee11f177393cd6ae8dadc7a44a6e2658b6'
4+
if platform.is_macos?
5+
settings[:gem_install_options] = "--use-system-libraries \
6+
--with-xml2-lib=#{settings[:libdir]} \
7+
--with-xml2-include=#{settings[:includedir]}/libxml2 \
8+
--with-xslt-lib=#{settings[:libdir]} \
9+
--with-xslt-include=#{settings[:includedir]}"
10+
end
411
instance_eval File.read('configs/components/_base-rubygem.rb')
5-
612
pkg.build_requires 'rubygem-mini_portile2'
7-
813
gem_home = settings[:gem_home]
914
pkg.environment "GEM_HOME", gem_home
10-
11-
# When cross compiling nokogiri native extensions on macOS 11/12 ARM, there is a 94M tmp
12-
# directory that's not needed
13-
if platform.is_macos? && platform.architecture == 'arm64'
14-
install do
15-
"rm -r #{gem_home}/gems/nokogiri-#{pkg.get_version}/ext/nokogiri/tmp"
15+
if platform.is_macos?
16+
pkg.environment "PKG_CONFIG_PATH", "#{settings[:libdir]}/pkgconfig"
17+
if platform.is_cross_compiled?
18+
pkg.install do
19+
"rm -r #{gem_home}/gems/nokogiri-#{pkg.get_version}/ext/nokogiri/tmp"
20+
end
1621
end
1722
end
1823
end

0 commit comments

Comments
 (0)