mkmf-lite 0.7.1 → 0.7.3

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: 55c14044604c5889a36d8d2fee0ae1112c35297201f9727cf7568630cd735bfc
4
- data.tar.gz: 4eecbb5306d00f09742f1969fcb30d14703f6730c9b5c9067ac9eb319a784d19
3
+ metadata.gz: 726b5a45c22c5700645950241fabc40621f7a1ec9f57a20fffd212623a41acd0
4
+ data.tar.gz: 34bc9e1d6d1c3bba0a9c73cfd7d899fda171054c73dfaaeec6305f246f0fe497
5
5
  SHA512:
6
- metadata.gz: 70a74c5abed4b1efb35eea74d866ab7eee463f52dea3eefbeb6d10b81cbdcbb21661413b5b31879c4c3cdca3cb655a94ee2f0332c1e782979b11db7922ab3285
7
- data.tar.gz: 3cbac4e68dbdede43b083a20713f4dc81a10ba351dd0842d9768f75218637a825e1526f43fabd5b8ea8721f79c4ee799e85994a8216716e27bbafe3d111ad3d4
6
+ metadata.gz: b5e4afd22216317af2dbb01ea8ead2339976c00276774b1a9e6b5a72e04e6d6ecb097863f6366ce7de93628299440a44b0663db245964d8c30bc310f72d14021
7
+ data.tar.gz: 0d132571eb8b470886c5e2bce7c5b80b0de36ffe563dd929d7ba479173125827a643b8d63584d7b76a6d05c8db72dd1f5c35b095f38cad707d06d29541c4103c
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.7.3 - 21-Mar-2025
2
+ * Add check_offsetof method.
3
+
4
+ ## 0.7.2 - 13-Mar-2025
5
+ * Allow option of adding directories to check_sizeof and check_valueof methods.
6
+
1
7
  ## 0.7.1 - 29-Sep-2024
2
8
  * Skip adding compiler switches for JRuby, which chokes on them for some reason.
3
9
 
data/lib/mkmf/lite.rb CHANGED
@@ -16,7 +16,7 @@ module Mkmf
16
16
  extend Memoist
17
17
 
18
18
  # The version of the mkmf-lite library
19
- MKMF_LITE_VERSION = '0.7.1'
19
+ MKMF_LITE_VERSION = '0.7.3'
20
20
 
21
21
  private
22
22
 
@@ -135,12 +135,20 @@ module Mkmf
135
135
  # If this method fails an error is raised. This could happen if the constant
136
136
  # can't be found and/or the header files do not include the indicated constant.
137
137
  #
138
- def check_valueof(constant, headers = [])
138
+ def check_valueof(constant, headers = [], *directories)
139
139
  headers = get_header_string(headers)
140
140
  erb = ERB.new(read_template('check_valueof.erb'))
141
141
  code = erb.result(binding)
142
142
 
143
- try_to_execute(code)
143
+ if directories.empty?
144
+ options = nil
145
+ else
146
+ options = ''
147
+ directories.each{ |dir| options += "-I#{dir} " }
148
+ options.rstrip!
149
+ end
150
+
151
+ try_to_execute(code, options)
144
152
  end
145
153
 
146
154
  memoize :check_valueof
@@ -158,16 +166,56 @@ module Mkmf
158
166
  # utsname = check_sizeof('struct utsname', 'sys/utsname.h')
159
167
  # end
160
168
  #
161
- def check_sizeof(type, headers = [])
169
+ def check_sizeof(type, headers = [], *directories)
162
170
  headers = get_header_string(headers)
163
171
  erb = ERB.new(read_template('check_sizeof.erb'))
164
172
  code = erb.result(binding)
165
173
 
166
- try_to_execute(code)
174
+ if directories.empty?
175
+ options = nil
176
+ else
177
+ options = ''
178
+ directories.each{ |dir| options += "-I#{dir} " }
179
+ options.rstrip!
180
+ end
181
+
182
+ try_to_execute(code, options)
167
183
  end
168
184
 
169
185
  memoize :check_sizeof
170
186
 
