Skip to content

Commit c77e1c8

Browse files
authored
Merge pull request #28 from sqreen/single-darwin-version
Build a single darwin gem for all versions
2 parents e7488fc + 8abdaec commit c77e1c8

File tree

6 files changed

+30
-42
lines changed

6 files changed

+30
-42
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ jobs:
115115
- name: Inject V8
116116
run: |
117117
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
118-
- name: Build binary gems
118+
- name: Build binary gem
119119
run: |
120-
bundle exec rake binary:all
120+
bundle exec rake binary
121121
- name: Upload V8
122122
uses: actions/upload-artifact@v1
123123
with:
@@ -299,7 +299,7 @@ jobs:
299299
- name: Set metadata
300300
id: set-metadata
301301
run: |
302-
ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
302+
ruby -e 'puts Gem.platforms.last.to_s.gsub(/-darwin-?\d+/, "-darwin")' | tee gem_platform
303303
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
304304
- name: Download a single artifact
305305
uses: actions/download-artifact@v2

Rakefile

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ module Helpers
2020
end
2121

2222
task :compile, [:platform] => [] do |_, args|
23-
local_platform = Gem::Platform.local.to_s
24-
target_platform = ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local.to_s
23+
local_platform = Gem::Platform.local
24+
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)
25+
26+
if target_platform.os == 'darwin'
27+
target_platform.instance_eval { @version = nil }
28+
end
2529

2630
puts "local platform: #{local_platform}"
2731
puts "target platform: #{target_platform}"
2832

29-
ENV['RUBY_TARGET_PLATFORM'] = target_platform
33+
ENV['RUBY_TARGET_PLATFORM'] = target_platform.to_s
3034

3135
if (libs = Dir["vendor/v8/#{target_platform}/**/*.a"]).any?
3236
puts "found: #{libs.inspect}"
@@ -39,8 +43,12 @@ task :compile, [:platform] => [] do |_, args|
3943
end
4044

4145
task :binary, [:platform] => [:compile] do |_, args|
42-
local_platform = Gem::Platform.local
43-
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM']) || Gem::Platform.new(args.to_h[:platform]) || Gem::Platform.local
46+
local_platform = Gem::Platform.local.dup
47+
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)
48+
49+
if target_platform.os == 'darwin'
50+
target_platform.instance_eval { @version = nil }
51+
end
4452

4553
puts "local platform: #{local_platform}"
4654
puts "target platform: #{target_platform}"
@@ -69,33 +77,3 @@ task :binary, [:platform] => [:compile] do |_, args|
6977

7078
FileUtils.mv(package, 'pkg')
7179
end
72-
73-
namespace :binary do
74-
task all: :binary do
75-
next unless RUBY_PLATFORM =~ /darwin-?(\d+)/
76-
77-
current = Integer($1)
78-
79-
Helpers.binary_gemspec # loads NODE_VERSION
80-
major, minor = File.read(Dir["src/node-v#{Libv8::Node::NODE_VERSION}/common.gypi"].last).lines.find { |l| l =~ /-mmacosx-version-min=(\d+).(\d+)/ } && [Integer($1), Integer($2)]
81-
82-
first = if RUBY_PLATFORM =~ /\barm64e?-/
83-
20 # arm64 darwin is only available since darwin20
84-
elsif major == 10
85-
minor + 4 # macos 10.X => darwinY offset, 10.15 is darwin19
86-
else
87-
minor + 20 # maxos 11.X => darwinY offset, 11.0 is darwin20
88-
end
89-
max = 20 # current known max to build for
90-
91-
(first..max).each do |version|
92-
next if version == current
93-
94-
platform = Gem::Platform.local.dup
95-
platform.instance_eval { @version = version }
96-
puts "> building #{platform}"
97-
98-
Rake::Task['binary'].execute(Rake::TaskArguments.new([:platform], [platform]))
99-
end
100-
end
101-
end

ext/libv8-node/paths.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ def include_paths
1313

1414
def object_paths
1515
[Shellwords.escape(File.join(vendored_source_path,
16-
Gem::Platform.local.to_s,
16+
platform,
1717
'libv8',
1818
'obj',
1919
"libv8_monolith.#{config['LIBEXT']}"))]
2020
end
2121

22+
def platform
23+
Gem::Platform.local.to_s.gsub(/-darwin-?\d+/, '-darwin')
24+
end
25+
2226
def config
2327
RbConfig::MAKEFILE_CONFIG
2428
end

libexec/inject-libv8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ done
2626

2727
cd "${BASEDIR}/out/${BUILDTYPE}"
2828

29+
case "${RUBY_TARGET_PLATFORM}" in
30+
*-darwin*)
31+
RUBY_TARGET_PLATFORM="$(echo "${RUBY_TARGET_PLATFORM}" | sed -e 's/-darwin[0-9]*/-darwin/')"
32+
;;
33+
esac
34+
2935
rm -rf "${top}/vendor/v8/${RUBY_TARGET_PLATFORM}"
3036
# shellcheck disable=SC2043
3137
for lib in libv8_monolith.a; do

libexec/metadata

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ case "$1" in
55
ruby -e 'puts RUBY_PLATFORM'
66
;;
77
gem_platform)
8-
ruby -e 'puts Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }'
8+
ruby -e 'puts Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }.to_s.gsub(/-darwin-?\d+/, "-darwin")'
99
;;
1010
gem_version|version)
1111
ruby -I'lib' -r'libv8/node/version' -e 'puts Libv8::Node::VERSION'

libexec/platform

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ case "${target_platform}" in
4242
;;
4343
x86_64*-darwin*)
4444
# not for cross compilation
45-
RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s')"
45+
RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s.gsub(/-darwin-?\d+/, "-darwin")')"
4646
;;
4747
arm64*-darwin*)
4848
# not for cross compilation
49-
RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s')"
49+
RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s.gsub(/-darwin-?\d+/, "-darwin")')"
5050
;;
5151
*)
5252
# not for cross compilation

0 commit comments

Comments
 (0)