rb_sys 0.9.58 → 0.9.60

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90a652030d4a4a3f53dc1ddfcfcae46d3f46508c7911308ef75a818e82682e35
4
- data.tar.gz: 5e08a0ffdb50841e50d876e242b7e7c22424a31920da80494ae22e2343c49f71
3
+ metadata.gz: 84546ca4af298b39d45c6c8b931d59671a1e04900a8e2b86a852c9921475442d
4
+ data.tar.gz: 6ea6cde3068e5fa49eed2c9fbedc676eb48bb6932922d986f6d691f5a25eb7a4
5
5
  SHA512:
6
- metadata.gz: 5907903b2ad6b8d2bb2415d5d0b4dff44e42c91f4e1ff4ce664746d1f772321984b96a7201226116136fee6448105ba733fc76fe9bcaef5e5751521e0146c0bd
7
- data.tar.gz: 1acfbea1fb82441f241e4b6c325d6f984ba58cee320957605ba5b0f43b5109c207b1cd5ddc8a15ad0e125cb335df886d12ecd306ebcafd45deff733447010860
6
+ metadata.gz: a9f6f0bbe1a74b1bd994217d7d25c89abce2df9b10b44dad0b656d906b02edc3aec1b142c927a57e773ea9e6764cb90f59657700a232775515717c450f42bf7d
7
+ data.tar.gz: c17a3fda12f884ab3577c1b9ee16f1aada070fc2935421b36fa7888cbd521a6c0c5d20848642829fe337e1da88f298941d3ab0409587d778668e175115ec6019
checksums.yaml.gz.sig CHANGED
Binary file
data/exe/rb-sys-dock CHANGED
@@ -4,6 +4,7 @@ require "optparse"
4
4
  require "rb_sys/version"
5
5
  require "rb_sys/toolchain_info"
6
6
  require "fileutils"
7
+ require "tmpdir"
7
8
 
