rb_sys 0.9.48 → 0.9.50

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: 0c20a93e6f901cd93729c524f5637ea642504062393f119c5972ccc198f5c431
4
- data.tar.gz: 7c3ac7ce3e4085eaadbba8a546ce6a8aabbb61ef8f4b79a47604a8876644bfcc
3
+ metadata.gz: 3b74d52f8db6d2d17f777a1eda0222ea8ad9960475fed697afacdd35f8e7ae79
4
+ data.tar.gz: fb24cccae1c2a1ae04e1dad6764c7c454e8e87e5f3d1cddbc118fd9d28281447
5
5
  SHA512:
6
- metadata.gz: a39231d9b950fcc2e5b589ef64e7309c76247cc199feaa4eedaba5137fbdb6cb77daba429990b2a91a5fc3c173c6d677e17a59c573ab680b83d40d4c5c38ede7
7
- data.tar.gz: 21ac41ec59a49f655a12315066f720036bac026ed086fd410a0562cf3f75c1620992346f33d7d106c50b0d7e9b7f7cb001186fe8f8f9425450dfde0687ccc882
6
+ metadata.gz: b6273e7a26eaff960d8e0f95f8d2d3601b70a438ac48969588299336f97fae8a8d80c7be2de4d4b32e8054b048da608f397c32e2b0bc810adec4c05b65b7a967
7
+ data.tar.gz: 111dc76d283d514786da3661ec73753c6cabf9aaf6e62e14b8b9b27d5e93943c7b1881457adf2058227cb17cfda0ed4066344b87a51c6d2ff42eaa60d3acea41
checksums.yaml.gz.sig CHANGED
Binary file
data/exe/rb-sys-dock CHANGED
@@ -3,6 +3,7 @@
3
3
  require "optparse"
4
4
  require "rb_sys/version"
5
5
  require "rb_sys/toolchain_info"
6
+ require "fileutils"
6
7
 
