libui 0.2.1-aarch64-linux → 0.2.3-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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46dd8a324e8f00193d0a24d23bcece4de9fc6526392e3506b3ec81543ff96bd5
4
- data.tar.gz: ac3ab3100f882d00d4e67f052ac1047495ae4e448eb4c63fdfd1069bf0ebda93
3
+ metadata.gz: b4a00e59b8214cf875852734d5b74c5716c38a1c4ba8354d8036a6ca6ec40599
4
+ data.tar.gz: b4d535e83d07883fe6561ab5fa8ff3620225dc29274f3c5ecdb6fa78ad27d115
5
5
  SHA512:
6
- metadata.gz: 89ca6535da0b6cc404ceb8cc840bdb938ea6e688f4e68f2d63c33279af5ce9cf42e8f6d53dbfaed5463731dbc59e52d76a3e5e9faa8043de8c2874d2e2731004
7
- data.tar.gz: c8df2b43a9563013247315255faaf11a0c2b5ff6b4cbaf3fcc1b7fca416783cae781371eb7a8ef2751113ee2c51e38d8fe707749c2a1e768386150296de75007
6
+ metadata.gz: b93bb829808ac504a2bbf4bed51f742ca266d4e7cf10aa9840677b089f309f4fc7d05c3c204491c239b775a5c023252770ac9125c44e0b56dcc9e55c842be4a3
7
+ data.tar.gz: b5cdf29edc3f92aae2a42431ce426d5d69ae7709905535e9d188749a990ef2c23ef81869cdeb7b2d407ae109c77cbe00886442358c2488216d997b22e8f7258d
data/README.md CHANGED
@@ -1,18 +1,13 @@
1
1
  # LibUI
2
2
 