187
+ # Returns the offset of +field+ within +struct_type+ using +headers+,
188
+ # or common headers, plus stddef.h, if no headers are specified.
189
+ #
190
+ # If this method fails an error is raised. This could happen if the field
191
+ # can't be found and/or the header files do not include the indicated type.
192
+ # It will also fail if the field is a bit field.
193
+ #
194
+ # Example:
195
+ #
196
+ # class Foo
197
+ # include Mkmf::Lite
198
+ # utsname = check_offsetof('struct utsname', 'release', 'sys/utsname.h')
199
+ # end
200
+ #
201
+ def check_offsetof(struct_type, field, headers = [], *directories)
202
+ headers = get_header_string(headers)
203
+ erb = ERB.new(read_template('check_offsetof.erb'))
204
+ code = erb.result(binding)
205
+
206
+ if directories.empty?
207
+ options = nil
208
+ else
209
+ options = ''
210
+ directories.each{ |dir| options += "-I#{dir} " }
211
+ options.rstrip!
212
+ end
213
+
214
+ try_to_execute(code, options)
215
+ end
216
+
217
+ memoize :check_offsetof
218
+
171
219
  private
172
220
 
173
221
  # Take an array of header file names (or convert it to an array if it's a
@@ -206,7 +254,7 @@ module Mkmf
206
254
  # we don't actually care about the reason for failure, though a Ruby
207
255
  # error is raised if the compilation step fails.
208
256
  #
209
- def try_to_execute(code)
257
+ def try_to_execute(code, command_options = nil)
210
258
  begin
211
259
  result = 0
212
260
 
@@ -216,7 +264,12 @@ module Mkmf
216
264
  Dir.chdir(Dir.tmpdir) do
217
265
  File.write(cpp_source_file, code)
218
266
 
219
- command = "#{cpp_command} #{cpp_libraries} #{cpp_defs} "
267
+ if command_options
268
+ command = "#{cpp_command} #{command_options} #{cpp_libraries} #{cpp_defs} "
269
+ else
270
+ command = "#{cpp_command} #{cpp_libraries} #{cpp_defs} "
271
+ end
272
+
220
273
  command += "#{cpp_out_file} "
221
274
  command += cpp_source_file
222
275
 
@@ -0,0 +1,11 @@
1
+ #include <stdio.h>
2
+ #include <stddef.h>
3
+
4
+ <%= headers %>
5
+
6
+ int conftest_const = (int)(offsetof(<%= struct_type %>, <%= field %>));
7
+
8
+ int main(){
9
+ printf("%d\n", conftest_const);
10
+ return 0;
11
+ }
data/mkmf-lite.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'mkmf-lite'
5
5
  spec.summary = 'A lighter version of mkmf designed for use as a library'
6
- spec.version = '0.7.1'
6
+ spec.version = '0.7.3'
7
7
  spec.author = 'Daniel J. Berger'
8
8
  spec.license = 'Apache-2.0'
9
9
  spec.email = 'djberg96@gmail.com'
@@ -27,7 +27,9 @@ Gem::Specification.new do |spec|
27
27
  'documentation_uri' => 'https://github.com/djberg96/mkmf-lite/wiki',
28
28
  'source_code_uri' => 'https://github.com/djberg96/mkmf-lite',
29
29
  'wiki_uri' => 'https://github.com/djberg96/mkmf-lite/wiki',
30
- 'rubygems_mfa_required' => 'true'
30
+ 'rubygems_mfa_required' => 'true',
31
+ 'github_repo' => 'https://github.com/djberg96/mkmf-lite',
32
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
31
33
  }
32
34
 
33
35
  spec.description = <<-EOF
@@ -20,7 +20,7 @@ RSpec.describe Mkmf::Lite do
20
20
 
21
21
  describe 'constants' do
22
22
  example 'version information' do
23
- expect(described_class::MKMF_LITE_VERSION).to eq('0.7.1')
23
+ expect(described_class::MKMF_LITE_VERSION).to eq('0.7.3')
24
24
  expect(described_class::MKMF_LITE_VERSION).to be_frozen
25
25
  end
26
26
  end
@@ -96,8 +96,8 @@ RSpec.describe Mkmf::Lite do
96
96
  expect{ subject.check_valueof }.to raise_error(ArgumentError)
97
97
  end
