rb_sys 0.9.41 → 0.9.43
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 +4 -4
- checksums.yaml.gz.sig +1 -1
- data/lib/rb_sys/cargo_builder.rb +13 -1
- data/lib/rb_sys/mkmf/config.rb +6 -3
- data/lib/rb_sys/mkmf.rb +60 -33
- data/lib/rb_sys/toolchain_info.rb +7 -0
- data/lib/rb_sys/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abede1c651510cc3d4995a424e634a9ce4afcccf1a83f85151c737ad7b578463
|
|
4
|
+
data.tar.gz: 17d3ea227ca871ae8fb1fc19a6964d57101747a8de0564b95caeda4b042ee8df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbbc55012efc13e0eb0ba2c3c578a96e1cca965cc8a8691e8c3e48b008c5603df73d80fbe493b6653582a0461fb7d9b3fbeb4fa8bcbe711c33468714631883de
|
|
7
|
+
data.tar.gz: e12945fed0147192dfdc4c8cbbaa01a34a734c358c3766970e285b563bf4b866216bb489a3075e89ab4f3860d5dce078db0ab291df126006de7718c156a7a280
|
checksums.yaml.gz.sig
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
�9��㼫:
|
data/lib/rb_sys/cargo_builder.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module RbSys
|
|
2
|
+
# A class to build a Ruby gem Cargo. Extracted from `rubygems` gem, with some modifications.
|
|
2
3
|
class CargoBuilder < Gem::Ext::Builder
|
|
3
|
-
attr_accessor :spec, :runner, :
|
|
4
|
+
attr_accessor :spec, :runner, :env, :features, :target, :extra_rustc_args, :dry_run, :ext_dir, :extra_rustflags
|
|
5
|
+
attr_writer :profile
|
|
4
6
|
|
|
5
7
|
def initialize(spec)
|
|
6
8
|
require "rubygems/command"
|
|
@@ -18,6 +20,12 @@ module RbSys
|
|
|
18
20
|
@extra_rustflags = []
|
|
19
21
|
end
|
|
20
22
|
|
|
23
|
+
def profile
|
|
24
|
+
return :release if rubygems_invoked?
|
|
25
|
+
|
|
26
|
+
@profile
|
|
27
|
+
end
|
|
28
|
+
|
|
21
29
|
def build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd)
|
|
22
30
|
require "fileutils"
|
|
23
31
|
require "shellwords"
|
|
@@ -323,6 +331,10 @@ module RbSys
|
|
|
323
331
|
end
|
|
324
332
|
end
|
|
325
333
|
|
|
334
|
+
def rubygems_invoked?
|
|
335
|
+
ENV.key?("SOURCE_DATE_EPOCH")
|
|
336
|
+
end
|
|
337
|
+
|
|
326
338
|
# Error raised when no cdylib artifact was created
|
|
327
339
|
class DylibNotFoundError < StandardError
|
|
328
340
|
def initialize(dir)
|
data/lib/rb_sys/mkmf/config.rb
CHANGED
|
@@ -4,14 +4,19 @@ module RbSys
|
|
|
4
4
|
module Mkmf
|
|
5
5
|
# Config that delegates to CargoBuilder if needded
|
|
6
6
|
class Config
|
|
7
|
-
attr_accessor :force_install_rust_toolchain, :clean_after_install
|
|
7
|
+
attr_accessor :force_install_rust_toolchain, :clean_after_install, :target_dir, :auto_install_rust_toolchain
|
|
8
8
|
|
|
9
9
|
def initialize(builder)
|
|
10
10
|
@builder = builder
|
|
11
11
|
@force_install_rust_toolchain = false
|
|
12
|
+
@auto_install_rust_toolchain = true
|
|
12
13
|
@clean_after_install = rubygems_invoked?
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
def cross_compiling?
|
|
17
|
+
RbConfig::CONFIG["CROSS_COMPILING"] == "yes"
|
|
18
|
+
end
|
|
19
|
+
|
|
15
20
|
def method_missing(name, *args, &blk)
|
|
16
21
|
@builder.send(name, *args, &blk)
|
|
17
22
|
end
|
|
@@ -20,8 +25,6 @@ module RbSys
|
|
|
20
25
|
@builder.respond_to?(name) || super
|
|
21
26
|
end
|
|
22
27
|
|
|
23
|
-
private
|
|
24
|
-
|
|
25
28
|
# Seems to be the only way to reliably know if we were invoked by Rubygems.
|
|
26
29
|
# We want to know this so we can cleanup the target directory after an
|
|
27
30
|
# install, to remove bloat.
|
data/lib/rb_sys/mkmf.rb
CHANGED
|
@@ -18,20 +18,22 @@ module RbSys
|
|
|
18
18
|
#
|
|
19
19
|
# @example Basic
|
|
20
20
|
# require 'mkmf'
|
|
21
|
-
#
|
|
21
|
+
# require 'rb_sys/mkmf'
|
|
22
22
|
#
|
|
23
|
-
#
|
|
23
|
+
# create_rust_makefile("my_extension") #=> Generate a Makefile in the current directory
|
|
24
24
|
#
|
|
25
25
|
# @example Configure a custom build profile
|
|
26
26
|
# require 'mkmf'
|
|
27
|
-
#
|
|
27
|
+
# require 'rb_sys/mkmf'
|
|
28
28
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
29
|
+
# create_rust_makefile("my_extension") do |r|
|
|
30
|
+
# # All of these are optional
|
|
31
|
+
# r.env = { 'FOO' => 'bar' }
|
|
32
|
+
# r.profile = ENV.fetch('RB_SYS_CARGO_PROFILE', :dev).to_sym
|
|
33
|
+
# r.features = %w[some_cargo_feature]
|
|
34
|
+
# r.rustflags = %w[--cfg=foo]
|
|
35
|
+
# r.target_dir = "some/target/dir"
|
|
36
|
+
# end
|
|
35
37
|
def create_rust_makefile(target, &blk)
|
|
36
38
|
if target.include?("/")
|
|
37
39
|
target_prefix, target = File.split(target)
|
|
@@ -62,7 +64,7 @@ module RbSys
|
|
|
62
64
|
#{conditional_assign("SOEXT_PREFIX", "lib", indent: 1)}
|
|
63
65
|
#{endif_stmt}
|
|
64
66
|
|
|
65
|
-
#{
|
|
67
|
+
#{set_cargo_profile(builder)}
|
|
66
68
|
#{conditional_assign("RB_SYS_CARGO_FEATURES", builder.features.join(","))}
|
|
67
69
|
#{conditional_assign("RB_SYS_GLOBAL_RUSTFLAGS", GLOBAL_RUSTFLAGS.join(" "))}
|
|
68
70
|
#{conditional_assign("RB_SYS_EXTRA_RUSTFLAGS", builder.extra_rustflags.join(" "))}
|
|
@@ -82,27 +84,30 @@ module RbSys
|
|
|
82
84
|
#{endif_stmt}
|
|
83
85
|
|
|
84
86
|
# Account for sub-directories when using `--target` argument with Cargo
|
|
87
|
+
#{conditional_assign("RB_SYS_CARGO_TARGET_DIR", "target")}
|
|
85
88
|
#{if_neq_stmt("$(CARGO_BUILD_TARGET)", "")}
|
|
86
|
-
#{assign_stmt("
|
|
89
|
+
#{assign_stmt("RB_SYS_FULL_TARGET_DIR", "$(RB_SYS_CARGO_TARGET_DIR)/$(CARGO_BUILD_TARGET)", indent: 1)}
|
|
87
90
|
#{else_stmt}
|
|
88
|
-
#{assign_stmt("
|
|
91
|
+
#{assign_stmt("RB_SYS_FULL_TARGET_DIR", "$(RB_SYS_CARGO_TARGET_DIR)", indent: 1)}
|
|
89
92
|
#{endif_stmt}
|
|
90
93
|
|
|
91
94
|
target_prefix = #{target_prefix}
|
|
92
95
|
TARGET_NAME = #{target[/\A\w+/]}
|
|
93
96
|
TARGET_ENTRY = #{RbConfig::CONFIG["EXPORT_PREFIX"]}Init_$(TARGET_NAME)
|
|
94
|
-
RUBYARCHDIR
|
|
97
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
|
95
98
|
TARGET = #{target}
|
|
96
99
|
DLLIB = $(TARGET).#{RbConfig::CONFIG["DLEXT"]}
|
|
97
|
-
|
|
98
|
-
RUSTLIB = $(
|
|
100
|
+
RUSTLIBDIR = $(RB_SYS_FULL_TARGET_DIR)/$(RB_SYS_CARGO_PROFILE_DIR)
|
|
101
|
+
RUSTLIB = $(RUSTLIBDIR)/$(SOEXT_PREFIX)$(TARGET_NAME).$(SOEXT)
|
|
99
102
|
|
|
100
|
-
CLEANOBJS = $(
|
|
101
|
-
DEFFILE = $(
|
|
103
|
+
CLEANOBJS = $(RUSTLIBDIR) $(RB_SYS_BUILD_DIR)
|
|
104
|
+
DEFFILE = $(RUSTLIBDIR)/$(TARGET)-$(arch).def
|
|
102
105
|
CLEANLIBS = $(DLLIB) $(RUSTLIB) $(DEFFILE)
|
|
103
106
|
|
|
104
107
|
#{base_makefile(srcdir)}
|
|
105
108
|
|
|
109
|
+
.PHONY: gemclean
|
|
110
|
+
|
|
106
111
|
#{if_neq_stmt("$(RB_SYS_VERBOSE)", "")}
|
|
107
112
|
#{assign_stmt("Q", "$(0=@)", indent: 1)}
|
|
108
113
|
#{endif_stmt}
|
|
@@ -112,9 +117,9 @@ module RbSys
|
|
|
112
117
|
|
|
113
118
|
FORCE: ;
|
|
114
119
|
|
|
115
|
-
$(
|
|
120
|
+
$(RUSTLIBDIR):
|
|
116
121
|
\t$(ECHO) creating target directory \\($(@)\\)
|
|
117
|
-
\t$(Q) $(MAKEDIRS) $(
|
|
122
|
+
\t$(Q) $(MAKEDIRS) $(RUSTLIBDIR)
|
|
118
123
|
|
|
119
124
|
#{deffile_definition}
|
|
120
125
|
|
|
@@ -122,7 +127,7 @@ module RbSys
|
|
|
122
127
|
|
|
123
128
|
$(RUSTLIB): #{deffile_definition ? "$(DEFFILE) " : nil}FORCE
|
|
124
129
|
\t$(ECHO) generating $(@) \\("$(RB_SYS_CARGO_PROFILE)"\\)
|
|
125
|
-
\t
|
|
130
|
+
\t#{full_cargo_command}
|
|
126
131
|
|
|
127
132
|
$(DLLIB): $(RUSTLIB)
|
|
128
133
|
\t$(Q) $(COPY) "$(RUSTLIB)" $@
|
|
@@ -132,7 +137,10 @@ module RbSys
|
|
|
132
137
|
\t$(Q) $(MAKEDIRS) $(RUBYARCHDIR)
|
|
133
138
|
\t$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
|
134
139
|
|
|
135
|
-
|
|
140
|
+
gemclean:
|
|
141
|
+
\t-$(Q)$(RM_RF) $(CLEANOBJS) $(CLEANFILES) 2> /dev/null || true
|
|
142
|
+
|
|
143
|
+
install: #{builder.clean_after_install ? "install-so gemclean" : "install-so"}
|
|
136
144
|
|
|
137
145
|
all: #{$extout ? "install" : "$(DLLIB)"}
|
|
138
146
|
MAKE
|
|
@@ -153,7 +161,7 @@ module RbSys
|
|
|
153
161
|
|
|
154
162
|
def cargo_command(cargo_dir, builder)
|
|
155
163
|
builder.ext_dir = cargo_dir
|
|
156
|
-
dest_path = File.join(Dir.pwd, "target")
|
|
164
|
+
dest_path = builder.target_dir || File.join(Dir.pwd, "target")
|
|
157
165
|
args = ARGV.dup
|
|
158
166
|
args.shift if args.first == "--"
|
|
159
167
|
cargo_cmd = builder.cargo_command(dest_path, args)
|
|
@@ -181,8 +189,7 @@ module RbSys
|
|
|
181
189
|
cargo_command.gsub!(/--profile \w+/, "$(RB_SYS_CARGO_PROFILE_FLAG)")
|
|
182
190
|
cargo_command.gsub!(%r{--features \S+}, "--features $(RB_SYS_CARGO_FEATURES)")
|
|
183
191
|
cargo_command.gsub!(%r{--target \S+}, "--target $(CARGO_BUILD_TARGET)")
|
|
184
|
-
|
|
185
|
-
cargo_command.gsub!(%r{/#{target_dir}/[^/]+}, "/$(RB_SYS_CARGO_BUILD_TARGET_DIR)/$(RB_SYS_CARGO_PROFILE_DIR)")
|
|
192
|
+
cargo_command.gsub!(/--target-dir (?:(?!--).)+/, "--target-dir $(RB_SYS_CARGO_TARGET_DIR) ")
|
|
186
193
|
cargo_command
|
|
187
194
|
end
|
|
188
195
|
|
|
@@ -192,18 +199,14 @@ module RbSys
|
|
|
192
199
|
return unless defined?(EXPORT_PREFIX) && EXPORT_PREFIX
|
|
193
200
|
|
|
194
201
|
@deffile_definition ||= <<~MAKE
|
|
195
|
-
$(DEFFILE): $(
|
|
202
|
+
$(DEFFILE): $(RUSTLIBDIR)
|
|
196
203
|
\t$(ECHO) generating $(@)
|
|
197
204
|
\t$(Q) ($(COPY) $(srcdir)/$(TARGET).def $@ 2> /dev/null) || (echo EXPORTS && echo $(TARGET_ENTRY)) > $@
|
|
198
205
|
MAKE
|
|
199
206
|
end
|
|
200
207
|
|
|
201
|
-
def
|
|
208
|
+
def rust_toolchain_env(builder)
|
|
202
209
|
<<~MAKE
|
|
203
|
-
#{conditional_assign("RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN", builder.force_install_rust_toolchain)}
|
|
204
|
-
|
|
205
|
-
# Only run if the we are told to explicitly install the Rust toolchain
|
|
206
|
-
#{if_neq_stmt("$(RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN)", "false")}
|
|
207
210
|
#{conditional_assign("RB_SYS_RUSTUP_PROFILE", "minimal")}
|
|
208
211
|
|
|
209
212
|
# If the user passed true, we assume stable Rust. Otherwise, use what
|
|
@@ -227,18 +230,36 @@ module RbSys
|
|
|
227
230
|
#{export_env("PATH", "$(CARGO_HOME)/bin:$(RUSTUP_HOME)/bin:$(PATH)")}
|
|
228
231
|
#{export_env("RUSTUP_TOOLCHAIN", "$(RB_SYS_DEFAULT_TOOLCHAIN)")}
|
|
229
232
|
#{export_env("CARGO", "$(CARGO_HOME)/bin/cargo")}
|
|
233
|
+
MAKE
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def optional_rust_toolchain(builder)
|
|
237
|
+
<<~MAKE
|
|
238
|
+
#{conditional_assign("RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN", force_install_rust_toolchain?(builder))}
|
|
239
|
+
|
|
240
|
+
# Only run if the we are told to explicitly install the Rust toolchain
|
|
241
|
+
#{if_neq_stmt("$(RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN)", "false")}
|
|
242
|
+
#{rust_toolchain_env(builder)}
|
|
230
243
|
|
|
231
244
|
$(CARGO):
|
|
232
245
|
\t$(Q) $(MAKEDIRS) $(CARGO_HOME) $(RUSTUP_HOME)
|
|
233
|
-
\
|
|
234
|
-
\
|
|
235
|
-
\
|
|
246
|
+
\t$(Q) curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --no-modify-path --profile $(RB_SYS_RUSTUP_PROFILE) --default-toolchain none -y
|
|
247
|
+
\t$(Q) rustup toolchain install $(RB_SYS_DEFAULT_TOOLCHAIN) --profile $(RB_SYS_RUSTUP_PROFILE)
|
|
248
|
+
\t$(Q) rustup default $(RB_SYS_DEFAULT_TOOLCHAIN)
|
|
249
|
+
\t$(Q) rustup component add rustfmt
|
|
236
250
|
|
|
237
251
|
$(RUSTLIB): $(CARGO)
|
|
238
252
|
#{endif_stmt}
|
|
239
253
|
MAKE
|
|
240
254
|
end
|
|
241
255
|
|
|
256
|
+
def force_install_rust_toolchain?(builder)
|
|
257
|
+
return builder.force_install_rust_toolchain if builder.force_install_rust_toolchain
|
|
258
|
+
return false unless builder.rubygems_invoked? && builder.auto_install_rust_toolchain
|
|
259
|
+
|
|
260
|
+
find_executable("cargo").nil?
|
|
261
|
+
end
|
|
262
|
+
|
|
242
263
|
def if_eq_stmt(a, b)
|
|
243
264
|
if $nmake
|
|
244
265
|
"!IF #{a.inspect} == #{b.inspect}"
|
|
@@ -296,6 +317,12 @@ module RbSys
|
|
|
296
317
|
"export #{k} := #{v}"
|
|
297
318
|
end
|
|
298
319
|
end
|
|
320
|
+
|
|
321
|
+
def set_cargo_profile(builder)
|
|
322
|
+
return assign_stmt("RB_SYS_CARGO_PROFILE", "release") if builder.rubygems_invoked?
|
|
323
|
+
|
|
324
|
+
conditional_assign("RB_SYS_CARGO_PROFILE", builder.profile)
|
|
325
|
+
end
|
|
299
326
|
end
|
|
300
327
|
end
|
|
301
328
|
# rubocop:enable Style/GlobalVars
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
require_relative "toolchain_info/data"
|
|
4
4
|
|
|
5
5
|
module RbSys
|
|
6
|
+
# A class to get information about the Rust toolchains, and how they map to
|
|
7
|
+
# Ruby platforms.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# RbSys::ToolchainInfo.new("x86_64-unknown-linux-gnu").ruby_platform # => "x86_64-linux"
|
|
11
|
+
# RbSys::ToolchainInfo.new("x86_64-unknown-linux-gnu").supported? # => true
|
|
12
|
+
# RbSys::ToolchainInfo.new("x86_64-unknown-linux-gnu")
|
|
6
13
|
class ToolchainInfo
|
|
7
14
|
attr_reader :platform, :gem_platform, :rust_target, :rake_compiler_dock_cc, :supported, :rake_compiler_dock_image, :docker_platform
|
|
8
15
|
|
data/lib/rb_sys/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.9.43
|
|
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-11-
|
|
33
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
|
34
34
|
dependencies: []
|
|
35
35
|
description:
|
|
36
36
|
email:
|
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0'
|
|
74
74
|
requirements: []
|
|
75
|
-
rubygems_version: 3.3.
|
|
75
|
+
rubygems_version: 3.3.22
|
|
76
76
|
signing_key:
|
|
77
77
|
specification_version: 4
|
|
78
78
|
summary: Helpers for compiling Rust extensions for ruby
|
metadata.gz.sig
CHANGED
|
Binary file
|