3
3
  [![test](https://github.com/kojix2/LibUI/actions/workflows/test.yml/badge.svg)](https://github.com/kojix2/LibUI/actions/workflows/test.yml)
4
- [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
5
- <a href="https://github.com/AndyObtiva/glimmer-dsl-libui"><img alt="glimmer-dsl-libui" src="https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-logo-hi-res.svg" width="50" height="50" align="right"></a>
6
- [![Pre-build](https://github.com/kojix2/libui-ng/actions/workflows/pre-build.yml/badge.svg?branch=pre-build)](https://github.com/kojix2/libui-ng/actions/workflows/pre-build.yml)
4
+ [![Gem Version](https://img.shields.io/badge/dynamic/json?label=gem%20version&query=%24%5B0%5D.number&url=https%3A%2F%2Frubygems.org%2Fapi%2Fv1%2Fversions%2Flibui.json&color=brightgreen)](https://rubygems.org/gems/libui/versions)
7
5
  [![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2FLibUI%2Flines)](https://tokei.kojix2.net/github/kojix2/LibUI)
6
+ <a href="https://github.com/AndyObtiva/glimmer-dsl-libui"><img alt="glimmer-dsl-libui" src="https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-logo-hi-res.svg" width="50" height="50" align="right"></a>
8
7
 
9
8
  LibUI is a Ruby wrapper for libui family.
10
9
 
11
- :rocket: [libui-ng](https://github.com/libui-ng/libui-ng) - A cross-platform portable GUI library
12
-
13
- :wrench: [libui-dev](https://github.com/petabyt/libui-dev) - Native UI library for C - with some extras
14
-
15
- :radio_button: [libui](https://github.com/andlabs/libui) - Original version by andlabs.
10
+ :rocket: [libui-ng](https://github.com/kojix2/libui-ng) - A cross-platform portable GUI library
16
11
 
17
12
  ## Installation
18
13
 
@@ -86,7 +81,6 @@ LibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the
86
81
  To build actual applications, it is recommended to use a DSL for LibUI, as they enable writing object-oriented code the Ruby way (instead of procedural code the C way):
87
82
 
88
83
  - [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
89
- - [libui_paradise](https://rubygems.org/gems/libui_paradise)
90
84
 
91
85
  ### Working with fiddle pointers
92
86
 
@@ -191,6 +185,18 @@ bundle exec rake vendor:auto
191
185
  bundle exec rake test
192
186
  ```
193
187
 
188
+ JRuby on macOS needs Java and AppKit must start on the first thread:
189
+
190
+ ```sh
191
+ export JAVA_HOME=/path/to/openjdk
192
+ export JRUBY_OPTS=-J-XstartOnFirstThread
193
+ jruby -Ilib examples/basic_button.rb
194
+ jruby -S rake test
195
+ ```
196
+
197
+ Take note that, as the above code shows, LibUI works via jruby as well, so you have an additional
198
+ GUI library (aside from jruby-swing by default) to test simple User Interfaces too.
199
+
194
200
  ### Pre-built shared libraries for libui-ng
195
201
 
196
202
  Download pre-built libui-ng shared libraries (per your current platform):
data/lib/libui/ffi.rb CHANGED
@@ -3,7 +3,6 @@ require_relative 'fiddle_patch'
3
3
  require_relative 'error'
4
4
 
5
5
  module LibUI
6
-
7
6
  module FFI
8
7
  extend Fiddle::Importer
9
8
  extend FiddlePatch
@@ -11,9 +11,9 @@ module LibUI
11
11
  def parse_signature(signature, tymap = nil)
12
12
  tymap ||= {}
13
13
  ctype, func, args = case compact(signature)
14
- when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
14
+ when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
15
15
  [TYPE_VOIDP, Regexp.last_match(1), Regexp.last_match(2)]
16
- when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
16
+ when /^([\w*\s]+[*\s])(\w+)\((.*?)\);?$/
17
17
  [parse_ctype(Regexp.last_match(1).strip, tymap), Regexp.last_match(2), Regexp.last_match(3)]
18
18
  else
19
19
  raise("can't parse the function prototype: #{signature}")
@@ -22,12 +22,12 @@ module LibUI
22
22
  callback_argument_types = {} # Added
23
23
  argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
24
24
  # Check if it is a function pointer or not
25
- if arg =~ /\(\*.*\)\(.*\)/ # Added
25
+ if arg =~ /\(\*.*\)\(.*\)/ # Added
26
26
  # From the arguments, create a notation that looks like a function declaration
27
27
  # int(*f)(int *, void *) -> int f(int *, void *)
28
- func_arg = arg.sub('(*', ' ').sub(')', '') # Added
28
+ func_arg = arg.sub('(*', ' ').sub(')', '') # Added
29
29
  # Use Fiddle's parse_signature method again.
30
- callback_argument_types[idx] = parse_signature(func_arg) # Added
30
+ callback_argument_types[idx] = parse_signature(func_arg) # Added
31
31
  end
32
32
  parse_ctype(arg, tymap)
33
33
  end
@@ -41,8 +41,8 @@ module LibUI
41
41
  func = import_function(symname, ctype, argtype, opt[:call_type])
42
42
 
43
43
  # callback_argument_types
44
- func.instance_variable_set(:@callback_argument_types,
45
- callback_argument_types) # Added
44
+ func.instance_variable_set(:@callback_argument_types,
45
+ callback_argument_types) # Added
46
46
  # attr_reader
47
47
  def func.callback_argument_types
48
48
  @callback_argument_types
@@ -68,9 +68,9 @@ module LibUI
68
68
  @func_map[name] = func
69
69
  # define_method(name){|*args,&block| f.call(*args,&block)}
70
70
  begin
71
- /^(.+?):(\d+)/ =~ caller.first
72
- file = Regexp.last_match(1)
73
- line = Regexp.last_match(2).to_i
71
+ location = caller_locations(1, 1).first
72
+ file = location.path
73
+ line = location.lineno
74
74
  rescue StandardError
75
75
  file, line = __FILE__, __LINE__ + 3
76
76
  end
@@ -0,0 +1,164 @@
1
+ require 'rbconfig'
2
+
3
+ module LibUI
4
+ module Platform
5
+ CONFIG = {
6
+ 'arm64-darwin' => {
7
+ vendor: 'vendor/libui.arm64.dylib',
8
+ lib_names: ['libui.arm64.dylib', 'libui.dylib'],
9
+ release_zip: 'macOS-arm64-shared-release.zip',
10
+ release_src: 'builddir/meson-out/libui.dylib'
11
+ },
12
+ 'x86_64-darwin' => {
13
+ vendor: 'vendor/libui.x86_64.dylib',
14
+ lib_names: ['libui.x86_64.dylib', 'libui.dylib'],
15
+ release_zip: 'macOS-x64-shared-release.zip',
16
+ release_src: 'builddir/meson-out/libui.dylib'
17
+ },
18
+ 'x86_64-linux' => {
19
+ vendor: 'vendor/libui.x86_64.so',
20
+ lib_names: ['libui.x86_64.so', 'libui.so'],
21
+ release_zip: 'Ubuntu-x64-shared-release.zip',
22
+ release_src: 'builddir/meson-out/libui.so'
23
+ },
24
+ 'aarch64-linux' => {
25
+ vendor: 'vendor/libui.aarch64.so',
26
+ lib_names: ['libui.aarch64.so', 'libui.so'],
27
+ release_zip: 'Ubuntu-arm64-shared-release.zip',
28
+ release_src: 'builddir/meson-out/libui.so'
29
+ },
30
+ 'x64-mingw32' => {
31
+ vendor: 'vendor/libui.x64.dll',
32
+ lib_names: ['libui.x64.dll', 'libui.dll'],
33
+ release_zip: 'Windows-x64-msvc-shared-release.zip',
34
+ release_src: 'builddir/meson-out/libui.dll'
35
+ },
36
+ 'x86-mingw32' => {
37
+ vendor: 'vendor/libui.x86.dll',
38
+ lib_names: ['libui.x86.dll', 'libui.dll'],
39
+ release_zip: 'Windows-x86-msvc-shared-release.zip',
40
+ release_src: 'builddir/meson-out/libui.dll'
41
+ }
42
+ }.freeze
43
+
44
+ class << self
45
+ def config_keys
46
+ CONFIG.keys
47
+ end
48
+
49
+ def config_for(platform_key)
50
+ CONFIG[normalize_platform_key(platform_key)]
51
+ end
52
+
53
+ def current_config
54
+ config_for(detect_platform_key)
55
+ end
56
+
57
+ def detect_platform_key
58
+ native_platform_key || rubygems_platform_key
59
+ end
60
+
61
+ def native_platform_key
62
+ platform_key = case host_os
63
+ when /darwin/
64
+ "#{normalized_cpu}-darwin"
65
+ when /linux/
66
+ # libc variants (glibc vs musl) are not supported as
67
+ # separate prebuilt targets yet; the shipped Linux
68
+ # binaries are built on Ubuntu. Supporting musl would
69
+ # require adding explicit *-linux-musl entries.
70
+ "#{normalized_cpu}-linux"
71
+ when /mingw|mswin/
72
+ windows_platform_key
73
+ end
74
+
75
+ CONFIG.key?(platform_key) ? platform_key : nil
76
+ end
77
+
78
+ def rubygems_platform_key
79
+ current_platform = Gem::Platform.local
80
+ platform_key = normalize_platform_key(current_platform.to_s)
81
+ return platform_key if CONFIG.key?(platform_key)
82
+
83
+ CONFIG.keys.find do |config_key|
84
+ config_platform = Gem::Platform.new(config_key)
85
+
86
+ # NOTE: match_platforms? is a private RubyGems API. It is used to
87
+ # reuse RubyGems' own platform matching (including the libc wildcard
88
+ # behaviour), but it may change or disappear across RubyGems versions.
89
+ if Gem::Platform.send(:match_platforms?, current_platform, [config_platform])
90
+ true
91
+ elsif config_key == 'x64-mingw32' &&
92
+ current_platform.os.start_with?('mingw') &&
93
+ %w[x64 x86_64 amd64].include?(current_platform.cpu)
94
+ true
95
+ elsif config_key == 'x86-mingw32' &&
96
+ current_platform.os.start_with?('mingw') &&
97
+ %w[x86 i386 i686].include?(current_platform.cpu)
98
+ true
99
+ else
100
+ false
101
+ end
102
+ end
103
+ end
104
+
105
+ # Canonicalizes alternate platform spellings to the keys used in CONFIG.
106
+ # Linux libc suffixes (-gnu / -musl) are intentionally not stripped here;
107
+ # adding libc-specific artifacts should be an explicit CONFIG change.
108
+ def normalize_platform_key(platform_key)
109
+ platform_key.to_s
110
+ .sub(/\Aarm64-linux\z/, 'aarch64-linux')
111
+ .sub(/\Ax64-linux\z/, 'x86_64-linux')
112
+ .sub(/-mingw-ucrt\z/, '-mingw32')
113
+ end
114
+
115
+ def vendor_file_for(platform_key)
116
+ config = config_for(platform_key)
117
+ config && config[:vendor]
118
+ end
119
+
120
+ def current_lib_names
121
+ # host_lib_name and the bare "libui.<soext>" are fallbacks for locally
122
+ # built or manually placed libraries (e.g. via LIBUIDIR or a source
123
+ # checkout) whose file names may not match the CONFIG lib_names.
124
+ host_lib_name = "libui.#{host_cpu}.#{RbConfig::CONFIG['SOEXT']}"
125
+ names = current_config ? current_config[:lib_names] : []
126
+ ([host_lib_name] + names + ["libui.#{RbConfig::CONFIG['SOEXT']}"]).uniq
127
+ end
128
+
129
+ private
130
+
131
+ def host_cpu
132
+ RbConfig::CONFIG['host_cpu']
133
+ end
134
+
135
+ def host_os
136
+ RbConfig::CONFIG['host_os']
137
+ end
138
+
139
+ def normalized_cpu
140
+ case host_cpu
141
+ when /i\d86/
142
+ 'x86'
143
+ when 'amd64', 'x64'
144
+ 'x86_64'
145
+ when 'aarch64'
146
+ host_os =~ /darwin/ ? 'arm64' : host_cpu
147
+ when 'arm64'
148
+ host_os =~ /linux/ ? 'aarch64' : host_cpu
149
+ else
150
+ host_cpu
151
+ end
152
+ end
153
+
154
+ def windows_platform_key
155
+ case normalized_cpu
156
+ when 'x86_64'
157
+ 'x64-mingw32'
158
+ when 'x86'
159
+ 'x86-mingw32'
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
data/lib/libui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LibUI
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.3'
3
3
  end
data/lib/libui.rb CHANGED
@@ -1,36 +1,20 @@
1
1
  require_relative 'libui/version'
2
2
  require_relative 'libui/utils'
3
3
  require_relative 'libui/error'
4
- require 'rbconfig'
4
+ require_relative 'libui/platform'
5
5
 
6
6
  module LibUI
7
7
  class << self
8
8
  attr_accessor :ffi_lib
9
9
  end
10
10
 
11
- host_cpu = case RbConfig::CONFIG['host_cpu']
12
- when /i\d86/
13
- 'x86'
14
- else
15
- RbConfig::CONFIG['host_cpu']
16
- end
17
-
18
- lib_name = [
19
- # For libui-ng shared libraries compiled with (rake vendor:build)
20
- "libui.#{RbConfig::CONFIG['host_cpu']}.#{RbConfig::CONFIG['SOEXT']}",
21
- # For libui-ng shared library downloaded from RubyGems.org
22
- "libui.#{host_cpu}.#{RbConfig::CONFIG['SOEXT']}",
23
- # For backward compatibility or manual compilation of libui-ng
24
- "libui.#{RbConfig::CONFIG['SOEXT']}"
25
- ]
26
-
27
11
  self.ffi_lib = \
28
12
  if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
29
- lib_name.lazy
13
+ Platform.current_lib_names.lazy
30
14
  .map { |name| File.expand_path(name, ENV['LIBUIDIR']) }
31
15
  .find { |path| File.exist?(path) }
32
16
  else
33
- lib_name.lazy
17
+ Platform.current_lib_names.lazy
34
18
  .map { |name| File.expand_path("../vendor/#{name}", __dir__) }
35
19
  .find { |path| File.exist?(path) }
36
20
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - kojix2
@@ -36,6 +36,7 @@ files:
36
36
  - lib/libui/ffi.rb
37
37
  - lib/libui/fiddle_patch.rb
38
38
  - lib/libui/libui_base.rb
39
+ - lib/libui/platform.rb
39
40
  - lib/libui/utils.rb
40
41
  - lib/libui/version.rb
41
42
  - vendor/LICENSE.md