rb_sys 0.9.126 → 0.9.128

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: 46e09c34d5c5b869948ee426e9d31c74a78ae8be25bb6df07899089cddf15f00
4
- data.tar.gz: 16a6269705d76fc42702ea69c6f18f69be09736f419210865ee4a66f21798eab
3
+ metadata.gz: 4907306eece620077a2b68e2b6f33a13a4e7c310e8937d1655229ff4cbc62605
4
+ data.tar.gz: bcca23169c98229da0467fffe834ac6de098261cea82fb7e90c6cb0273c048b8
5
5
  SHA512:
6
- metadata.gz: 1485a6d17ae171bf93978b65828a112021fcc3bdf67b037757618781723c4118dc3bbfa5010b8d334377a372a5086c419bdd6a69ba075b8c0ae2467a48eb86fd
7
- data.tar.gz: d392c3a4a80770ccce97d71535dc44e2d7107217243817497558dd67aa552662749b85c08ca39be6c7bf0775dfff023a0c4f3f4ea9e538e460a2aba99d2f1b4c
6
+ metadata.gz: 89690dc28b0a42302744554a4e9aac8c0573c88a016ffc67e4aed3873de3fad862947613403e46e711650eebf055751542473db0a64ce60b5c73134ac7ef9162
7
+ data.tar.gz: 10d2bd2e67bd9e937b300c5deb451c8d5fbdf88d39399815b6b7f7cdeb3c69a140048ed6c57b6d7a82a7a840fc47b66f04379a9c1273be200af383ee2f4923a0
checksums.yaml.gz.sig CHANGED
Binary file
data/exe/rb-sys-dock CHANGED
@@ -154,17 +154,42 @@ OptionParser.new do |opts|
154
154
  end
155
155
  end.parse!
156
156
 
157
+ def find_executable(name)
158
+ executable_file = ->(path) {
159
+ stat = begin
160
+ File.stat(path)
161
+ rescue
162
+ nil
163
+ end
164
+ path if stat&.file? && stat.executable?
165
+ }
166
+
167
+ # On Windows, PATHEXT lists the extensions that make a file executable
168
+ exts = ENV["PATHEXT"]&.split(File::PATH_SEPARATOR)&.map(&:downcase)
169
+
170
+ try_path = ->(path) {
171
+ executable_file.call(path) || exts&.lazy&.filter_map { |ext| executable_file.call(path + ext) }&.first
172
+ }
173
+
174
+ # Handle absolute/explicit paths without a PATH search
175
+ return try_path.call(name) if File.expand_path(name) == name
176
+
177
+ path_dirs = ENV.fetch("PATH", "/usr/local/bin:/usr/bin:/bin").split(File::PATH_SEPARATOR)
178
+ path_dirs.each do |dir|
179
+ dir = dir.sub(/\A"(.*)"\z/m, '\1') if /mswin|mingw/i.match?(RbConfig::CONFIG["host_os"])
180
+ found = try_path.call(File.join(dir, name))
181
+ return found if found
182
+ end
183
+ nil
184
+ end
185
+
157
186
  def default_docker_command
158
187
  return @default_docker_command if defined?(@default_docker_command)
159
188
 
160
189
  @default_docker_command = ENV.fetch("DOCKER") do
161
- if !(docker = `which docker`).empty?
162
- docker.strip
163
- elsif !(podman = `which podman`).empty?
164
- podman.strip
165
- else
190
+ find_executable("docker") ||
191
+ find_executable("podman") ||
166
192
  logger.fatal("Could not find docker or podman command, please install one of them")
167
- end
168
193
  end
169
194
  end
170
195
 
@@ -314,7 +339,7 @@ def default_command_to_run(input_args)
314
339
  input_cmd = input_args.empty? ? "true" : input_args.join(" ")
315
340
 
316
341
  if OPTIONS[:build]
