rb_sys 0.9.19 → 0.9.22

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: 48b3782a3c2bd7804f9f0a1c42f4bbb1181173525c63011e77fa9a122b93bfe3
4
- data.tar.gz: 04acd400f1997b1d1a981a148a7f9e7027d3b7af4c23fb924b97a5b3831f4115
3
+ metadata.gz: 63ba0fbfb3a21414b8e379d92abf8cf37ca5b310e57360d57d42d10a1aa42b22
4
+ data.tar.gz: 54ab9824e5902fbe11416cd8be8529fb90f9129412bbe916b5195270ca54fb9d
5
5
  SHA512:
6
- metadata.gz: 706f56f3d6ee988b4216481d0bdbe90ba5a57e25304a07b7e790f9bc3c50adf91a76b2b12097747c4be4148b5e2a8bb1374f8c5d9dc9dd6e4318ab8bbee2ae25
7
- data.tar.gz: 247aa3d5cf43aa9dd83775617ca2a2c60a68f15083a3502e05c9ad76aa8beaa0f2d725d846983e84f1b4af1b0503714d26fde921b14c3ea2e972f8fe19c2f1d3
6
+ metadata.gz: 523f540fdbfabed2e6988871ec2bd4f2d97a20c5ab0c39a8b10181dacff50a6c32cfcfaafe1335d6f4d5454458201feb20df7fb2fc14f6a28a8b9df7c077b1c8
7
+ data.tar.gz: a49dc910f814519fc42d37c08ba3ce52729b90ca47bc08a1f48f9edba26e54c7bcfe234ce952b80c0a2a8a88f82565bfc7784f9ee067e92b3bbade2cc7bda4dc
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  module RbSys
2
2
  class CargoBuilder < Gem::Ext::Builder
3
- attr_accessor :spec, :runner, :profile, :env, :features, :target, :extra_rustc_args, :dry_run, :ext_dir
3
+ attr_accessor :spec, :runner, :profile, :env, :features, :target, :extra_rustc_args, :dry_run, :ext_dir, :extra_rustflags
4
4
 
5
5
  def initialize(spec)
6
6
  require "rubygems/command"
@@ -15,6 +15,7 @@ module RbSys
15
15
  @extra_rustc_args = []
16
16
  @dry_run = true
17
17
  @ext_dir = nil
18
+ @extra_rustflags = []
18
19
  end
19
20
 
20
21
  def build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd)
@@ -0,0 +1,33 @@
1
+ # Root module
2
+ module RbSys
3
+ # Helper class for creating Rust Makefiles
4
+ module Mkmf
5
+ # Config that delegates to CargoBuilder if needded
6
+ class Config
7
+ attr_accessor :force_install_rust_toolchain, :clean_after_install
8
+
9
+ def initialize(builder)
10
+ @builder = builder
11
+ @force_install_rust_toolchain = false
12
+ @clean_after_install = rubygems_invoked?
13
+ end
14
+
15
+ def method_missing(name, *args, &blk)
16
+ @builder.send(name, *args, &blk)
17
+ end
18
+
19
+ def respond_to_missing?(name, include_private = false)
20
+ @builder.respond_to?(name) || super
21
+ end
22
+
23
+ private
24
+
25
+ # Seems to be the only way to reliably know if we were invoked by Rubygems.
26
+ # We want to know this so we can cleanup the target directory after an
27
+ # install, to remove bloat.
28
+ def rubygems_invoked?
29
+ ENV.key?("SOURCE_DATE_EPOCH")
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/rb_sys/mkmf.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "rubygems/ext"
4
4
  require "shellwords"
5
5
  require_relative "cargo_builder"
6
+ require_relative "mkmf/config"
6
7
 
7
8
  # Root module
8
9
  module RbSys
@@ -37,7 +38,8 @@ module RbSys
37
38
  end
38
39
 
39
40
  spec = Struct.new(:name, :metadata).new(target, {})
40
- builder = CargoBuilder.new(spec)
41
+ cargo_builder = CargoBuilder.new(spec)
42
+ builder = Config.new(cargo_builder)
41
43
 
42
44
  yield builder if blk
43
45
 
@@ -48,6 +50,7 @@ module RbSys
48
50
 
49
51
  # rubocop:disable Style/GlobalVars
50
52
  make_install = +<<~MAKE