7
8
  options = {
8
9
  version: RbSys::VERSION
@@ -18,6 +19,10 @@ def log(level, message, emoji: true, io: $stderr)
18
19
  ["ℹ️", "\e[1;37m"]
19
20
  when :notice
20
21
  ["🐳", "\e[1;34m"]
22
+ when :trace
23
+ return unless ENV["LOG_LEVEL"] == "trace"
24
+
25
+ ["🔍", "\e[1;2m"]
21
26
  else raise "Unknown log level: #{level.inspect}"
22
27
  end
23
28
 
@@ -27,7 +32,10 @@ def log(level, message, emoji: true, io: $stderr)
27
32
  emoji_opt + " "
28
33
  end
29
34
 
30
- io.puts "#{shellcode}#{emoji_opt}#{message}\e[0m"
35
+ # Escape the message for bash shell codes (e.g. \e[1;31m)
36
+ escaped = message.gsub("\\", "\\\\\\").gsub("\e", "\\e")
37
+
38
+ io.puts "#{shellcode}#{emoji_opt}#{escaped}\e[0m"
31
39
  end
32
40
 
33
41
  OptionParser.new do |opts|
@@ -73,37 +81,126 @@ OptionParser.new do |opts|
73
81
  puts opts
74
82
  exit
75
83
  end
76
- end.parse!
77
84
 
78
- def rcd(input_args)
79
- begin
80
- require "rake_compiler_dock"
81
- rescue LoadError
82
- abort "rake-compiler-dock is not installed. Please run `gem install rake-compiler-dock` to use this command."
85
+ opts.on("-V", "--verbose", "Prints verbose output") do
86
+ ENV["LOG_LEVEL"] = "trace"
87
+ ENV["VERBOSE"] = "1"
88
+ options[:verbose] = true
83
89
  end
90
+ end.parse!
84
91
 
85
- args = input_args.empty? ? ["bash"] : input_args.dup
92
+ def determine_cache_dir
93
+ return ENV["RB_SYS_DOCK_CACHE_DIR"] if ENV["RB_SYS_DOCK_CACHE_DIR"]
94
+ return File.join(ENV["XDG_CACHE_HOME"], "rb-sys-dock") if ENV["XDG_CACHE_HOME"]
86
95
 
87
- if $stdin.tty?
88
- # An interactive session should not leave the container on Ctrl-C
89
- args << {sigfw: false}
90
- end
96
+ File.join(ENV["HOME"], ".cache", "rb-sys-dock")
97
+ end
91
98
 
92
- begin
93
- RakeCompilerDock.exec(*args) do |ok, res|
94
- exit(res.exitstatus)
95
- end
96
- rescue RakeCompilerDock::DockerIsNotAvailable
97
- exit(-1)
99
+ def docker_tmp
100
+ @docker_tmp ||= "/tmp/rb-sys-dock"
101
+ end
102
+
103
+ def cache_dir
104
+ return @cache_dir if defined?(@cache_dir)
105
+
106
+ @cache_dir = determine_cache_dir
107
+ FileUtils.mkdir_p(@cache_dir)
108
+ @cache_dir
109
+ end
110
+
111
+ def mount_cargo_registry
112
+ local_registry_dir = if ENV["CARGO_HOME"]
113
+ ENV["CARGO_HOME"]
114
+ elsif File.exist?(cargo_home = File.join(ENV["HOME"], ".cargo"))
115
+ cargo_home
116
+ else
117
+ File.join(cache_dir, "cargo")
98
118
  end
119
+
120
+ dir = File.join("registry")
121
+ log(:trace, "Mounting cargo registry dir: #{dir}")
122
+ FileUtils.mkdir_p(dir)
123
+
124
+ "--mount type=bind,source=#{File.join(local_registry_dir, dir)},target=#{File.join("/usr/local/cargo", dir)},readonly=false"
125
+ end
126
+
127
+ def mount_bundle_cache(options, extra_env)
128
+ dir = File.join(cache_dir, options.fetch(:platform), "bundle")
129
+ FileUtils.mkdir_p(dir)
130
+ log(:trace, "Mounting bundle cache: #{dir}")
131
+ "-v #{dir}:#{File.join(docker_tmp, "bundle")}"
132
+ end
133
+
134
+ def mount_target_dir(options, _extra_env)
135
+ tmp_target_dir = File.join(Dir.pwd, "tmp", "rb-sys-dock", options[:platform], "target")
136
+ FileUtils.mkdir_p(tmp_target_dir)
137
+ "-v #{tmp_target_dir}:#{File.join(Dir.pwd, "target")}"
138
+ end
139
+
140
+ def mount_command_history(options)
141
+ return unless $stdin.tty?
142
+
143
+ history_dir = File.join(cache_dir, options.fetch(:platform), "commandhistory")
144
+ "-v #{history_dir}:#{File.join(docker_tmp, "commandhistory")}"
145
+ end
146
+
147
+ def rcd(input_args, options)
148
+ wrapper_command = []
149
+ wrapper_command << "sigfw" unless $stdin.tty?
150
+ wrapper_command << "runas"
151
+
152
+ extra_env = []
153
+
154
+ docker_options = []
155
+ docker_options << "--tty" if $stdin.tty?
156
+ run_command = input_args.empty? ? "bash" : input_args.join(" ")
157
+
158
+ cmd = <<~SH
159
+ #{docker_command} run \
160
+ -v #{Dir.pwd}:#{Dir.pwd} \
161
+ #{mount_target_dir(options, extra_env)} \
162
+ #{mount_cargo_registry} \
163
+ #{mount_bundle_cache(options, extra_env)} \
164
+ #{mount_command_history(options)} \
165
+ -e UID=#{ENV.fetch("RB_SYS_DOCK_UID", "1000")} \
166
+ -e GID=#{ENV.fetch("RB_SYS_DOCK_GID", "1000")} \
167
+ -e USER=rb-sys-dock \
168
+ -e GROUP=_staff \
169
+ -e GEM_PRIVATE_KEY_PASSPHRASE \
170
+ -e ftp_proxy \
171
+ -e http_proxy \
172
+ -e https_proxy \
173
+ -e RCD_HOST_RUBY_PLATFORM=#{RbConfig::CONFIG["arch"]} \
174
+ -e RCD_HOST_RUBY_VERSION=#{RUBY_VERSION} \
175
+ -e RCD_IMAGE \
176
+ -e TERM \
177
+ -w #{Dir.pwd} \
178
+ --rm \
179
+ --interactive \
180
+ #{docker_options.join(" ")} \
181
+ #{ENV.fetch("RCD_IMAGE")} \
182
+ #{wrapper_command.join(" ")} \
183
+ #{run_command}
184
+ SH
185
+
186
+ log(:trace, "Running command: \n$ #{cmd}")
187
+
188
+ exec(cmd)
189
+ end
190
+
191
+ def docker_command
192
+ return @docker_command if defined?(@docker_command)
193
+
194
+ @docker_command = ENV.fetch("DOCKER", "docker")
99
195
  end
100
196
 
101
197
  def download_image(_options)
102
198
  image = ENV.fetch("RCD_IMAGE")
103
- if `docker images -q #{image}`.strip.empty?
199
+
200
+ if `#{docker_command} images -q #{image}`.strip.empty?
104
201
  # Nicely formatted message that we are downloading the image which might take awhile
105
202
  log(:notice, "Downloading container #{image.inspect}, this might take awhile...")
106
- system("docker pull #{image} --quiet > /dev/null")
203
+ system("#{docker_command} pull #{image} --quiet > /dev/null")
107
204
  end
108
205
  end
109
206
 
@@ -116,10 +213,10 @@ def log_some_useful_info(_options)
116
213
  end
117
214
 
118
215
  def set_env(options)
119
- ENV["RCD_IMAGE"] = "rbsys/#{options[:toolchain_info]}:#{options[:version]}"
216
+ ENV["RCD_IMAGE"] ||= "rbsys/#{options[:toolchain_info].platform}:#{options[:version]}"
120
217
  end
121
218
 
122
219
  set_env(options)
123
220
  download_image(options)
124
221
  log_some_useful_info(options)
125
- rcd(ARGV)
222
+ rcd(ARGV, options)
@@ -1,10 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "shellwords"
4
+
3
5
  module RbSys
4
- class CargoBuilder
6
+ class CargoBuilder < Gem::Ext::Builder
5
7
  # Converts Ruby link flags into something cargo understands
6
8
  class LinkFlagConverter
7
- def self.convert(arg)
9
+ FILTERED_PATTERNS = [
10
+ /compress-debug-sections/ # Not supported by all linkers, and not required for Rust
11
+ ]
12
+
13
+ def self.convert(args)
14
+ Shellwords.split(args).flat_map { |arg| convert_arg(arg) }
15
+ end
16
+
17
+ def self.convert_arg(arg)
18
+ return [] if FILTERED_PATTERNS.any? { |p| p.match?(arg) }
19
+
8
20
  case arg.chomp
9
21
  when /^-L\s*(.+)$/
10
22
  ["-L", "native=#{$1}"]
@@ -1,3 +1,5 @@
1
+ require_relative "cargo_builder/link_flag_converter"
2
+
1
3
  module RbSys
2
4
  # A class to build a Ruby gem Cargo. Extracted from `rubygems` gem, with some modifications.
3
5
  class CargoBuilder < Gem::Ext::Builder
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbSys
4
- VERSION = "0.9.48"
4
+ VERSION = "0.9.50"
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.48
4
+ version: 0.9.50
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: 2022-12-12 00:00:00.000000000 Z
33
+ date: 2022-12-13 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email:
metadata.gz.sig CHANGED
Binary file