prebake 0.3.5 → 0.3.7
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
- data/lib/prebake/async_publisher.rb +1 -1
- data/lib/prebake/backends/base.rb +5 -0
- data/lib/prebake/backends/http.rb +25 -8
- data/lib/prebake/elf_inspector.rb +4 -4
- data/lib/prebake/ext_builder_patch.rb +14 -18
- data/lib/prebake/{extension_validator.rb → extension_layout.rb} +5 -5
- data/lib/prebake/extractor.rb +1 -1
- data/lib/prebake/glibc.rb +2 -2
- data/lib/prebake/hooks.rb +3 -3
- data/lib/prebake/platform.rb +3 -3
- data/lib/prebake/platform_gem_builder.rb +7 -1
- data/lib/prebake/static_ruby.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8773dbffbc19494a8ca48af28bf2d68bef4f4ebecae1fd37ff7ec171880b2c4d
|
|
4
|
+
data.tar.gz: a3e243baec1fcebd091c3b7b466f65cb6f74b0cfc6ca5a9f69f81e46cbd2eea8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: efbb626624281ca0488cd549ffa3e8467c7601214153733d7e035c949c9b0c7c275b3668ea616c386b7d2726090e8309613ab7727295940c02fd6f23c1119ac9
|
|
7
|
+
data.tar.gz: 0a0ce57c3e7bbd2f03c8d0c1f9d7883d2d8b46389a0dbaccfed45ae545be05b88fb2e7f40d45fc386ede90b778e3684564b5fafdf02f8765d7a3eb68311e6eec
|
|
@@ -13,6 +13,11 @@ module Prebake
|
|
|
13
13
|
nil
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def fetch_with_checksum(cache_key)
|
|
17
|
+
path = fetch(cache_key)
|
|
18
|
+
[path, path && fetch_checksum(cache_key)]
|
|
19
|
+
end
|
|
20
|
+
|
|
16
21
|
def push(gem_path, cache_key, checksum)
|
|
17
22
|
raise NotImplementedError, "#{self.class}#push not implemented"
|
|
18
23
|
end
|
|
@@ -11,6 +11,9 @@ module Prebake
|
|
|
11
11
|
class Http < Base
|
|
12
12
|
include HttpClient
|
|
13
13
|
|
|
14
|
+
CHECKSUM_HEADER = "X-Prebake-Sha256"
|
|
15
|
+
SHA256_HEX = /\A[0-9a-f]{64}\z/
|
|
16
|
+
|
|
14
17
|
def initialize(url:, token: nil)
|
|
15
18
|
@url = url.chomp("/")
|
|
16
19
|
@token = token
|
|
@@ -19,15 +22,16 @@ module Prebake
|
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
def fetch(cache_key)
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
download(cache_key)&.first
|
|
26
|
+
end
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
# The hosted cache sends the checksum with the gem, so a hit costs one
|
|
29
|
+
# request. For servers that don't, the .sha256 file is fetched instead.
|
|
30
|
+
def fetch_with_checksum(cache_key)
|
|
31
|
+
path, checksum = download(cache_key)
|
|
32
|
+
return [nil, nil] unless path
|
|
33
|
+
|
|
34
|
+
[path, checksum || fetch_checksum(cache_key)]
|
|
31
35
|
end
|
|
32
36
|
|
|
33
37
|
def fetch_checksum(cache_key)
|
|
@@ -82,6 +86,19 @@ module Prebake
|
|
|
82
86
|
|
|
83
87
|
private
|
|
84
88
|
|
|
89
|
+
def download(cache_key)
|
|
90
|
+
response = http_request(:get, gem_uri(cache_key))
|
|
91
|
+
return unless response.is_a?(Net::HTTPSuccess)
|
|
92
|
+
|
|
93
|
+
path = File.join(Dir.tmpdir, "prebake-#{SecureRandom.hex(16)}.gem")
|
|
94
|
+
File.binwrite(path, response.body)
|
|
95
|
+
checksum = response[CHECKSUM_HEADER]
|
|
96
|
+
[path, (checksum if checksum&.match?(SHA256_HEX))]
|
|
97
|
+
rescue StandardError => e
|
|
98
|
+
Logger.debug "Fetch failed for #{cache_key}: #{e.message}"
|
|
99
|
+
nil
|
|
100
|
+
end
|
|
101
|
+
|
|
85
102
|
def gem_uri(cache_key)
|
|
86
103
|
URI("#{@url}/gems/#{cache_key}")
|
|
87
104
|
end
|
|
@@ -51,19 +51,19 @@ module Prebake
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def self.needed_libraries(path)
|
|
54
|
-
|
|
54
|
+
output, status = Open3.capture2e("objdump", "-p", path)
|
|
55
55
|
return [] unless status.success?
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
output.scan(/NEEDED\s+(\S+)/).flatten
|
|
58
58
|
rescue Errno::ENOENT
|
|
59
59
|
[]
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def self.run_objdump(path)
|
|
63
|
-
|
|
63
|
+
output, status = Open3.capture2e("objdump", "-T", path)
|
|
64
64
|
return nil unless status.success?
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
output
|
|
67
67
|
rescue Errno::ENOENT
|
|
68
68
|
nil
|
|
69
69
|
end
|
|
@@ -27,22 +27,15 @@ module Prebake
|
|
|
27
27
|
|
|
28
28
|
if Prebake.optional_native_extension?(@spec.name) && !Prebake.libruby_available?
|
|
29
29
|
Logger.warn "#{@spec.name}: native extension skipped (optional gem, libruby.so absent on static Ruby build)"
|
|
30
|
-
|
|
30
|
+
mark_build_complete
|
|
31
31
|
return
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
platform = Platform.generalized
|
|
35
35
|
cache_key = CacheKey.for(@spec.name, @spec.version.to_s, platform)
|
|
36
36
|
|
|
37
|
-
expected_checksum = Prebake.backend.fetch_checksum(cache_key)
|
|
38
|
-
|
|
39
|
-
if expected_checksum.nil? && Prebake.backend.checksums_supported?
|
|
40
|
-
trigger_rebuild(cache_key)
|
|
41
|
-
return super
|
|
42
|
-
end
|
|
43
|
-
|
|
44
37
|
begin
|
|
45
|
-
cached_gem = Prebake.backend.
|
|
38
|
+
cached_gem, expected_checksum = Prebake.backend.fetch_with_checksum(cache_key)
|
|
46
39
|
rescue StandardError => e
|
|
47
40
|
Logger.debug "Cache fetch error for #{@spec.name}: #{e.message}"
|
|
48
41
|
return super
|
|
@@ -53,7 +46,12 @@ module Prebake
|
|
|
53
46
|
return super
|
|
54
47
|
end
|
|
55
48
|
|
|
56
|
-
if
|
|
49
|
+
if expected_checksum.nil? && Prebake.backend.checksums_supported?
|
|
50
|
+
trigger_rebuild(cache_key)
|
|
51
|
+
return super
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if checksum_matches?(cache_key, expected_checksum, cached_gem)
|
|
57
55
|
unless PortabilityGuard.portable_for_host?(cached_gem, spec_name: @spec.name)
|
|
58
56
|
# Binary is valid for other hosts; don't delete from backend.
|
|
59
57
|
return super
|
|
@@ -83,13 +81,15 @@ module Prebake
|
|
|
83
81
|
|
|
84
82
|
def trigger_rebuild(cache_key)
|
|
85
83
|
Logger.warn "No checksum available for #{cache_key}, removing cached gem"
|
|
86
|
-
|
|
84
|
+
# Without the delete the gem is still there, so the GET below would only download it again.
|
|
85
|
+
return unless Prebake.backend.delete(cache_key)
|
|
86
|
+
|
|
87
87
|
# GET triggers the worker to dispatch a rebuild via GH Actions on cache miss
|
|
88
|
-
|
|
89
|
-
FileUtils.rm_f(
|
|
88
|
+
leftover = Prebake.backend.fetch(cache_key)
|
|
89
|
+
FileUtils.rm_f(leftover) if leftover
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def
|
|
92
|
+
def checksum_matches?(cache_key, expected, gem_path)
|
|
93
93
|
return true if expected.nil?
|
|
94
94
|
|
|
95
95
|
actual = Digest::SHA256.file(gem_path).hexdigest
|
|
@@ -101,10 +101,6 @@ module Prebake
|
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
def install_without_native_extension
|
|
105
|
-
mark_build_complete
|
|
106
|
-
end
|
|
107
|
-
|
|
108
104
|
def install_from_cache(gem_path)
|
|
109
105
|
count = Extractor.install(gem_path, @spec)
|
|
110
106
|
|
|
@@ -4,14 +4,14 @@ require "fileutils"
|
|
|
4
4
|
require_relative "logger"
|
|
5
5
|
|
|
6
6
|
module Prebake
|
|
7
|
-
module
|
|
7
|
+
module ExtensionLayout
|
|
8
8
|
BINARY_GLOB = "*.{so,bundle,dll}"
|
|
9
9
|
|
|
10
|
-
def self.
|
|
11
|
-
Bundler.definition.specs.each { |spec|
|
|
10
|
+
def self.repair_all
|
|
11
|
+
Bundler.definition.specs.each { |spec| repair(spec) }
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def self.
|
|
14
|
+
def self.repair(spec)
|
|
15
15
|
ext_dir = spec.extension_dir
|
|
16
16
|
return unless File.exist?(File.join(ext_dir, ".prebake"))
|
|
17
17
|
|
|
@@ -30,7 +30,7 @@ module Prebake
|
|
|
30
30
|
next if File.exist?(dest)
|
|
31
31
|
|
|
32
32
|
FileUtils.cp(binary, dest)
|
|
33
|
-
Logger.info "
|
|
33
|
+
Logger.info "Restored #{File.basename(binary)} to #{ext_dir}"
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
data/lib/prebake/extractor.rb
CHANGED
|
@@ -27,7 +27,7 @@ module Prebake
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
# Mark this extension_dir as prebake-managed for post-install
|
|
30
|
+
# Mark this extension_dir as prebake-managed for post-install layout repair
|
|
31
31
|
FileUtils.touch(File.join(spec.extension_dir, ".prebake")) if extracted_count.positive?
|
|
32
32
|
|
|
33
33
|
Logger.info "Installed precompiled #{File.basename(gem_path)} " \
|
data/lib/prebake/glibc.rb
CHANGED
|
@@ -37,10 +37,10 @@ module Prebake
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def self.run_ldd
|
|
40
|
-
|
|
40
|
+
output, status = Open3.capture2e("ldd", "--version")
|
|
41
41
|
return nil unless status.success?
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
output
|
|
44
44
|
rescue Errno::ENOENT
|
|
45
45
|
nil
|
|
46
46
|
end
|
data/lib/prebake/hooks.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "async_publisher"
|
|
4
|
-
require_relative "
|
|
4
|
+
require_relative "extension_layout"
|
|
5
5
|
require_relative "logger"
|
|
6
6
|
|
|
7
7
|
module Prebake
|
|
@@ -22,11 +22,11 @@ module Prebake
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
Bundler::Plugin::API.hook("after-install-all") do |_deps|
|
|
25
|
-
|
|
25
|
+
ExtensionLayout.repair_all
|
|
26
26
|
|
|
27
27
|
next unless Prebake.push_enabled?
|
|
28
28
|
|
|
29
|
-
AsyncPublisher.
|
|
29
|
+
AsyncPublisher.publish_pending
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
Logger.debug "Hooks registered"
|
data/lib/prebake/platform.rb
CHANGED
|
@@ -9,12 +9,12 @@ module Prebake
|
|
|
9
9
|
[/\Aaarch64-linux(-gnu)?\z/, "aarch64-linux"]
|
|
10
10
|
].freeze
|
|
11
11
|
|
|
12
|
-
def self.normalize(
|
|
12
|
+
def self.normalize(platform)
|
|
13
13
|
NORMALIZATIONS.each do |pattern, normalized|
|
|
14
|
-
return normalized if
|
|
14
|
+
return normalized if platform.match?(pattern)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
platform
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def self.generalized
|
|
@@ -44,7 +44,7 @@ module Prebake
|
|
|
44
44
|
private
|
|
45
45
|
|
|
46
46
|
def build_platform_spec(build_dir)
|
|
47
|
-
platform_spec =
|
|
47
|
+
platform_spec = gemspec.dup
|
|
48
48
|
platform_spec.platform = Gem::Platform.new(Platform.generalized)
|
|
49
49
|
platform_spec.extensions = []
|
|
50
50
|
|
|
@@ -64,6 +64,12 @@ module Prebake
|
|
|
64
64
|
platform_spec
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
# Bundler's spec for a compact-index gem has no summary, authors or files,
|
|
68
|
+
# so read the full gemspec from the downloaded .gem. Path and git gems have none.
|
|
69
|
+
def gemspec
|
|
70
|
+
File.exist?(@spec.cache_file) ? Gem::Package.new(@spec.cache_file).spec : @spec
|
|
71
|
+
end
|
|
72
|
+
|
|
67
73
|
def copy_installed_binaries(ext_dir, build_dir)
|
|
68
74
|
installed_binaries(ext_dir).each do |binary|
|
|
69
75
|
next if File.symlink?(binary)
|
data/lib/prebake/static_ruby.rb
CHANGED
|
@@ -10,14 +10,14 @@ module Prebake
|
|
|
10
10
|
# instead of installing a broken .so. Extend via PREBAKE_OPTIONAL_NATIVE_EXTENSIONS=gem1,gem2.
|
|
11
11
|
# Intentionally empty: bootsnap 1.18+ requires its native extension unconditionally;
|
|
12
12
|
# skipping the build produces a broken install.
|
|
13
|
-
|
|
13
|
+
DEFAULT_OPTIONAL_NATIVE_EXTENSIONS = %w[].freeze
|
|
14
14
|
|
|
15
15
|
class << self
|
|
16
16
|
def optional_native_extensions
|
|
17
17
|
@optional_native_extensions ||= begin
|
|
18
18
|
extra = ENV.fetch("PREBAKE_OPTIONAL_NATIVE_EXTENSIONS", "")
|
|
19
19
|
.split(",").map(&:strip).reject(&:empty?)
|
|
20
|
-
(
|
|
20
|
+
(DEFAULT_OPTIONAL_NATIVE_EXTENSIONS + extra).uniq
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prebake
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thejus Paul
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Prebake speeds up bundle install by skipping native gem compilation.
|
|
14
14
|
It fetches precompiled binaries for gems like puma, nokogiri, pg, grpc, and bootsnap
|
|
@@ -33,7 +33,7 @@ files:
|
|
|
33
33
|
- lib/prebake/cache_key.rb
|
|
34
34
|
- lib/prebake/elf_inspector.rb
|
|
35
35
|
- lib/prebake/ext_builder_patch.rb
|
|
36
|
-
- lib/prebake/
|
|
36
|
+
- lib/prebake/extension_layout.rb
|
|
37
37
|
- lib/prebake/extractor.rb
|
|
38
38
|
- lib/prebake/glibc.rb
|
|
39
39
|
- lib/prebake/hooks.rb
|