53
+ RB_SYS_BUILD_DIR ?= #{File.join(Dir.pwd, ".rb-sys")}
51
54
  CARGO ?= cargo
52
55
  CARGO_BUILD_TARGET ?= #{builder.target}
53
56
  SOEXT ?= #{builder.so_ext}
@@ -59,6 +62,7 @@ module RbSys
59
62
 
60
63
  RB_SYS_CARGO_PROFILE ?= #{builder.profile}
61
64
  RB_SYS_CARGO_FEATURES ?= #{builder.features.join(",")}
65
+ RB_SYS_EXTRA_RUSTFLAGS ?= #{builder.extra_rustflags.join(" ")}
62
66
 
63
67
  # Set dirname for the profile, since the profiles do not directly map to target dir (i.e. dev -> debug)
64
68
  ifeq ($(RB_SYS_CARGO_PROFILE),dev)
@@ -84,14 +88,14 @@ module RbSys
84
88
  target_prefix = #{target_prefix}
85
89
  TARGET_NAME = #{target[/\A\w+/]}
86
90
  TARGET_ENTRY = #{RbConfig::CONFIG["EXPORT_PREFIX"]}Init_$(TARGET_NAME)
87
- CLEANLIBS = $(RUSTLIB) $(DLLIB) $(DEFFILE)
91
+ CLEANLIBS = $(RUSTLIB)
88
92
  RUBYARCHDIR = $(sitearchdir)$(target_prefix)
89
93
  TARGET = #{target}
90
94
  DLLIB = $(TARGET).#{RbConfig::CONFIG["DLEXT"]}
91
95
  TARGET_DIR = #{Dir.pwd}/$(RB_SYS_CARGO_BUILD_TARGET_DIR)/$(RB_SYS_CARGO_PROFILE_DIR)
92
96
  RUSTLIB = $(TARGET_DIR)/$(SOEXT_PREFIX)$(TARGET_NAME).$(SOEXT)
93
97
 
