revault_api 0.6.0-aarch64-linux → 0.6.1-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbconfig'
4
+
5
+ module Revault
6
+ module NativeLibrary
7
+ module_function
8
+
9
+ def path(explicit_path = nil)
10
+ raise ArgumentError, 'native library path must not be empty' if explicit_path == ''
11
+ return @selected_path if defined?(@selected_path) && explicit_path.nil?
12
+ inherited = ENV['REVAULT_LIBRARY']
13
+ selected = explicit_path || (inherited unless inherited.nil? || inherited.empty?) || bundled_path
14
+ selected = resolve_windows_bare_name(selected)
15
+ if defined?(@selected_path) && @selected_path != selected
16
+ raise 'the process-wide reVault native library is already selected'
17
+ end
18
+ @selected_path = selected
19
+ end
20
+
21
+ def resolve_windows_bare_name(path)
22
+ return path unless RbConfig::CONFIG['host_os'].match?(/mswin|mingw/)
23
+ return path if path.match?(%r{[/\\]})
24
+
25
+ ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).each do |directory|
26
+ candidate = File.expand_path(path, directory)
27
+ return candidate if File.file?(candidate)
28
+ end
29
+ path
30
+ end
31
+
32
+ def bundled_path
33
+ bundled = bundled_location
34
+ return bundled if File.file?(bundled)
35
+ raise "revault-api native carrier is missing: #{bundled}; install the matching platform gem"
36
+ end
37
+
38
+ def bundled_location
39
+ cpu = case RbConfig::CONFIG['host_cpu']
40
+ when 'x86_64', 'amd64', 'x64' then 'x86_64'
41
+ when 'aarch64', 'arm64' then 'aarch64'
42
+ else raise "unsupported reVault architecture: #{RbConfig::CONFIG['host_cpu']}"
43
+ end
44
+ target, library = case RbConfig::CONFIG['host_os']
45
+ when /linux/ then ["linux-#{cpu}-gnu", 'librevault_api.so']
46
+ when /darwin/ then ["macos-#{cpu}", 'librevault_api.dylib']
47
+ when /mswin|mingw/ then ["windows-#{cpu}-msvc", 'revault_api.dll']
48
+ else raise "unsupported reVault operating system: #{RbConfig::CONFIG['host_os']}"
49
+ end
50
+ File.expand_path("../../native/#{target}/#{library}", __dir__)
51
+ end
52
+
53
+ # Bind struct-return adapters to the same carrier as ordinary operations.
54
+ def bind_shim
55
+ addresses = Revault::Shim.singleton_methods(false).grep(/^ruby_/).to_h do |name|
56
+ symbol = name.to_s.delete_prefix('ruby_')
57
+ [symbol, Revault::Native.handler[symbol]]
58
+ end
59
+ resolver = Fiddle::Closure::BlockCaller.new(
60
+ Fiddle::TYPE_VOIDP, [Fiddle::TYPE_VOIDP]
61
+ ) { |name| addresses.fetch(Fiddle::Pointer.new(name).to_s) }
62
+ Fiddle::Function.new(
63
+ Revault::Shim.handler['ruby_bind_library'],
64
+ [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID
65
+ ).call(resolver)
66
+ end
67
+
68
+ def shim_path
69
+ name = case RbConfig::CONFIG['host_os']
70
+ when /linux/ then 'librevault_ruby_shim.so'
71
+ when /darwin/ then 'librevault_ruby_shim.dylib'
72
+ when /mswin|mingw/ then 'revault_ruby_shim.dll'
73
+ else raise "unsupported reVault operating system: #{RbConfig::CONFIG['host_os']}"
74
+ end
75
+ bundled = File.join(File.dirname(bundled_location), name)
76
+ return bundled if File.file?(bundled)
77
+ raise "revault-api Ruby native shim is missing beside #{bundled_location}"
78
+ end
79
+ end
80
+ end