Skip to content

Commit 253c743

Browse files
committed
Get windows builds on github runners working again.
1 parent 613a11c commit 253c743

2 files changed

Lines changed: 42 additions & 48 deletions

File tree

Rakefile

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ Rake::ExtensionTask.new do |ext|
2121
ext.name = SO_NAME
2222
ext.ext_dir = "ext/libxml"
2323
ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d+$/, '')}"
24-
if RUBY_PLATFORM.match(/mingw/)
25-
ext.config_options <<
26-
if (dir = ENV['WINDOWS_XML2_INCLUDE'])
27-
"--with-xml2-include=#{dir}"
28-
else
29-
case RUBY_PLATFORM
30-
when 'i386-mingw32'
31-
'--with-xml2-include=C:/msys64/mingw32/include/libxml2'
32-
when 'x64-mingw32'
33-
'--with-xml2-include=C:/msys64/mingw64/include/libxml2'
34-
when 'x64-mingw-ucrt'
35-
'--with-xml2-include=C:/msys64/ucrt64/include/libxml2'
36-
else
37-
raise "Unknown Windows Ruby, please set ENV['WINDOWS_XML2_INCLUDE']"
38-
end
39-
end
40-
else
41-
ext.config_options << '--with-xml2-include=/usr/include/libxml2'
42-
end
4324
end
4425

4526
# Setup generic gem
@@ -49,21 +30,20 @@ Gem::PackageTask.new(spec) do |pkg|
4930
end
5031

5132
# Setup Windows Gem
52-
if RUBY_PLATFORM.match(/mswin|mingw/)
53-
binaries = (FileList['lib/**/*.so',
54-
'lib/**/*dll'])
33+
if RUBY_PLATFORM.match(/mingw/)
34+
binaries = (FileList['lib/**/*.so'])
5535

5636
# Windows specification
57-
win_spec = spec.clone
58-
win_spec.platform = Gem::Platform::CURRENT
59-
win_spec.files += binaries.to_a
60-
win_spec.instance_variable_set(:@cache_file, nil)
37+
mingw_spec = spec.clone
38+
mingw_spec.platform = Gem::Platform::CURRENT
39+
mingw_spec.files += binaries.to_a
40+
mingw_spec.instance_variable_set(:@cache_file, nil)
6141

6242
# Unset extensions
63-
win_spec.extensions = nil
43+
mingw_spec.extensions = nil
6444

6545
# Rake task to build the windows package
66-
Gem::PackageTask.new(win_spec) do |pkg|
46+
Gem::PackageTask.new(mingw_spec) do |pkg|
6747
pkg.package_dir = 'pkg'
6848
pkg.need_tar = false
6949
end

ext/libxml/extconf.rb

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,46 @@ def crash(str)
2323
end
2424
else
2525
dir_config('xml2')
26+
pkg_config('libxml-2.0')
2627
end
2728

28-
found_header = find_header('libxml/xmlversion.h',
29-
'/opt/include/libxml2',
30-
'/opt/local/include/libxml2',
31-
'/opt/homebrew/opt/libxml2/include/libxml2',
32-
'/usr/local/include/libxml2',
33-
'/usr/include/libxml2',
34-
'/usr/local/include',
35-
'/usr/local/opt/libxml2/include/libxml2')
29+
include_dirs = []
30+
lib_dirs = []
31+
32+
if (msystem_prefix = ENV['MSYSTEM_PREFIX']) && !msystem_prefix.empty?
33+
include_dirs.concat([
34+
"#{msystem_prefix}/include/libxml2",
35+
"#{msystem_prefix}/include"
36+
])
37+
lib_dirs << "#{msystem_prefix}/lib"
38+
end
39+
40+
include_dirs.concat([
41+
'/opt/include/libxml2',
42+
'/opt/local/include/libxml2',
43+
'/opt/homebrew/opt/libxml2/include/libxml2',
44+
'/usr/local/include/libxml2',
45+
'/usr/include/libxml2',
46+
'/usr/local/include',
47+
'/usr/local/opt/libxml2/include/libxml2'
48+
])
49+
50+
lib_dirs.concat([
51+
'/opt/lib',
52+
'/opt/local/lib',
53+
'/opt/homebrew/opt/libxml2/lib',
54+
'/usr/lib',
55+
'/usr/local/lib',
56+
'/usr/local/opt/libxml2/lib'
57+
])
58+
59+
found_header = find_header('libxml/xmlversion.h', *include_dirs)
3660

3761
found_lib = find_library('xml2', 'xmlParseDoc',
38-
'/opt/lib',
39-
'/opt/local/lib',
40-
'/opt/homebrew/opt/libxml2/lib',
41-
'/usr/lib',
42-
'/usr/local/lib',
43-
'/usr/local/opt/libxml2/lib')
62+
*lib_dirs)
4463

4564
found_lib ||= find_library('libxml2', 'xmlParseDoc',
46-
'/opt/lib',
47-
'/opt/local/lib',
48-
'/opt/homebrew/opt/libxml2/lib',
49-
'/usr/lib',
50-
'/usr/local/lib',
51-
'/usr/local/opt/libxml2/lib')
65+
*lib_dirs)
5266

5367
if !found_header || !found_lib
5468
crash(<<~EOL)

0 commit comments

Comments
 (0)