rb_sys 0.9.127 → 0.9.129

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: cfc10236ea19ee031b7296523be78667b5ae90408c4111180a12c29e93ae1586
4
- data.tar.gz: cb8d43340e414462a3d446181a8ed16c49a998967098e8ed7a84b09e27ba3571
3
+ metadata.gz: 82ca808ba001224b45263763167b562faad29ce575bf8b490845cf85e555bc26
4
+ data.tar.gz: ef1ab354b5451ad6e815eebd65e9863a58e9cb73d0dd13732b2ffaa0db1e48ed
5
5
  SHA512:
6
- metadata.gz: 7e9d5c929ca44955127ec55a288f7ceefe6222dd0035cb9b730557150d90175dca62e09c06baed60a6fd11ac234212727076241170b5d370b5cf300f388c30ff
7
- data.tar.gz: 58ec6c8e410ccb5a52be1b671c984dbad5c369b456715f06fb27614f00fbd9cbfbe25ca9e0c1d0dada496f48de6b6e282d882e69d2e64e6d5446fcf8196b0a7f
6
+ metadata.gz: 062cc26ba140d61fc252b877446601287cd4098be9e7bbf3d8b464d2f3c08439bf749d8dc548fd44c38f33f7627f33ec908f1ff7e6e6db07fccb9e7ded30aaf6
7
+ data.tar.gz: 6b65c7ba433bf42579a13b43874155528fff7e1967e64f83cb304dc07223a7d3bd3f9c219ee8109edeb57ec511112421677ab09976c1d8508ee91553ea0c4e6c
checksums.yaml.gz.sig CHANGED
@@ -1 +1,4 @@
1
- ��~!`���A[�WA�FG࣊#ɋקp{6�� 9w鯳��Z"�R�ӝ��� �! a �?�a^���n�Z����q̘2�`�|q��]�LQ�u�R���� 9j;�)�C�A��86<��͗�p�QJ�y���E���nV�R�=���1H)�K9l���.��[L"vJx��u���U-�2.��j��.܎fsȈ�ݡ�'�S�'p K�ێ.^wr��10�E�� Q*Y��
1
+ �'�*����ft1�xmG[Lԡ�u�����v�#��^mA���aBbiC�p�M��΀�̈́�$L�?T�����[O��|!M������ӯ�!6Mr'���
2
+ ����BS�%�\�8%o��pT�k}:W݈���P��3;�p��wn��
3
+ X��fP�D#��X�2,Ϟ9Z�8�
4
+ �H�L���H\"���<���֬c!���~LL����*d�
data/exe/rb-sys-dock CHANGED
@@ -339,7 +339,7 @@ def default_command_to_run(input_args)
339
339
  input_cmd = input_args.empty? ? "true" : input_args.join(" ")
340
340
 
341
341
  if OPTIONS[:build]
342
- 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"
343
343
  without_bundle = "#{input_cmd} && rake native:$RUBY_TARGET gem"
344
344
  logger.info("Running default build command (rake native:#{ruby_platform} gem)")
345
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
@@ -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/error.rb CHANGED
@@ -32,7 +32,7 @@ module RbSys
32
32
  - Make sure `cargo` is installed and in your PATH
33
33
  MSG
34
34
 
35
- if !stderr.empty?
35
+ if stderr && !stderr.empty?
36
36
  indented_stderr = stderr.lines.map { |line| " #{line}" }.join
37
37
  msg << "Stderr from `cargo metadata` was:\n#{indented_stderr}"
38
38
  end
@@ -29,8 +29,8 @@ module RbSys
29
29
  def init(name = nil, gem_spec = nil)
30
30
  super(name, lint_gem_spec(name, gem_spec))
31
31
 
32
- @orginal_ext_dir = @ext_dir
33
- @ext_dir = cargo_metadata.manifest_directory
32
+ @original_ext_dir = @ext_dir
33
+ @ext_dir = cargo_manifest_directory
34
34
  @source_pattern = nil
35
35
  @compiled_pattern = "*.{obj,so,bundle,dSYM}"
36
36
  @cross_compile = ENV.key?("RUBY_TARGET")
@@ -61,7 +61,7 @@ module RbSys
61
61
  end
62
62
 
63
63
  def extconf
64
- File.join(cargo_metadata.manifest_directory, "extconf.rb")
64
+ File.join(ext_dir, "extconf.rb")
65
65
  end
66
66
 
67
67
  def binary(_platf)
@@ -86,6 +86,8 @@ module RbSys
86
86
  end
87
87
 
88
88
  def target_directory
89
+ return fallback_target_directory if @cargo_metadata_unavailable
90
+
89
91
  cargo_metadata.target_directory
90
92
  end
91
93
 
@@ -104,7 +106,7 @@ module RbSys
104
106
  def define_env_tasks
105
107
  task "rb_sys:env:default" do
106
108
  ENV["RB_SYS_CARGO_TARGET_DIR"] ||= target_directory
107
- ENV["RB_SYS_CARGO_MANIFEST_DIR"] ||= cargo_metadata.manifest_directory
109
+ ENV["RB_SYS_CARGO_MANIFEST_DIR"] ||= File.expand_path(ext_dir)
108
110
  ENV["RB_SYS_CARGO_PROFILE"] ||= "release"
109
111
  end
110
112
 
@@ -129,6 +131,33 @@ module RbSys
129
131
 
130
132
  private
131
133
 
134
+ def cargo_manifest_directory
135
+ cargo_metadata.manifest_directory
136
+ rescue CargoMetadataError
137
+ raise unless force_install_rust_toolchain?
138
+
139
+ # Let the generated Makefile install Cargo before the extension is built.
140
+ @cargo_metadata_unavailable = true
141
+ File.expand_path(configured_extension_directory)
142
+ end
143
+
144
+ def configured_extension_directory
145
+ extension = @gem_spec&.extensions&.find do |path|
146
+ %w[Cargo.toml extconf.rb].include?(File.basename(path))
147
+ end
148
+
149
+ extension ? File.dirname(extension) : @original_ext_dir
150
+ end
151
+
152
+ def fallback_target_directory
153
+ File.expand_path(ENV["RB_SYS_CARGO_TARGET_DIR"] || ENV["CARGO_TARGET_DIR"] || "target")
154
+ end
155
+
156
+ def force_install_rust_toolchain?
157
+ value = ENV["RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN"]
158
+ value && value != "false"
159
+ end
160
+
132
161
  def lint_gem_spec(name, gs)
133
162
  gem_spec = case gs
134
163
  when :undefined
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
@@ -297,7 +297,7 @@ module RbSys
297
297
  return
298
298
  end
299
299
 
300
- %($(Q) #{tool} -id "" $(DLLIB))
300
+ %($(Q) #{tool} -id "$(notdir $(DLLIB))" $(DLLIB))
301
301
  end
302
302
 
303
303
  def if_eq_stmt(a, b)
@@ -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.127"
4
+ VERSION = "0.9.129"
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.127
4
+ version: 0.9.129
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
@@ -60,6 +60,7 @@ files:
60
60
  - exe/rb-sys-dock
61
61
  - lib/rb_sys.rb
62
62
  - lib/rb_sys/cargo.rb
63
+ - lib/rb_sys/cargo/config.rb
63
64
  - lib/rb_sys/cargo/metadata.rb
64
65
  - lib/rb_sys/cargo_builder.rb
65
66
  - lib/rb_sys/cargo_builder/link_flag_converter.rb
metadata.gz.sig CHANGED
Binary file