98
98
 
99
- example 'check_valueof accepts a maximum of two arguments' do
100
- expect{ subject.check_valueof(constant, 'stdio.h', 1) }.to raise_error(ArgumentError)
99
+ example 'check_valueof accepts directory arguments' do
100
+ expect{ subject.check_valueof(constant, 'stdio.h', ['/usr/include']) }.not_to raise_error
101
101
  end
102
102
 
103
103
  example 'check_valueof works with one or two arguments' do
@@ -112,6 +112,33 @@ RSpec.describe Mkmf::Lite do
112
112
  end
113
113
  end
114
114
 
115
+ context 'check_offsetof' do
116
+ let(:st_field){ 'st_dev' }
117
+
118
+ example 'check_offsetof basic functionality' do
119
+ expect(subject).to respond_to(:check_offsetof)
120
+ expect{ subject.check_offsetof(st_type, st_field, st_header) }.not_to raise_error
121
+ end
122
+
123
+ example 'check_offsetof requires at least two arguments' do
124
+ expect{ subject.check_offsetof }.to raise_error(ArgumentError)
125
+ expect{ subject.check_offsetof(st_type) }.to raise_error(ArgumentError)
126
+ end
127
+
128
+ example 'check_offsetof accepts directory arguments' do
129
+ expect{ subject.check_offsetof(st_type, st_field, [st_header, 'stdlib.h'], ['/usr/include']) }.not_to raise_error
130
+ end
131
+
132
+ example 'check_offsetof returns an integer value' do
133
+ size1 = subject.check_offsetof(st_type, st_field, st_header)
134
+ size2 = subject.check_offsetof(st_type, 'st_ino', st_header)
135
+ expect(size1).to be_a(Integer)
136
+ expect(size2).to be_a(Integer)
137
+ expect(size1).to eq(0)
138
+ expect(size2).to be > size1
139
+ end
140
+ end
141
+
115
142
  context 'check_sizeof' do
116
143
  example 'check_sizeof basic functionality' do
117
144
  expect(subject).to respond_to(:check_sizeof)
@@ -122,8 +149,8 @@ RSpec.describe Mkmf::Lite do
122
149
  expect{ subject.check_sizeof }.to raise_error(ArgumentError)
123
150
  end
124
151
 
125
- example 'check_sizeof accepts a maximum of two arguments' do
126
- expect{ subject.check_sizeof('div_t', 'stdlib.h', 1) }.to raise_error(ArgumentError)
152
+ example 'check_sizeof accepts directory arguments' do
153
+ expect{ subject.check_sizeof('div_t', 'stdlib.h', ['/usr/include']) }.not_to raise_error
127
154
  end
128
155
 
129
156
  example 'check_sizeof works with one or two arguments' do
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkmf-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2024-09-29 00:00:00.000000000 Z
38
+ date: 2025-03-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ptools
@@ -141,6 +141,7 @@ files:
141
141
  - certs/djberg96_pub.pem
142
142
  - lib/mkmf-lite.rb
143
143
  - lib/mkmf/lite.rb
144
+ - lib/mkmf/templates/check_offsetof.erb
144
145
  - lib/mkmf/templates/check_sizeof.erb
145
146
  - lib/mkmf/templates/check_valueof.erb
146
147
  - lib/mkmf/templates/have_func.erb
@@ -160,6 +161,8 @@ metadata:
160
161
  source_code_uri: https://github.com/djberg96/mkmf-lite
161
162
  wiki_uri: https://github.com/djberg96/mkmf-lite/wiki
162
163
  rubygems_mfa_required: 'true'
164
+ github_repo: https://github.com/djberg96/mkmf-lite
165
+ funding_uri: https://github.com/sponsors/djberg96
163
166
  post_install_message:
164
167
  rdoc_options: []
165
168
  require_paths:
@@ -175,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
178
  - !ruby/object:Gem::Version
176
179
  version: '0'
177
180
  requirements: []
178
- rubygems_version: 3.5.16
181
+ rubygems_version: 3.5.22
179
182
  signing_key:
180
183
  specification_version: 4
181
184
  summary: A lighter version of mkmf designed for use as a library
metadata.gz.sig CHANGED
Binary file