8
9
  options = {
9
10
  version: RbSys::VERSION
@@ -101,6 +102,7 @@ OptionParser.new do |opts|
101
102
  opts.on("--latest", "Use the latest version of the Docker image") do
102
103
  log(:notice, "Using latest version of the Docker image", emoji: "🆕")
103
104
  options[:version] = "latest"
105
+ options[:no_cache] = true
104
106
  end
105
107
 
106
108
  opts.on("--list-platforms", "--list", "List all supported platforms") do
@@ -123,6 +125,10 @@ OptionParser.new do |opts|
123
125
  ENV["VERBOSE"] = "1"
124
126
  options[:verbose] = true
125
127
  end
128
+
129
+ opts.on("--build", "Build the Docker image") do
130
+ options[:build] = true
131
+ end
126
132
  end.parse!
127
133
 
128
134
  def determine_cache_dir
@@ -160,48 +166,113 @@ def mount_cargo_registry
160
166
  "--mount type=bind,source=#{File.join(local_registry_dir, dir)},target=#{File.join("/usr/local/cargo", dir)},readonly=false"
161
167
  end
162
168
 
163
- def mount_bundle_cache(options, extra_env)
164
- dir = File.join(cache_dir, options.fetch(:platform), "bundle")
169
+ def volume(src, dest, mode: "rw")
170
+ "--volume #{src}:#{dest}:rw"
171
+ end
172
+
173
+ def mount_bundle_cache(options)
174
+ unless File.exist?(File.join(Dir.pwd, "Gemfile"))
175
+ log(:trace, "Ignoring bundler config")
176
+ return
177
+ end
178
+
179
+ dir = File.join(cache_dir, options.fetch(:toolchain_info).platform, "bundle")
180
+ bundle_path = File.join(docker_tmp, "bundle")
165
181
  FileUtils.mkdir_p(dir)
166
182
  log(:trace, "Mounting bundle cache: #{dir}")
167
- "-v #{dir}:#{File.join(docker_tmp, "bundle")}"
183
+ bundle_config = gen_bundle_config_file(bundle_path)
184
+ bundle_dir = File.dirname(bundle_config)
185
+
186
+ "#{volume(dir, bundle_path)} -v #{bundle_dir}:#{File.join(Dir.pwd, ".bundle")}"
168
187
  end
169
188
 
170
- def mount_target_dir(options, _extra_env)
171
- tmp_target_dir = File.join(Dir.pwd, "tmp", "rb-sys-dock", options[:platform], "target")
172
- FileUtils.mkdir_p(tmp_target_dir)
173
- "-v #{tmp_target_dir}:#{File.join(Dir.pwd, "target")}"
189
+ def tmp_target_dir(options)
190
+ return @tmp_target_dir if defined?(@tmp_target_dir)
191
+
192
+ dir = File.join(Dir.pwd, "tmp", "rb-sys-dock", options.fetch(:toolchain_info).platform, "target")
193
+ FileUtils.mkdir_p(dir)
194
+ @tmp_target_dir = dir
195
+ end
196
+
197
+ def mount_target_dir(options)
198
+ "-v #{tmp_target_dir(options)}:#{File.join(Dir.pwd, "target")}"
174
199
  end
175
200
 
176
201
  def mount_command_history(options)
177
202
  return unless $stdin.tty?
178
203
 
179
204
  history_dir = File.join(cache_dir, options.fetch(:platform), "commandhistory")
205
+ FileUtils.mkdir_p(history_dir)
180
206
  "-v #{history_dir}:#{File.join(docker_tmp, "commandhistory")}"
181
207
  end
182
208
 
209
+ def default_command_to_run(input_args, options)
210
+ input_cmd = input_args.empty? ? "true" : input_args.join(" ")
211
+
212
+ if options[:build]
213
+ with_bundle = "test -f Gemfile && bundle install && #{input_cmd} && bundle exec rake native:$RUBY_TARGET gem"
214
+ without_bundle = "#{input_cmd} && rake native:$RUBY_TARGET gem"
215
+
216
+ log(:notice, "Running default build command:")
217
+ log(:notice, " $ rake native:#{options[:toolchain_info].platform} gem")
218
+ cargo_env = "export RB_SYS_CARGO_TARGET_DIR=#{tmp_target_dir(options)}"
219
+ "bash -c '#{cargo_env}; (#{with_bundle}) || (#{without_bundle})'"
220
+ else
221
+ input_args.empty? ? "bash" : "bash -c '#{input_args.join(" ")}'"
222
+ end
223
+ end
224
+
225
+ def uid_gid
226
+ if /darwin/.match?(RbConfig::CONFIG["host_os"])
227
+ ["1000", "1000"]
228
+ else
229
+ [Process.uid, Process.gid]
230
+ end
231
+ end
232
+
233
+ def user_mapping
234
+ uid, gid = uid_gid
235
+ "-e UID=#{uid} -e GID=#{gid} -e GROUP=_staff -e USER=rb-sys-dock"
236
+ end
237
+
238
+ def interactive?(input_args)
239
+ $stdin.tty?
240
+ end
241
+
242
+ def gen_bundle_config_file(path)
243
+ dir = Dir.mktmpdir("rb-sys-dock")
244
+ file = File.join(dir, "config")
245
+ File.write(file, <<~YAML)
246
+ ---
247
+ BUNDLE_JOBS: "4"
248
+ BUNDLE_RETRY: "4"
249
+ BUNDLE_PATH: #{path.inspect}
250
+ YAML
251
+
252
+ file
253
+ end
254
+
255
+ def mount_tmp_dir(options)
256
+ "--mount type=bind,source=#{Dir.mktmpdir},destination=#{Dir.pwd}/tmp/#{options.fetch(:toolchain_info).platform},readonly=false"
257
+ end
258
+
183
259
  def rcd(input_args, options)
184
260
  wrapper_command = []
185
- wrapper_command << "sigfw" unless $stdin.tty?
261
+ wrapper_command << "sigfw" unless interactive?(input_args)
186
262
  wrapper_command << "runas"
187
263
 
188
- extra_env = []
189
-
190
264
  docker_options = []
191
- docker_options << "--tty" if $stdin.tty?
192
- cmd = input_args.empty? ? "bash" : "bash -c '#{input_args.join(" ")}'"
265
+ docker_options << "--tty" if interactive?(input_args)
193
266
 
194
267
  cmd = <<~SH
195
268
  #{default_docker_command} run \
196
269
  -v #{Dir.pwd}:#{Dir.pwd} \
197
- #{mount_target_dir(options, extra_env)} \
270
+ #{mount_tmp_dir(options)} \
271
+ #{mount_target_dir(options)} \
198
272
  #{mount_cargo_registry} \
199
- #{mount_bundle_cache(options, extra_env)} \
273
+ #{mount_bundle_cache(options)} \
200
274
  #{mount_command_history(options)} \
201
- -e UID=#{ENV.fetch("RB_SYS_DOCK_UID", "1000")} \
202
- -e GID=#{ENV.fetch("RB_SYS_DOCK_GID", "1000")} \
203
- -e USER=rb-sys-dock \
204
- -e GROUP=_staff \
275
+ #{user_mapping} \
205
276
  -e GEM_PRIVATE_KEY_PASSPHRASE \
206
277
  -e ftp_proxy \
207
278
  -e http_proxy \
@@ -216,7 +287,7 @@ def rcd(input_args, options)
216
287
  #{docker_options.join(" ")} \
217
288
  #{ENV.fetch("RCD_IMAGE")} \
218
289
  #{wrapper_command.join(" ")} \
219
- #{cmd}
290
+ #{default_command_to_run(input_args, options)}
220
291
  SH
221
292
 
222
293
  log(:trace, "Running command: $ #{cmd}")
@@ -224,10 +295,10 @@ def rcd(input_args, options)
224
295
  exec(cmd)
225
296
  end
226
297
 
227
- def download_image(_options)
298
+ def download_image(options)
228
299
  image = ENV.fetch("RCD_IMAGE")
229
300
 
230
- if docker("images -q #{image}").strip.empty?
301
+ if docker("images -q #{image}").strip.empty? || options[:no_cache]
231
302
  # Nicely formatted message that we are downloading the image which might take awhile
232
303
  log(:notice, "Downloading container #{image.inspect}, this might take awhile...")
233
304
  docker("pull #{image} --quiet > /dev/null")
@@ -1,9 +1,12 @@
1
+ require "rubygems/ext"
2
+ require "rubygems/ext/builder"
1
3
  require_relative "cargo_builder/link_flag_converter"
2
4
 
3
5
  module RbSys
4
6
  # A class to build a Ruby gem Cargo. Extracted from `rubygems` gem, with some modifications.
5
7
  class CargoBuilder < Gem::Ext::Builder
6
- attr_accessor :spec, :runner, :env, :features, :target, :extra_rustc_args, :dry_run, :ext_dir, :extra_rustflags
8
+ attr_accessor :spec, :runner, :env, :features, :target, :extra_rustc_args, :dry_run, :ext_dir, :extra_rustflags,
9
+ :extra_cargo_args
7
10
  attr_writer :profile
8
11
 
9
12
  def initialize(spec)
@@ -17,6 +20,7 @@ module RbSys
17
20
  @features = []
18
21
  @target = ENV["CARGO_BUILD_TARGET"] || ENV["RUST_TARGET"]
19
22
  @extra_rustc_args = []
23
+ @extra_cargo_args = []
20
24
  @dry_run = true
21
25
  @ext_dir = nil
22
26
  @extra_rustflags = []
@@ -55,10 +59,9 @@ module RbSys
55
59
 
56
60
  def cargo_command(dest_path, args = [])
57
61
  manifest = File.join(ext_dir, "Cargo.toml")
58
- cargo = ENV.fetch("CARGO", "cargo")
59
62
 
60
63
  cmd = []
61
- cmd += [cargo, "rustc"]
64
+ cmd += ["cargo", "rustc"]
62
65
  cmd += ["--target", target] if target
63
66
  cmd += ["--target-dir", dest_path]
64
67
  cmd += ["--features", features.join(",")] unless features.empty?
@@ -68,7 +71,7 @@ module RbSys
68
71
  cmd += Gem::Command.build_args
69
72
  cmd += args
70
73
  cmd += ["--"]
71
- cmd += [*cargo_rustc_args(dest_path)]
74
+ cmd += [*rustc_args(dest_path)]
72
75
  cmd += extra_rustc_args
73
76
  cmd
74
77
  end
@@ -105,7 +108,7 @@ module RbSys
105
108
  result
106
109
  end
107
110
 
108
- def cargo_rustc_args(dest_dir)
111
+ def rustc_args(dest_dir)
109
112
  [
110
113
  *linker_args,
111
114
  *mkmf_libpath,
data/lib/rb_sys/mkmf.rb CHANGED
@@ -68,6 +68,7 @@ module RbSys
68
68
  #{conditional_assign("RB_SYS_CARGO_FEATURES", builder.features.join(","))}
69
69
  #{conditional_assign("RB_SYS_GLOBAL_RUSTFLAGS", GLOBAL_RUSTFLAGS.join(" "))}
70
70
  #{conditional_assign("RB_SYS_EXTRA_RUSTFLAGS", builder.extra_rustflags.join(" "))}
71
+ #{conditional_assign("RB_SYS_EXTRA_CARGO_ARGS", builder.extra_cargo_args.join(" "))}
71
72
 
72
73
  # Set dirname for the profile, since the profiles do not directly map to target dir (i.e. dev -> debug)
73
74
  #{if_eq_stmt("$(RB_SYS_CARGO_PROFILE)", "dev")}
@@ -163,7 +164,11 @@ module RbSys
163
164
  args = ARGV.dup
164
165
  args.shift if args.first == "--"
165
166
  cargo_cmd = builder.cargo_command(dest_path, args)
166
- Shellwords.join(cargo_cmd).gsub("\\=", "=").gsub(/\Acargo/, "$(CARGO)").gsub(/-v=\d/, "")
167
+ cmd = Shellwords.join(cargo_cmd)
168
+ cmd.gsub!("\\=", "=")
169
+ cmd.gsub!(/\Acargo rustc/, "$(CARGO) rustc $(RB_SYS_EXTRA_CARGO_ARGS)")
170
+ cmd.gsub!(/-v=\d/, "")
171
+ cmd
167
172
  end
168
173
 
169
174
  def env_vars(builder)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbSys
4
- VERSION = "0.9.58"
4
+ VERSION = "0.9.60"
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.58
4
+ version: 0.9.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
@@ -30,7 +30,7 @@ cert_chain:
30
30
  Rl+ASkq2/1i07TkBpCf+2hq66+h/hx+/Y/KrUzXfe0jtvil0WESkJT2kqRqHWNhD
31
31
  9GKBxaQlXokNDtWCm1/gl6cD8WRZ0N5S4ZGJT1FLLsA=
32
32
  -----END CERTIFICATE-----
33
- date: 2023-01-22 00:00:00.000000000 Z
33
+ date: 2023-02-02 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email:
metadata.gz.sig CHANGED
Binary file