mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/fiddle] Support MSWIN (#43)
https://github.com/ruby/fiddle/commit/f16e7ff6e0
This commit is contained in:
parent
a40b390b17
commit
f2bcdc7283
Notes:
git
2020-06-28 02:03:18 +09:00
4 changed files with 54 additions and 32 deletions
|
@ -3,23 +3,32 @@ require 'mkmf'
|
||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
|
|
||||||
|
libffi_version = nil
|
||||||
|
have_libffi = false
|
||||||
bundle = enable_config('bundled-libffi')
|
bundle = enable_config('bundled-libffi')
|
||||||
if ! bundle
|
unless bundle
|
||||||
dir_config 'libffi'
|
dir_config 'libffi'
|
||||||
|
|
||||||
pkg_config("libffi") and
|
if pkg_config("libffi")
|
||||||
ver = pkg_config("libffi", "modversion")
|
libffi_version = pkg_config("libffi", "modversion")
|
||||||
|
end
|
||||||
|
|
||||||
|
have_ffi_header = false
|
||||||
if have_header(ffi_header = 'ffi.h')
|
if have_header(ffi_header = 'ffi.h')
|
||||||
true
|
have_ffi_header = true
|
||||||
elsif have_header(ffi_header = 'ffi/ffi.h')
|
elsif have_header(ffi_header = 'ffi/ffi.h')
|
||||||
$defs.push('-DUSE_HEADER_HACKS')
|
$defs.push('-DUSE_HEADER_HACKS')
|
||||||
true
|
have_ffi_header = true
|
||||||
end and (have_library('ffi') || have_library('libffi'))
|
end
|
||||||
end or
|
if have_ffi_header && (have_library('ffi') || have_library('libffi'))
|
||||||
begin
|
have_libffi = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
unless have_libffi
|
||||||
# for https://github.com/ruby/fiddle
|
# for https://github.com/ruby/fiddle
|
||||||
if bundle && File.exist?("../../bin/extlibs.rb")
|
extlibs_rb = File.expand_path("../../bin/extlibs.rb", $srcdir)
|
||||||
|
if bundle && File.exist?(extlibs_rb)
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
require_relative "../../bin/extlibs"
|
require_relative "../../bin/extlibs"
|
||||||
extlibs = ExtLibs.new
|
extlibs = ExtLibs.new
|
||||||
|
@ -28,31 +37,32 @@ begin
|
||||||
Dir.glob("#{$srcdir}/libffi-*/").each{|dir| FileUtils.rm_rf(dir)}
|
Dir.glob("#{$srcdir}/libffi-*/").each{|dir| FileUtils.rm_rf(dir)}
|
||||||
extlibs.run(["--cache=#{cache_dir}", ext_dir])
|
extlibs.run(["--cache=#{cache_dir}", ext_dir])
|
||||||
end
|
end
|
||||||
ver = bundle != false &&
|
if bundle
|
||||||
Dir.glob("#{$srcdir}/libffi-*/")
|
libffi_package_name = Dir.glob("#{$srcdir}/libffi-*/")
|
||||||
.map {|n| File.basename(n)}
|
.map {|n| File.basename(n)}
|
||||||
.max_by {|n| n.scan(/\d+/).map(&:to_i)}
|
.max_by {|n| n.scan(/\d+/).map(&:to_i)}
|
||||||
unless ver
|
end
|
||||||
|
unless libffi_package_name
|
||||||
raise "missing libffi. Please install libffi."
|
raise "missing libffi. Please install libffi."
|
||||||
end
|
end
|
||||||
|
|
||||||
srcdir = "#{$srcdir}/#{ver}"
|
libffi_srcdir = "#{$srcdir}/#{libffi_package_name}"
|
||||||
ffi_header = 'ffi.h'
|
ffi_header = 'ffi.h'
|
||||||
libffi = Struct.new(*%I[dir srcdir builddir include lib a cflags ldflags opt arch]).new
|
libffi = Struct.new(*%I[dir srcdir builddir include lib a cflags ldflags opt arch]).new
|
||||||
libffi.dir = ver
|
libffi.dir = libffi_package_name
|
||||||
if $srcdir == "."
|
if $srcdir == "."
|
||||||
libffi.builddir = "#{ver}/#{RUBY_PLATFORM}"
|
libffi.builddir = libffi_package_name
|
||||||
libffi.srcdir = "."
|
libffi.srcdir = "."
|
||||||
else
|
else
|
||||||
libffi.builddir = libffi.dir
|
libffi.builddir = libffi.dir
|
||||||
libffi.srcdir = relative_from(srcdir, "..")
|
libffi.srcdir = relative_from(libffi_srcdir, "..")
|
||||||
end
|
end
|
||||||
libffi.include = "#{libffi.builddir}/include"
|
libffi.include = "#{libffi.builddir}/include"
|
||||||
libffi.lib = "#{libffi.builddir}/.libs"
|
libffi.lib = "#{libffi.builddir}/.libs"
|
||||||
libffi.a = "#{libffi.lib}/libffi_convenience.#{$LIBEXT}"
|
libffi.a = "#{libffi.lib}/libffi_convenience.#{$LIBEXT}"
|
||||||
nowarn = CONFIG.merge("warnflags"=>"")
|
nowarn = CONFIG.merge("warnflags"=>"")
|
||||||
libffi.cflags = RbConfig.expand("$(CFLAGS)".dup, nowarn)
|
libffi.cflags = RbConfig.expand("$(CFLAGS)".dup, nowarn)
|
||||||
ver = ver[/libffi-(.*)/, 1]
|
libffi_version = libffi_package_name[/libffi-(.*)/, 1]
|
||||||
|
|
||||||
FileUtils.mkdir_p(libffi.dir)
|
FileUtils.mkdir_p(libffi.dir)
|
||||||
libffi.opt = CONFIG['configure_args'][/'(-C)'/, 1]
|
libffi.opt = CONFIG['configure_args'][/'(-C)'/, 1]
|
||||||
|
@ -81,7 +91,6 @@ begin
|
||||||
args.concat %W[
|
args.concat %W[
|
||||||
--srcdir=#{libffi.srcdir}
|
--srcdir=#{libffi.srcdir}
|
||||||
--host=#{libffi.arch}
|
--host=#{libffi.arch}
|
||||||
--enable-builddir=#{RUBY_PLATFORM}
|
|
||||||
]
|
]
|
||||||
args << ($enable_shared || !$static ? '--enable-shared' : '--enable-static')
|
args << ($enable_shared || !$static ? '--enable-shared' : '--enable-static')
|
||||||
args << libffi.opt if libffi.opt
|
args << libffi.opt if libffi.opt
|
||||||
|
@ -98,7 +107,7 @@ begin
|
||||||
begin
|
begin
|
||||||
IO.copy_stream(libffi.dir + "/config.log", Logging.instance_variable_get(:@logfile))
|
IO.copy_stream(libffi.dir + "/config.log", Logging.instance_variable_get(:@logfile))
|
||||||
rescue SystemCallError => e
|
rescue SystemCallError => e
|
||||||
Logfile.message("%s\n", e.message)
|
Logging.message("%s\n", e.message)
|
||||||
end
|
end
|
||||||
raise "failed to configure libffi. Please install libffi."
|
raise "failed to configure libffi. Please install libffi."
|
||||||
end
|
end
|
||||||
|
@ -107,27 +116,32 @@ begin
|
||||||
FileUtils.rm_f("#{libffi.include}/ffitarget.h")
|
FileUtils.rm_f("#{libffi.include}/ffitarget.h")
|
||||||
end
|
end
|
||||||
unless File.file?("#{libffi.include}/ffitarget.h")
|
unless File.file?("#{libffi.include}/ffitarget.h")
|
||||||
FileUtils.cp("#{srcdir}/src/x86/ffitarget.h", libffi.include, preserve: true)
|
FileUtils.cp("#{libffi_srcdir}/src/x86/ffitarget.h", libffi.include, preserve: true)
|
||||||
end
|
end
|
||||||
$INCFLAGS << " -I" << libffi.include
|
$INCFLAGS << " -I" << libffi.include
|
||||||
end
|
end
|
||||||
|
|
||||||
if ver
|
if libffi_version
|
||||||
ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored.
|
# If libffi_version contains rc version, just ignored.
|
||||||
ver = (ver.split('.').map(&:to_i) + [0,0])[0,3]
|
libffi_version = libffi_version.gsub(/-rc\d+/, '')
|
||||||
$defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver }})
|
libffi_version = (libffi_version.split('.').map(&:to_i) + [0,0])[0,3]
|
||||||
warn "libffi_version: #{ver.join('.')}"
|
$defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % libffi_version }})
|
||||||
|
warn "libffi_version: #{libffi_version.join('.')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
case
|
case
|
||||||
when $mswin, $mingw, (ver && (ver <=> [3, 2]) >= 0)
|
when $mswin, $mingw, (libffi_version && (libffi_version <=> [3, 2]) >= 0)
|
||||||
$defs << "-DUSE_FFI_CLOSURE_ALLOC=1"
|
$defs << "-DUSE_FFI_CLOSURE_ALLOC=1"
|
||||||
when (ver && (ver <=> [3, 2]) < 0)
|
when (libffi_version && (libffi_version <=> [3, 2]) < 0)
|
||||||
else
|
else
|
||||||
have_func('ffi_closure_alloc', ffi_header)
|
have_func('ffi_closure_alloc', ffi_header)
|
||||||
end
|
end
|
||||||
|
|
||||||
have_func('ffi_prep_cif_var', ffi_header)
|
if libffi
|
||||||
|
$defs << "-DHAVE_FFI_PREP_CIF_VAR"
|
||||||
|
else
|
||||||
|
have_func('ffi_prep_cif_var', ffi_header)
|
||||||
|
end
|
||||||
|
|
||||||
have_header 'sys/mman.h'
|
have_header 'sys/mman.h'
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,13 @@ Gem::Specification.new do |spec|
|
||||||
"LICENSE.txt",
|
"LICENSE.txt",
|
||||||
"README.md",
|
"README.md",
|
||||||
"Rakefile",
|
"Rakefile",
|
||||||
|
"bin/downloader.rb",
|
||||||
|
"bin/extlibs.rb",
|
||||||
"ext/fiddle/closure.c",
|
"ext/fiddle/closure.c",
|
||||||
"ext/fiddle/closure.h",
|
"ext/fiddle/closure.h",
|
||||||
"ext/fiddle/conversions.c",
|
"ext/fiddle/conversions.c",
|
||||||
"ext/fiddle/conversions.h",
|
"ext/fiddle/conversions.h",
|
||||||
|
"ext/fiddle/depend",
|
||||||
"ext/fiddle/extconf.rb",
|
"ext/fiddle/extconf.rb",
|
||||||
"ext/fiddle/extlibs",
|
"ext/fiddle/extlibs",
|
||||||
"ext/fiddle/fiddle.c",
|
"ext/fiddle/fiddle.c",
|
||||||
|
|
|
@ -32,7 +32,7 @@ IO.foreach("#{srcdir}/configure.ac") do |line|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
builddir = srcdir == "." ? enable['builddir'] : "."
|
builddir = srcdir == "." ? (enable['builddir'] || ".") : "."
|
||||||
conf['TARGET'] = /^x64/ =~ host ? "X86_WIN64" : "X86_WIN32"
|
conf['TARGET'] = /^x64/ =~ host ? "X86_WIN64" : "X86_WIN32"
|
||||||
|
|
||||||
FileUtils.mkdir_p([builddir, "#{builddir}/include", "#{builddir}/src/x86"])
|
FileUtils.mkdir_p([builddir, "#{builddir}/include", "#{builddir}/src/x86"])
|
||||||
|
|
|
@ -86,7 +86,12 @@ module Fiddle
|
||||||
else
|
else
|
||||||
snprintf_name = "snprintf"
|
snprintf_name = "snprintf"
|
||||||
end
|
end
|
||||||
snprintf = Function.new(@libc[snprintf_name],
|
begin
|
||||||
|
snprintf_pointer = @libc[snprintf_name]
|
||||||
|
rescue Fiddle::DLError
|
||||||
|
skip "Can't find #{snprintf_name}: #{$!.message}"
|
||||||
|
end
|
||||||
|
snprintf = Function.new(snprintf_pointer,
|
||||||
[
|
[
|
||||||
TYPE_VOIDP,
|
TYPE_VOIDP,
|
||||||
TYPE_SIZE_T,
|
TYPE_SIZE_T,
|
||||||
|
|
Loading…
Add table
Reference in a new issue