317
- with_bundle = +"test -f Gemfile && bundle install && #{input_cmd} && bundle exec rake native:$RUBY_TARGET gem"
342
+ with_bundle = "test -f Gemfile && bundle install && #{input_cmd} && bundle exec rake native:$RUBY_TARGET gem"
318
343
  without_bundle = "#{input_cmd} && rake native:$RUBY_TARGET gem"
319
344
  logger.info("Running default build command (rake native:#{ruby_platform} gem)")
320
345
  "bash -c '(#{with_bundle}) || (#{without_bundle})'"
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbSys
4
+ module Cargo
5
+ # Reads Cargo configuration files to extract build settings.
6
+ module Config
7
+ class << self
8
+ # Returns the build target from Cargo configuration files.
9
+ # Searches from start_dir up to root, then checks CARGO_HOME.
10
+ #
11
+ # @param start_dir [String] the directory to start searching from
12
+ # @return [String, nil] the target triple, or nil if not configured
13
+ def build_target(start_dir: Dir.pwd)
14
+ find_in_hierarchy(start_dir) || find_in_home
15
+ end
16
+
17
+ private
18
+
19
+ def find_in_hierarchy(dir)
20
+ dir = File.expand_path(dir)
21
+ while (parent = File.dirname(dir)) != dir
22
+ target = read_build_target(File.join(dir, ".cargo"))
23
+ return target if target
24
+ dir = parent
25
+ end
26
+ nil
27
+ end
28
+
29
+ def find_in_home
30
+ cargo_home = ENV["CARGO_HOME"] || File.join(Dir.home, ".cargo")
31
+ read_build_target(cargo_home)
32
+ rescue ArgumentError
33
+ # Dir.home can raise if HOME is not set
34
+ nil
35
+ end
36
+
37
+ def read_build_target(cargo_dir)
38
+ # Version without `.toml` is for cargo < 1.39
39
+ %w[config.toml config].each do |name|
40
+ path = File.join(cargo_dir, name)
41
+ next unless File.exist?(path)
42
+ target = parse_build_target(File.read(path))
43
+ return target if target
44
+ rescue Errno::EACCES, Errno::ENOENT
45
+ next
46
+ end
47
+ nil
48
+ end
49
+
50
+ def parse_build_target(content)
51
+ # That is a hacky way to avoid pulling a proper toml parser as a dependency
52
+ current_section = nil
53
+ content.each_line do |line|
54
+ line = line.sub(/#.*/, "").strip
55
+ next if line.empty?
56
+
57
+ if line =~ /^\["?([^\]"]+)"?\]/
58
+ current_section = $1.strip
59
+ elsif current_section.nil? && line =~ /^"?build"?\."?target"?\s*=\s*["']([^"']+)["']/
60
+ return $1
61
+ elsif current_section.nil? && line =~ /^"?build"?\s*=\s*\{[^}]*"?target"?\s*=\s*["']([^"']+)["']/
62
+ return $1
63
+ elsif current_section == "build" && line =~ /^"?target"?\s*=\s*["']([^"']+)["']/
64
+ return $1
65
+ end
66
+ end
67
+ nil
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -145,6 +145,7 @@ module RbSys
145
145
  args = ["metadata", "--format-version", "1"]
146
146
  args << "--no-deps" unless @deps
147
147
  out, stderr, status = Open3.capture3(cargo, *args)
148
+ out.force_encoding(Encoding::UTF_8)
148
149
  raise "exited with non-zero status (#{status})" unless status.success?
149
150
  data = JSON.parse(out)
150
151
  raise "metadata must be a Hash" unless data.is_a?(Hash)
@@ -1,6 +1,7 @@
1
1
  require "rubygems/ext"
2
2
  require "rubygems/ext/builder"
3
3
  require_relative "cargo_builder/link_flag_converter"
4
+ require_relative "cargo/config"
4
5
 
5
6
  module RbSys
6
7
  # A class to build a Ruby gem Cargo. Extracted from `rubygems` gem, with some modifications.
@@ -21,7 +22,7 @@ module RbSys
21
22
  @profile = ENV.fetch("RB_SYS_CARGO_PROFILE", :release).to_sym