94
- DISTCLEANDIRS = $(TARGET_DIR)
98
+ CLEANOBJS = $(TARGET_DIR)/.fingerprint $(TARGET_DIR)/incremental $(TARGET_DIR)/examples $(TARGET_DIR)/deps $(TARGET_DIR)/build $(TARGET_DIR)/.cargo-lock $(TARGET_DIR)/*.d $(RB_SYS_BUILD_DIR)
95
99
  DEFFILE = $(TARGET_DIR)/$(TARGET)-$(arch).def
96
100
  #{base_makefile(srcdir)}
97
101
 
@@ -100,6 +104,7 @@ module RbSys
100
104
  endif
101
105
 
102
106
  #{env_vars(builder)}
107
+ $(DLLIB): export RUSTFLAGS := $(RUSTFLAGS) $(RB_SYS_EXTRA_RUSTFLAGS)
103
108
 
104
109
  FORCE: ;
105
110
 
@@ -111,16 +116,20 @@ module RbSys
111
116
  \t$(ECHO) generating $(@)
112
117
  \t$(Q) ($(COPY) $(srcdir)/$(TARGET).def $@ 2> /dev/null) || (echo EXPORTS && echo $(TARGET_ENTRY)) > $@
113
118
 
119
+ #{optional_rust_toolchain(builder)}
120
+
114
121
  $(DLLIB): $(DEFFILE) FORCE
115
122
  \t$(ECHO) generating $(@) \\("$(RB_SYS_CARGO_PROFILE)"\\)
116
123
  \t$(Q) #{full_cargo_command}
117
124
  \t$(Q) $(COPY) "$(RUSTLIB)" $@
118
125
 
119
- install: $(DLLIB) Makefile
126
+ install-so: $(DLLIB) Makefile
120
127
  \t$(ECHO) installing $(DLLIB)
121
128
  \t$(Q) $(MAKEDIRS) $(RUBYARCHDIR)
122
129
  \t$(Q) $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
123
130
 
131
+ install: #{builder.clean_after_install ? "install-so realclean" : "install-so"}
132
+
124
133
  all: #{$extout ? "install" : "$(DLLIB)"}
125
134
  MAKE
126
135
 
@@ -134,8 +143,7 @@ module RbSys
134
143
 
135
144
  def base_makefile(cargo_dir)
136
145
  base_makefile = dummy_makefile(__dir__).join("\n")
137
- base_makefile.gsub!("all install static install-so install-rb", "all static install-so install-rb")
138
- base_makefile.gsub!("clean-so::", "clean-so:\n\t-$(Q)$(RM) $(DLLIB)\n")
146
+ base_makefile.gsub!("all install static install-so install-rb", "all static install-rb")
139
147
  base_makefile.gsub!(/^srcdir = .*$/, "srcdir = #{cargo_dir}")
140
148
  base_makefile
141
149
  end
@@ -152,6 +160,7 @@ module RbSys
152
160
  def env_vars(builder)
153
161
  lines = builder.build_env.map { |k, v| env_line(k, v) }
154
162
  lines << env_line("CC", env_or_makefile_config("CC"))
163
+ lines << env_line("CXX", env_or_makefile_config("CXX"))
155
164
  lines << env_line("AR", env_or_makefile_config("AR")) unless env_or_makefile_config("AR") == "libtool -static"
156
165
  lines.compact.join("\n")
157
166
  end
@@ -173,6 +182,45 @@ module RbSys
173
182
  cargo_command.gsub!(%r{/#{target_dir}/[^/]+}, "/$(RB_SYS_CARGO_BUILD_TARGET_DIR)/$(RB_SYS_CARGO_PROFILE_DIR)")
174
183
  cargo_command
175
184
  end
185
+
186
+ def optional_rust_toolchain(builder)
187
+ <<~MAKE
188
+ RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN ?= #{builder.force_install_rust_toolchain}
189
+
190
+ # Only run if the we are told to explicitly install the Rust toolchain
191
+ ifneq ($(RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN),false)
192
+ RB_SYS_RUSTUP_PROFILE ?= minimal
193
+
194
+ # If the user passed true, we assume stable Rust. Otherwise, use what
195
+ # was specified (i.e. RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN=beta)
196
+ ifeq ($(RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN),true)
197
+ RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN = stable
198
+ endif
199
+
200
+ # If a $RUST_TARGET is specified (i.e. for rake-compiler-dock), append
201
+ # that to the profile.
202
+ ifeq ($(RUST_TARGET),)
203
+ RB_SYS_DEFAULT_TOOLCHAIN = $(RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN)
204
+ else
205
+ RB_SYS_DEFAULT_TOOLCHAIN = $(RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN)-$(RUST_TARGET)
206
+ endif
207
+
208
+ export CARGO_HOME ?= $(RB_SYS_BUILD_DIR)/$(RB_SYS_DEFAULT_TOOLCHAIN)/cargo
209
+ export RUSTUP_HOME ?= $(RB_SYS_BUILD_DIR)/$(RB_SYS_DEFAULT_TOOLCHAIN)/rustup
210
+ export PATH := $(CARGO_HOME)/bin:$(RUSTUP_HOME)/bin:$(PATH)
211
+ export RUSTUP_TOOLCHAIN := $(RB_SYS_DEFAULT_TOOLCHAIN)
212
+ export CARGO := $(CARGO_HOME)/bin/cargo
213
+
214
+ $(CARGO):
215
+ \t$(Q) $(MAKEDIRS) $(CARGO_HOME) $(RUSTUP_HOME)
216
+ \tcurl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
217
+ \trustup toolchain install $(RB_SYS_DEFAULT_TOOLCHAIN) --profile $(RB_SYS_RUSTUP_PROFILE)
218
+ \trustup default $(RB_SYS_DEFAULT_TOOLCHAIN)
219
+
220
+ $(DLLIB): $(CARGO)
221
+ endif
222
+ MAKE
223
+ end
176
224
  end
177
225
  end
178
226
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbSys
4
- VERSION = "0.9.19"
4
+ VERSION = "0.9.22"
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.19
4
+ version: 0.9.22
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-07-05 00:00:00.000000000 Z
33
+ date: 2022-07-19 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email:
@@ -46,6 +46,7 @@ files:
46
46
  - lib/rb_sys/cargo_builder.rb
47
47
  - lib/rb_sys/cargo_builder/link_flag_converter.rb
48
48
  - lib/rb_sys/mkmf.rb
49
+ - lib/rb_sys/mkmf/config.rb
49
50
  - lib/rb_sys/version.rb
50
51
  - sig/rb_sys.rbs
51
52
  homepage: https://github.com/oxidize-rb/rb-sys
metadata.gz.sig CHANGED
Binary file