From ae0fd2ab79b0e46d3bd9fc89170d8db99bb91489 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Tue, 15 Jun 2021 15:13:39 +0200 Subject: [PATCH 1/3] Fix Windows libc detection for MSYS2-ucrt build Take the same approach for detection as used in fiddle: https://github.com/ruby/ruby/blob/79717f81f8ba24960cca6c934d00c72db64139ed/test/fiddle/helper.rb#L55-L56 --- lib/ffi/platform.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/ffi/platform.rb b/lib/ffi/platform.rb index 0f0639e48..bf01a27ad 100644 --- a/lib/ffi/platform.rb +++ b/lib/ffi/platform.rb @@ -132,11 +132,8 @@ def self.is_os(os) end LIBC = if IS_WINDOWS - if RbConfig::CONFIG['host_os'] =~ /mingw/i - RbConfig::CONFIG['RUBY_SO_NAME'].split('-')[-2] + '.dll' - else - "ucrtbase.dll" - end + crtname = RbConfig::CONFIG["RUBY_SO_NAME"][/msvc\w+/] || 'ucrtbase' + "#{crtname}.dll" elsif IS_GNU GNU_LIBC elsif OS == 'cygwin' From 3dd973eb384804e9448e483db973d06c0548d1bf Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Tue, 15 Jun 2021 15:28:05 +0200 Subject: [PATCH 2/3] Use _time on Windows UCRT platform --- bench/bench_time.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/bench_time.rb b/bench/bench_time.rb index aaec64f36..8454f811b 100644 --- a/bench/bench_time.rb +++ b/bench/bench_time.rb @@ -4,7 +4,7 @@ module BenchTime module Posix extend FFI::Library ffi_lib FFI::Library::LIBC - if RUBY_PLATFORM =~ /mswin/ + if RUBY_PLATFORM =~ /mswin/ || FFI::Library::LIBC =~ /ucrt/ attach_function :time, :_time64, [ :buffer_out ], :uint64, ignore_error: true else attach_function :time, [ :buffer_out ], :ulong, ignore_error: true From 3a5bef5c1ad4f3ebfcdbb89b3564c981b1ae24c8 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Tue, 15 Jun 2021 15:49:56 +0200 Subject: [PATCH 3/3] Better test --- bench/bench_time.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/bench_time.rb b/bench/bench_time.rb index 8454f811b..099ec3086 100644 --- a/bench/bench_time.rb +++ b/bench/bench_time.rb @@ -4,7 +4,7 @@ module BenchTime module Posix extend FFI::Library ffi_lib FFI::Library::LIBC - if RUBY_PLATFORM =~ /mswin/ || FFI::Library::LIBC =~ /ucrt/ + if FFI::Library::LIBC =~ /ucrtbase/ attach_function :time, :_time64, [ :buffer_out ], :uint64, ignore_error: true else attach_function :time, [ :buffer_out ], :ulong, ignore_error: true