22
23
  @env = {}
23
24
  @features = []
24
- @target = ENV["CARGO_BUILD_TARGET"] || ENV["RUST_TARGET"]
25
+ @target = ENV["CARGO_BUILD_TARGET"] || ENV["RUST_TARGET"] || Cargo::Config.build_target
25
26
  @extra_rustc_args = []
26
27
  @extra_cargo_args = []
27
28
  @dry_run = true
data/lib/rb_sys/mkmf.rb CHANGED
@@ -56,7 +56,7 @@ module RbSys
56
56
  # global_rustflags << "--cfg=rb_sys_gem" unless builder.use_cargo_build
57
57
  global_rustflags << "--cfg=rb_sys_use_stable_api_compiled_fallback" if builder.use_stable_api_compiled_fallback?
58
58
 
59
- make_install = +<<~MAKE
59
+ make_install = <<~MAKE
60
60
  #{conditional_assign("RB_SYS_BUILD_DIR", File.join(Dir.pwd, ".rb-sys"))}
61
61
  #{conditional_assign("CARGO", "cargo")}
62
62
  #{conditional_assign("CARGO_BUILD_TARGET", builder.target)}
@@ -150,7 +150,7 @@ module RbSys
150
150
  all: #{$extout ? "install" : "$(DLLIB)"}
151
151
  MAKE
152
152
 
153
- gsub_cargo_command!(make_install, builder: builder)
153
+ make_install = gsub_cargo_command!(make_install.dup, builder: builder)
154
154
 
155
155
  File.write("Makefile", make_install)
156
156
  end
@@ -334,7 +334,7 @@ module RbSys
334
334
 
335
335
  def conditional_assign(a, b, export: false, indent: 0)
336
336
  if $nmake
337
- result = +"!IFNDEF #{a}\n#{a} = #{b}\n!ENDIF\n"
337
+ result = "!IFNDEF #{a}\n#{a} = #{b}\n!ENDIF\n"
338
338
  result << export_env(a, b) if export
339
339
  result
340
340
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbSys
4
- VERSION = "0.9.126"
4
+ VERSION = "0.9.128"
5
5
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_sys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.126
4
+ version: 0.9.128
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
@@ -31,34 +31,20 @@ cert_chain:
31
31
  -----END CERTIFICATE-----
32
32
  date: 1980-01-01 00:00:00.000000000 Z
33
33
  dependencies:
34
- - !ruby/object:Gem::Dependency
35
- name: json
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '2'
41
- type: :runtime
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '2'
48
34
  - !ruby/object:Gem::Dependency
49
35
  name: rake-compiler-dock
50
36
  requirement: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - '='
53
39
  - !ruby/object:Gem::Version
54
- version: 1.11.0
40
+ version: 1.12.0
55
41
  type: :runtime
56
42
  prerelease: false
57
43
  version_requirements: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - '='
60
46
  - !ruby/object:Gem::Version
61
- version: 1.11.0
47
+ version: 1.12.0
62
48
  email:
63
49
  - i.kerseymer@gmail.com
64
50
  executables:
@@ -74,6 +60,7 @@ files:
74
60
  - exe/rb-sys-dock
75
61
  - lib/rb_sys.rb
76
62
  - lib/rb_sys/cargo.rb
63
+ - lib/rb_sys/cargo/config.rb
77
64
  - lib/rb_sys/cargo/metadata.rb
78
65
  - lib/rb_sys/cargo_builder.rb
79
66
  - lib/rb_sys/cargo_builder/link_flag_converter.rb
@@ -107,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
94
  - !ruby/object:Gem::Version
108
95
  version: '0'
109
96
  requirements: []
110
- rubygems_version: 4.0.3
97
+ rubygems_version: 4.0.6
111
98
  specification_version: 4
112
99
  summary: Helpers for compiling Rust extensions for ruby
113
100
  test_files: []
metadata.gz.sig CHANGED
Binary file