thermite-ruby3-fork-dont-use 0.14.0
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 +7 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +29 -0
- data/.ruby-version +1 -0
- data/.yardopts +2 -0
- data/CONTRIBUTING.md +67 -0
- data/Gemfile +9 -0
- data/LICENSE +9 -0
- data/NEWS.md +180 -0
- data/README.md +144 -0
- data/Rakefile +32 -0
- data/lib/thermite/cargo.rb +125 -0
- data/lib/thermite/config.rb +293 -0
- data/lib/thermite/custom_binary.rb +66 -0
- data/lib/thermite/fiddle.rb +45 -0
- data/lib/thermite/github_release_binary.rb +125 -0
- data/lib/thermite/package.rb +96 -0
- data/lib/thermite/semver.rb +50 -0
- data/lib/thermite/tasks.rb +160 -0
- data/lib/thermite/util.rb +59 -0
- data/test/fixtures/config/Cargo.toml +5 -0
- data/test/fixtures/github/releases.atom +30 -0
- data/test/lib/thermite/cargo_test.rb +95 -0
- data/test/lib/thermite/config_test.rb +239 -0
- data/test/lib/thermite/custom_binary_test.rb +59 -0
- data/test/lib/thermite/github_release_binary_test.rb +160 -0
- data/test/lib/thermite/package_test.rb +119 -0
- data/test/lib/thermite/semver_test.rb +58 -0
- data/test/lib/thermite/util_test.rb +55 -0
- data/test/test_helper.rb +57 -0
- data/thermite.gemspec +27 -0
- metadata +184 -0
@@ -0,0 +1,293 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'fileutils'
|
21
|
+
require 'rbconfig'
|
22
|
+
require 'thermite/semver'
|
23
|
+
require 'tomlrb'
|
24
|
+
|
25
|
+
module Thermite
|
26
|
+
#
|
27
|
+
# Configuration helper
|
28
|
+
#
|
29
|
+
class Config
|
30
|
+
#
|
31
|
+
# Creates a new configuration object.
|
32
|
+
#
|
33
|
+
# `options` is the same as the {Thermite::Tasks#initialize} parameter.
|
34
|
+
#
|
35
|
+
def initialize(options = {})
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Location to emit debug output, if not `nil`. Defaults to `nil`.
|
41
|
+
#
|
42
|
+
def debug_filename
|
43
|
+
@debug_filename ||= ENV['THERMITE_DEBUG_FILENAME']
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# The file extension of the compiled shared Rust library.
|
48
|
+
#
|
49
|
+
def shared_ext
|
50
|
+
@shared_ext ||= if dlext == 'bundle'
|
51
|
+
'dylib'
|
52
|
+
elsif Gem.win_platform?
|
53
|
+
'dll'
|
54
|
+
else
|
55
|
+
dlext
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# The interpolation-formatted string used to construct the download URI for the pre-built
|
61
|
+
# native extension. Can be set via the `THERMITE_BINARY_URI_FORMAT` environment variable, or a
|
62
|
+
# `binary_uri_format` option.
|
63
|
+
#
|
64
|
+
def binary_uri_format
|
65
|
+
@binary_uri_format ||= ENV['THERMITE_BINARY_URI_FORMAT'] ||
|
66
|
+
@options[:binary_uri_format] ||
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# The major and minor version of the Ruby interpreter that's currently running.
|
72
|
+
#
|
73
|
+
def ruby_version
|
74
|
+
@ruby_version ||= begin
|
75
|
+
version_info = rbconfig_ruby_version.split('.')
|
76
|
+
"ruby#{version_info[0]}#{version_info[1]}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# :nocov:
|
81
|
+
|
82
|
+
#
|
83
|
+
# Alias for `RbConfig::CONFIG['target_cpu']`.
|
84
|
+
#
|
85
|
+
def target_arch
|
86
|
+
@target_arch ||= RbConfig::CONFIG['target_cpu']
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Alias for `RbConfig::CONFIG['target_os']`.
|
91
|
+
#
|
92
|
+
def target_os
|
93
|
+
@target_os ||= RbConfig::CONFIG['target_os']
|
94
|
+
end
|
95
|
+
# :nocov:
|
96
|
+
|
97
|
+
#
|
98
|
+
# The name of the library compiled by Rust.
|
99
|
+
#
|
100
|
+
# Due to the way that Cargo works, all hyphens in library names are replaced with underscores.
|
101
|
+
#
|
102
|
+
def library_name
|
103
|
+
@library_name ||= begin
|
104
|
+
base = toml[:lib] && toml[:lib][:name] ? toml[:lib] : toml[:package]
|
105
|
+
base[:name].tr('-', '_') if base[:name]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# The basename of the shared library built by Cargo.
|
111
|
+
#
|
112
|
+
def cargo_shared_library
|
113
|
+
@cargo_shared_library ||= begin
|
114
|
+
filename = "#{library_name}.#{shared_ext}"
|
115
|
+
filename = "lib#{filename}" unless Gem.win_platform?
|
116
|
+
filename
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# The basename of the Rust shared library, as installed in the {#ruby_extension_path}.
|
122
|
+
#
|
123
|
+
def shared_library
|
124
|
+
@shared_library ||= "#{library_name}.so"
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Return the basename of the tarball generated by the `thermite:tarball` Rake task, given a
|
129
|
+
# package `version`.
|
130
|
+
#
|
131
|
+
def tarball_filename(version)
|
132
|
+
static = static_extension? ? '-static' : ''
|
133
|
+
|
134
|
+
"#{library_name}-#{version}-#{ruby_version}-#{target_os}-#{target_arch}#{static}.tar.gz"
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# The top-level directory of the Ruby project. Defaults to the current working directory.
|
139
|
+
#
|
140
|
+
def ruby_toplevel_dir
|
141
|
+
@ruby_toplevel_dir ||= @options.fetch(:ruby_project_path, FileUtils.pwd)
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Generate a path relative to {#ruby_toplevel_dir}, given the `path_components` that are passed
|
146
|
+
# to `File.join`.
|
147
|
+
#
|
148
|
+
def ruby_path(*path_components)
|
149
|
+
File.join(ruby_toplevel_dir, *path_components)
|
150
|
+
end
|
151
|
+
|
152
|
+
# :nocov:
|
153
|
+
|
154
|
+
#
|
155
|
+
# Absolute path to the shared libruby.
|
156
|
+
#
|
157
|
+
def libruby_path
|
158
|
+
@libruby_path ||= File.join(RbConfig::CONFIG['libdir'], RbConfig::CONFIG['LIBRUBY_SO'])
|
159
|
+
end
|
160
|
+
|
161
|
+
# :nocov:
|
162
|
+
|
163
|
+
#
|
164
|
+
# The top-level directory of the Cargo project. Defaults to the current working directory.
|
165
|
+
#
|
166
|
+
def rust_toplevel_dir
|
167
|
+
@rust_toplevel_dir ||= @options.fetch(:cargo_project_path, FileUtils.pwd)
|
168
|
+
end
|
169
|
+
|
170
|
+
#
|
171
|
+
# Generate a path relative to {#rust_toplevel_dir}, given the `path_components` that are
|
172
|
+
# passed to `File.join`.
|
173
|
+
#
|
174
|
+
def rust_path(*path_components)
|
175
|
+
File.join(rust_toplevel_dir, *path_components)
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Generate a path relative to the `CARGO_TARGET_DIR` environment variable, or
|
180
|
+
# {#rust_toplevel_dir}/target if that is not set.
|
181
|
+
#
|
182
|
+
def cargo_target_path(target, *path_components)
|
183
|
+
target_base = ENV.fetch('CARGO_TARGET_DIR', File.join(rust_toplevel_dir, 'target'))
|
184
|
+
File.join(target_base, target, *path_components)
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# If run in a multi-crate environment, the Cargo workspace member that contains the
|
189
|
+
# Ruby extension.
|
190
|
+
#
|
191
|
+
def cargo_workspace_member
|
192
|
+
@cargo_workspace_member ||= @options[:cargo_workspace_member]
|
193
|
+
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# The absolute path to the `Cargo.toml` file. The path depends on the existence of the
|
197
|
+
# {#cargo_workspace_member} configuration option.
|
198
|
+
#
|
199
|
+
def cargo_toml_path
|
200
|
+
@cargo_toml_path ||= begin
|
201
|
+
components = ['Cargo.toml']
|
202
|
+
components.unshift(cargo_workspace_member) if cargo_workspace_member
|
203
|
+
|
204
|
+
rust_path(*components)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
#
|
209
|
+
# The relative directory where the Rust shared library resides, in the context of the Ruby
|
210
|
+
# project.
|
211
|
+
#
|
212
|
+
def ruby_extension_dir
|
213
|
+
@ruby_extension_dir ||= @options.fetch(:ruby_extension_dir, 'lib')
|
214
|
+
end
|
215
|
+
|
216
|
+
#
|
217
|
+
# Path to the Rust shared library in the context of the Ruby project.
|
218
|
+
#
|
219
|
+
def ruby_extension_path
|
220
|
+
ruby_path(ruby_extension_dir, shared_library)
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# The default git tag regular expression (semantic versioning format).
|
225
|
+
#
|
226
|
+
DEFAULT_TAG_REGEX = /^(#{Thermite::SemVer::VERSION})$/
|
227
|
+
|
228
|
+
#
|
229
|
+
# The format (as a regular expression) that git tags containing Rust binary
|
230
|
+
# tarballs are supposed to match. Defaults to `DEFAULT_TAG_REGEX`.
|
231
|
+
#
|
232
|
+
def git_tag_regex
|
233
|
+
@git_tag_regex ||= if @options[:git_tag_regex]
|
234
|
+
Regexp.new(@options[:git_tag_regex])
|
235
|
+
else
|
236
|
+
DEFAULT_TAG_REGEX
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
#
|
241
|
+
# Parsed TOML object (courtesy of `tomlrb`).
|
242
|
+
#
|
243
|
+
def toml
|
244
|
+
@toml ||= Tomlrb.load_file(cargo_toml_path, symbolize_keys: true)
|
245
|
+
end
|
246
|
+
|
247
|
+
#
|
248
|
+
# Alias to the crate version specified in the TOML file.
|
249
|
+
#
|
250
|
+
def crate_version
|
251
|
+
toml[:package][:version]
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# The Thermite-specific config from the TOML file.
|
256
|
+
#
|
257
|
+
def toml_config
|
258
|
+
# Not using .dig to be Ruby < 2.3 compatible
|
259
|
+
@toml_config ||= if toml && toml[:package] && toml[:package][:metadata] &&
|
260
|
+
toml[:package][:metadata][:thermite]
|
261
|
+
toml[:package][:metadata][:thermite]
|
262
|
+
else
|
263
|
+
{}
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# :nocov:
|
268
|
+
|
269
|
+
#
|
270
|
+
# Linker flags for libruby.
|
271
|
+
#
|
272
|
+
def dynamic_linker_flags
|
273
|
+
@dynamic_linker_flags ||= RbConfig::CONFIG['DLDFLAGS'].strip
|
274
|
+
end
|
275
|
+
|
276
|
+
#
|
277
|
+
# Whether to use a statically linked extension.
|
278
|
+
#
|
279
|
+
def static_extension?
|
280
|
+
ENV.key?('RUBY_STATIC') || RbConfig::CONFIG['ENABLE_SHARED'] == 'no'
|
281
|
+
end
|
282
|
+
|
283
|
+
private
|
284
|
+
|
285
|
+
def dlext
|
286
|
+
RbConfig::CONFIG['DLEXT']
|
287
|
+
end
|
288
|
+
|
289
|
+
def rbconfig_ruby_version
|
290
|
+
RbConfig::CONFIG['ruby_version']
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'net/http'
|
21
|
+
require 'uri'
|
22
|
+
|
23
|
+
module Thermite
|
24
|
+
#
|
25
|
+
# Custom binary URI helpers.
|
26
|
+
#
|
27
|
+
module CustomBinary
|
28
|
+
#
|
29
|
+
# Downloads a Rust binary using a custom URI format, given the target OS and architecture.
|
30
|
+
#
|
31
|
+
# Requires the `binary_uri_format` option to be set. The version of the binary is determined by
|
32
|
+
# the crate version given in `Cargo.toml`.
|
33
|
+
#
|
34
|
+
# Returns whether a binary was found and unpacked.
|
35
|
+
#
|
36
|
+
def download_binary_from_custom_uri
|
37
|
+
return false unless config.binary_uri_format
|
38
|
+
|
39
|
+
version = config.crate_version
|
40
|
+
uri ||= format(
|
41
|
+
config.binary_uri_format,
|
42
|
+
filename: config.tarball_filename(version),
|
43
|
+
version: version
|
44
|
+
)
|
45
|
+
|
46
|
+
return false unless (tgz = download_versioned_binary(uri, version))
|
47
|
+
|
48
|
+
debug "Unpacking binary from Cargo version: #{File.basename(uri)}"
|
49
|
+
unpack_tarball(tgz)
|
50
|
+
prepare_downloaded_library
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def download_versioned_binary(uri, version)
|
57
|
+
unless ENV.key?('THERMITE_TEST')
|
58
|
+
# :nocov:
|
59
|
+
puts "Downloading compiled version (#{version})"
|
60
|
+
# :nocov:
|
61
|
+
end
|
62
|
+
|
63
|
+
http_get(uri)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'fiddle'
|
21
|
+
require 'thermite/config'
|
22
|
+
|
23
|
+
module Thermite
|
24
|
+
#
|
25
|
+
# Fiddle helper functions.
|
26
|
+
#
|
27
|
+
module Fiddle
|
28
|
+
#
|
29
|
+
# Loads a native extension using {Thermite::Config} and the builtin `Fiddle` extension.
|
30
|
+
#
|
31
|
+
# @param init_function_name [String] the name of the native function that initializes
|
32
|
+
# the extension
|
33
|
+
# @param config_options [Hash] {Thermite::Tasks#options options} passed to {Thermite::Config}.
|
34
|
+
# Options likely needed to be set:
|
35
|
+
# `cargo_project_path`, `ruby_project_path`
|
36
|
+
#
|
37
|
+
def self.load_module(init_function_name, config_options)
|
38
|
+
config = Thermite::Config.new(config_options)
|
39
|
+
library = ::Fiddle.dlopen(config.ruby_extension_path)
|
40
|
+
func = ::Fiddle::Function.new(library[init_function_name],
|
41
|
+
[], ::Fiddle::TYPE_VOIDP)
|
42
|
+
func.call
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016, 2017 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'net/http'
|
21
|
+
require 'rexml/document'
|
22
|
+
require 'uri'
|
23
|
+
|
24
|
+
module Thermite
|
25
|
+
#
|
26
|
+
# GitHub releases binary helpers.
|
27
|
+
#
|
28
|
+
module GithubReleaseBinary
|
29
|
+
#
|
30
|
+
# Downloads a Rust binary from GitHub releases, given the target OS and architecture.
|
31
|
+
#
|
32
|
+
# Requires the `github_releases` option to be `true`. It uses the `repository` value in the
|
33
|
+
# project's `Cargo.toml` (in the `package` section) to determine where the releases
|
34
|
+
# are located.
|
35
|
+
#
|
36
|
+
# If the `github_release_type` is `'latest'`, it will attempt to use the appropriate binary for
|
37
|
+
# the latest version in GitHub releases. Otherwise, it will download the appropriate binary for
|
38
|
+
# the crate version given in `Cargo.toml`.
|
39
|
+
#
|
40
|
+
# Returns whether a binary was found and unpacked.
|
41
|
+
#
|
42
|
+
def download_binary_from_github_release
|
43
|
+
return false unless options[:github_releases]
|
44
|
+
|
45
|
+
case options[:github_release_type]
|
46
|
+
when 'latest'
|
47
|
+
download_latest_binary_from_github_release
|
48
|
+
else # 'cargo'
|
49
|
+
download_cargo_version_from_github_release
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def download_cargo_version_from_github_release
|
56
|
+
version = config.crate_version
|
57
|
+
# TODO: Change this to a named token and increment the 0.minor version
|
58
|
+
tag = options.fetch(:git_tag_format, 'v%s') % version
|
59
|
+
uri = github_download_uri(tag, version)
|
60
|
+
return false unless (tgz = download_versioned_github_release_binary(uri, version))
|
61
|
+
|
62
|
+
debug "Unpacking GitHub release from Cargo version: #{File.basename(uri)}"
|
63
|
+
unpack_tarball(tgz)
|
64
|
+
prepare_downloaded_library
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Downloads and unpacks the latest binary from GitHub releases, given the target OS
|
70
|
+
# and architecture.
|
71
|
+
#
|
72
|
+
def download_latest_binary_from_github_release
|
73
|
+
installed_binary = false
|
74
|
+
each_github_release(github_uri) do |version, download_uri|
|
75
|
+
tgz = download_versioned_github_release_binary(download_uri, version)
|
76
|
+
next unless tgz
|
77
|
+
|
78
|
+
debug "Unpacking GitHub release: #{File.basename(download_uri)}"
|
79
|
+
unpack_tarball(tgz)
|
80
|
+
prepare_downloaded_library
|
81
|
+
installed_binary = true
|
82
|
+
break
|
83
|
+
end
|
84
|
+
|
85
|
+
installed_binary
|
86
|
+
end
|
87
|
+
|
88
|
+
def github_uri
|
89
|
+
@github_uri ||= begin
|
90
|
+
unless (repository = config.toml[:package][:repository])
|
91
|
+
raise KeyError, 'No repository found in Config.toml'
|
92
|
+
end
|
93
|
+
|
94
|
+
repository
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def github_download_uri(tag, version)
|
99
|
+
"#{github_uri}/releases/download/#{tag}/#{config.tarball_filename(version)}"
|
100
|
+
end
|
101
|
+
|
102
|
+
def each_github_release(github_uri)
|
103
|
+
releases_uri = "#{github_uri}/releases.atom"
|
104
|
+
feed = REXML::Document.new(http_get(releases_uri))
|
105
|
+
REXML::XPath.each(feed, '//entry/title/text()') do |tag|
|
106
|
+
match = config.git_tag_regex.match(tag.to_s)
|
107
|
+
next unless match
|
108
|
+
|
109
|
+
version = match[1]
|
110
|
+
|
111
|
+
yield(version, github_download_uri(tag, version))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def download_versioned_github_release_binary(uri, version)
|
116
|
+
unless ENV.key?('THERMITE_TEST')
|
117
|
+
# :nocov:
|
118
|
+
puts "Downloading compiled version (#{version}) from GitHub"
|
119
|
+
# :nocov:
|
120
|
+
end
|
121
|
+
|
122
|
+
http_get(uri)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'archive/tar/minitar'
|
21
|
+
require 'rubygems/package'
|
22
|
+
require 'zlib'
|
23
|
+
|
24
|
+
module Thermite
|
25
|
+
#
|
26
|
+
# Helpers to package the Rust library into a gzipped tarball.
|
27
|
+
#
|
28
|
+
module Package
|
29
|
+
#
|
30
|
+
# Builds a tarball of the Rust-compiled shared library.
|
31
|
+
#
|
32
|
+
def build_package
|
33
|
+
filename = config.tarball_filename(config.toml[:package][:version])
|
34
|
+
relative_library_path = config.ruby_extension_path.sub("#{config.ruby_toplevel_dir}/", '')
|
35
|
+
prepare_built_library
|
36
|
+
Zlib::GzipWriter.open(filename) do |tgz|
|
37
|
+
Dir.chdir(config.ruby_toplevel_dir) do
|
38
|
+
Archive::Tar::Minitar.pack(relative_library_path, tgz)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Unpack a gzipped tarball stream (specified by `tgz`) into the current
|
45
|
+
# working directory.
|
46
|
+
#
|
47
|
+
def unpack_tarball(tgz)
|
48
|
+
Dir.chdir(config.ruby_toplevel_dir) do
|
49
|
+
each_compressed_file(tgz) do |path, entry|
|
50
|
+
debug "Unpacking file: #{path}"
|
51
|
+
File.open(path, 'wb') do |f|
|
52
|
+
f.write(entry.read)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# :nocov:
|
59
|
+
|
60
|
+
def prepare_downloaded_library
|
61
|
+
return unless config.target_os.start_with?('darwin')
|
62
|
+
|
63
|
+
libruby_path = Shellwords.escape(config.libruby_path)
|
64
|
+
library_path = Shellwords.escape(config.ruby_extension_path)
|
65
|
+
`install_name_tool -id #{library_path} #{library_path}`
|
66
|
+
`install_name_tool -change @libruby_path@ #{libruby_path} #{library_path}`
|
67
|
+
end
|
68
|
+
|
69
|
+
# :nocov:
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def each_compressed_file(tgz)
|
74
|
+
Zlib::GzipReader.wrap(tgz) do |gz|
|
75
|
+
Gem::Package::TarReader.new(gz) do |tar|
|
76
|
+
tar.each do |entry|
|
77
|
+
path = entry.header.name
|
78
|
+
next if path.end_with?('/')
|
79
|
+
|
80
|
+
yield path, entry
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# :nocov:
|
87
|
+
|
88
|
+
def prepare_built_library
|
89
|
+
return unless config.target_os.start_with?('darwin')
|
90
|
+
|
91
|
+
libruby_path = Shellwords.escape(config.libruby_path)
|
92
|
+
library_path = Shellwords.escape(config.ruby_extension_path)
|
93
|
+
`install_name_tool -change #{libruby_path} @libruby_path@ #{library_path}`
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2018 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
module Thermite
|
21
|
+
#
|
22
|
+
# [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (2.0.0) regular expression.
|
23
|
+
#
|
24
|
+
module SemVer
|
25
|
+
#
|
26
|
+
# Valid version number part (major/minor/patch).
|
27
|
+
#
|
28
|
+
NUMERIC = '(?:0|[1-9]\d*)'
|
29
|
+
|
30
|
+
#
|
31
|
+
# Valid identifier for pre-release versions or build metadata.
|
32
|
+
#
|
33
|
+
IDENTIFIER = '[-0-9A-Za-z][-0-9A-Za-z.]*'
|
34
|
+
|
35
|
+
#
|
36
|
+
# Version pre-release section, including the hyphen.
|
37
|
+
#
|
38
|
+
PRERELEASE = "-#{IDENTIFIER}"
|
39
|
+
|
40
|
+
#
|
41
|
+
# Version build metadata section, including the plus sign.
|
42
|
+
#
|
43
|
+
BUILD_METADATA = "\\+#{IDENTIFIER}"
|
44
|
+
|
45
|
+
#
|
46
|
+
# Semantic version-compliant regular expression.
|
47
|
+
#
|
48
|
+
VERSION = "v?#{NUMERIC}\.#{NUMERIC}\.#{NUMERIC}(?:#{PRERELEASE})?(?:#{BUILD_METADATA})?"
|
49
|
+
end
|
50
|
+
end
|