Skip to content

Commit cf6b17b

Browse files
committed
Add 'ruby' from-source platform
1 parent f7fec49 commit cf6b17b

18 files changed

+187
-78
lines changed

.github/workflows/build.yml

+46-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,48 @@ on:
33
- push
44

55
jobs:
6+
build-ruby:
7+
name: Build (ruby)
8+
runs-on: ubuntu-20.04
9+
container: ruby:2.3
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
- name: Bundle
14+
run: bundle install
15+
- name: Set metadata
16+
id: set-metadata
17+
run: |
18+
bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
19+
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
20+
bundle exec ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
21+
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
22+
bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
23+
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
24+
bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_version
25+
echo "::set-output name=NODE_VERSION::$(cat node_version)"
26+
bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_version
27+
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
28+
- name: Download Node.js
29+
run: |
30+
./libexec/download-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
31+
- name: Extract Node.js
32+
run: |
33+
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
34+
- name: Validate V8 version
35+
run: |
36+
ruby -e 'h = File.read("src/node-${{ steps.set-metadata.outputs.NODE_VERSION }}/deps/v8/include/v8-version.h"); eval h.each_line.with_object([]) { |l, e| l =~ /#define (V8_[A-Z_]+)\s(\d+)/ && e << "#{$1} = #{$2}" }.join(";"); puts "#{V8_MAJOR_VERSION}.#{V8_MINOR_VERSION}.#{V8_BUILD_NUMBER}.#{V8_PATCH_LEVEL}"' | tee libv8_version_h
37+
diff libv8_version_h libv8_version
38+
- name: Build gem
39+
run: |
40+
bundle exec rake build
41+
- name: Upload gem
42+
uses: actions/upload-artifact@v1
43+
with:
44+
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-ruby
45+
path: pkg
646
build-macos:
7-
name: Build (macOS)
47+
name: Build (x86_64-darwin)
848
runs-on: macos-10.15
949
steps:
1050
- name: Checkout
@@ -43,7 +83,7 @@ jobs:
4383
- name: Inject V8
4484
run: |
4585
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
46-
- name: Build gem
86+
- name: Build binary gems
4787
run: |
4888
bundle exec rake binary:all
4989
- name: Upload V8
@@ -57,7 +97,7 @@ jobs:
5797
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
5898
path: pkg
5999
build-linux-glibc:
60-
name: Build (Linux glibc)
100+
name: Build (x86_64-linux-gnu)
61101
runs-on: ubuntu-20.04
62102
container: ruby:2.3
63103
steps:
@@ -97,7 +137,7 @@ jobs:
97137
- name: Inject V8
98138
run: |
99139
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
100-
- name: Build gem
140+
- name: Build binary gem
101141
run: |
102142
bundle exec rake binary
103143
- name: Upload V8
@@ -111,7 +151,7 @@ jobs:
111151
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
112152
path: pkg
113153
build-linux-musl:
114-
name: Build (Linux musl)
154+
name: Build (x86_64-linux-musl)
115155
runs-on: ubuntu-20.04
116156
container: ruby:2.3-alpine
117157
steps:
@@ -153,7 +193,7 @@ jobs:
153193
- name: Inject V8
154194
run: |
155195
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
156-
- name: Build gem
196+
- name: Build binary gem
157197
run: |
158198
bundle exec rake binary
159199
- name: Prepare artifacts

.rubocop.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
AllCops:
2+
TargetRubyVersion: 2.0
3+
Exclude:
4+
- src/**
5+
6+
Style/Documentation:
7+
Enabled: false
8+
9+
Style/ClassAndModuleChildren:
10+
Enabled: false
11+
12+
Style/NumericPredicate:
13+
Enabled: false
14+
15+
Metrics/LineLength:
16+
Enabled: false

Gemfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
# Specify your gem's dependencies in libv8.gemspec
43
gemspec

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2009,2010 Charles Lowell
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Rakefile

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Helpers
88
def binary_gemspec(platform: Gem::Platform.local, str: RUBY_PLATFORM)
99
platform.instance_eval { @version = 'musl' } if str =~ /-musl/ && platform.version.nil?
1010

11-
gemspec = eval(File.read('libv8-node.gemspec'))
11+
gemspec = eval(File.read('libv8-node.gemspec')) # rubocop:disable Security/Eval
1212
gemspec.platform = platform
1313
gemspec
1414
end
@@ -19,7 +19,7 @@ module Helpers
1919
end
2020

2121
task :compile do
22-
#sh 'ruby ext/libv8-node/extconf.rb'
22+
sh 'ruby ext/libv8-node/extconf.rb'
2323
end
2424

2525
task :binary, [:platform] => [:compile] do |_, args|
@@ -50,15 +50,17 @@ task :binary, [:platform] => [:compile] do |_, args|
5050
end
5151

5252
namespace :binary do
53-
task :all => :binary do
53+
task all: :binary do
5454
return unless RUBY_PLATFORM =~ /darwin-?(\d+)/
5555

56-
Helpers.binary_gemspec # loads NODE_VERSION
57-
5856
current = Integer($1)
57+
58+
Helpers.binary_gemspec # loads NODE_VERSION
5959
major, minor = File.read(Dir["src/node-#{Libv8::Node::NODE_VERSION}/common.gypi"].last).lines.find { |l| l =~ /-mmacosx-version-min=(\d+).(\d+)/ } && [Integer($1), Integer($2)]
60-
first = minor + 4
61-
max = 20
60+
61+
first = minor + 4 # macos 10.X => darwinY offset
62+
first = 20 if RUBY_PLATFORM =~ /^arm46/
63+
max = 20 # current known max
6264

6365
(first..max).each do |version|
6466
next if version == current
@@ -67,7 +69,7 @@ namespace :binary do
6769
platform.instance_eval { @version = version }
6870
puts "> building #{platform}"
6971

70-
Rake::Task["binary"].execute(Rake::TaskArguments.new([:platform], [platform]))
72+
Rake::Task['binary'].execute(Rake::TaskArguments.new([:platform], [platform]))
7173
end
7274
end
7375
end

Vagrantfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Vagrant.configure("2") do |config|
1+
Vagrant.configure('2') do |config|
22
config.vm.box = 'secretescapes/smartos-base64'
33
config.vm.box_version = '1.0.0'
44
config.vm.synced_folder './vagrant', '/usbkey/user_home/vagrant/vagrant',
@@ -19,5 +19,3 @@ Vagrant.configure("2") do |config|
1919
v.customize ['modifyvm', :id, '--cpus', 2]
2020
end
2121
end
22-
23-

ext/libv8-node/.location.yml

-2
This file was deleted.

ext/libv8-node/builder.rb

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
unless $LOAD_PATH.include?(File.expand_path('../../lib', __dir__))
2+
$LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
3+
end
4+
require 'libv8/node/version'
5+
6+
module Libv8::Node
7+
class BuilderError < StandardError; end
8+
9+
class Builder
10+
def build_libv8!
11+
version = Libv8::Node::NODE_VERSION
12+
download_node(version) || raise(BuilderError, "failed to download node #{NODE_VERSION}")
13+
extract_node(version) || raise(BuilderError, "failed to extract node #{NODE_VERSION}")
14+
build_libv8(version) || raise(BuilderError, "failed to build libv8 #{NODE_VERSION}")
15+
build_monolith(version) || raise(BuilderError, "failed to build monolith #{NODE_VERSION}")
16+
inject_libv8(version) || raise(BuilderError, "failed to inject libv8 #{NODE_VERSION}")
17+
18+
0
19+
end
20+
21+
private
22+
23+
def download_node(version)
24+
system(script('download-node'), version)
25+
end
26+
27+
def extract_node(version)
28+
system(script('extract-node'), version)
29+
end
30+
31+
def build_libv8(version)
32+
system(script('build-libv8'), version)
33+
end
34+
35+
def build_monolith(version)
36+
system(script('build-monolith'), version)
37+
end
38+
39+
def inject_libv8(version)
40+
system(script('inject-libv8'), version)
41+
end
42+
43+
def script(name)
44+
File.expand_path("../../libexec/#{name}", __dir__).tap { |v| p Dir.pwd; p v }
45+
end
46+
end
47+
end

ext/libv8-node/extconf.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
# frozen_string_literal: true
2+
13
require 'mkmf'
24
create_makefile('libv8-node')
35

4-
#require File.expand_path('../location', __FILE__)
5-
#location = Libv8::Node::Location::Vendor.new
6+
require File.expand_path('location', __dir__)
7+
location = Libv8::Node::Location::Vendor.new
68

7-
#exit location.install!
8-
exit 0
9+
exit location.install!

ext/libv8-node/location.rb

+22-38
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
1+
# frozen_string_literal: true
2+
13
require 'yaml'
24
require 'pathname'
3-
require File.expand_path '../paths', __FILE__
5+
require File.expand_path('paths', __dir__)
46

57
module Libv8; end
68

79
module Libv8::Node
810
class Location
911
def install!
10-
File.open(Pathname(__FILE__).dirname.join('.location.yml'), "w") do |f|
11-
f.write self.to_yaml
12+
File.open(Pathname(__FILE__).dirname.join('.location.yml'), 'w') do |f|
13+
f.write(to_yaml)
1214
end
13-
return 0
15+
16+
0
1417
end
1518

1619
def self.load!
1720
File.open(Pathname(__FILE__).dirname.join('.location.yml')) do |f|
18-
YAML.load f
21+
YAML.load(f) # rubocop:disable Security/YAMLLoad
1922
end
2023
end
2124

2225
class Vendor < Location
2326
def install!
24-
require File.expand_path '../builder', __FILE__
27+
require File.expand_path('builder', __dir__)
28+
2529
builder = Libv8::Node::Builder.new
2630
exit_status = builder.build_libv8!
31+
2732
super if exit_status == 0
33+
2834
verify_installation!
29-
return exit_status
35+
36+
exit_status
3037
end
3138

3239
def configure(context = MkmfContext.new)
33-
context.incflags.insert 0, Libv8::Node::Paths.include_paths.map{ |p| "-I#{p}" }.join(" ") + " "
34-
context.ldflags.insert 0, Libv8::Node::Paths.object_paths.join(" ") + " "
40+
context.incflags.insert(0, Libv8::Node::Paths.include_paths.map { |p| "-I#{p}" }.join(' ') << ' ')
41+
context.ldflags.insert(0, Libv8::Node::Paths.object_paths.join(' ') << ' ')
3542
end
3643

3744
def verify_installation!
3845
include_paths = Libv8::Node::Paths.include_paths
46+
3947
unless include_paths.detect { |p| Pathname(p).join('v8.h').exist? }
40-
fail HeaderNotFound, "Unable to locate 'v8.h' in the libv8 header paths: #{include_paths.inspect}"
48+
raise(HeaderNotFound, "Unable to locate 'v8.h' in the libv8 header paths: #{include_paths.inspect}")
4149
end
50+
4251
Libv8::Node::Paths.object_paths.each do |p|
43-
fail ArchiveNotFound, p unless File.exist? p
52+
raise(ArchiveNotFound, p) unless File.exist?(p)
4453
end
4554
end
4655

@@ -53,38 +62,13 @@ def initialize(filename)
5362
end
5463
end
5564

56-
class System < Location
57-
def configure(context = MkmfContext.new)
58-
context.send(:dir_config, 'v8')
59-
context.send(:find_header, 'v8.h') or fail NotFoundError
60-
context.send(:find_header, 'libplatform/libplatform.h') or fail NotFoundError
61-
context.send(:have_library, 'v8') or fail NotFoundError
62-
end
63-
64-
class NotFoundError < StandardError
65-
def initialize(*args)
66-
super(<<-EOS)
67-
By using --with-system-v8, you have chosen to use the version
68-
of V8 found on your system and *not* the one that is bundled with
69-
the libv8 rubygem.
70-
71-
However, your system version of v8 could not be located.
72-
73-
Please make sure your system version of v8 that is compatible
74-
with #{Libv8::Node::VERSION} installed. You may need to use the
75-
--with-v8-dir option if it is installed in a non-standard location
76-
EOS
77-
end
78-
end
79-
end
80-
8165
class MkmfContext
8266
def incflags
83-
$INCFLAGS
67+
$INCFLAGS # rubocop:disable Style/GlobalVars
8468
end
8569

8670
def ldflags
87-
$LDFLAGS
71+
$LDFLAGS # rubocop:disable Style/GlobalVars
8872
end
8973
end
9074
end

ext/libv8-node/paths.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def config
2424
end
2525

2626
def vendored_source_path
27-
File.expand_path "../../../vendor/v8", __FILE__
27+
File.expand_path('../../vendor/v8', __dir__)
2828
end
2929
end
3030
end

lib/libv8/node/version.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Libv8; end
22

33
module Libv8::Node
4-
VERSION = "15.5.1.0.beta1"
5-
NODE_VERSION = "15.5.1"
6-
LIBV8_VERSION = "8.6.395.17" # v8/include/v8-version.h
4+
VERSION = '15.5.1.0.beta1'.freeze
5+
NODE_VERSION = '15.5.1'.freeze
6+
LIBV8_VERSION = '8.6.395.17'.freeze # from v8/include/v8-version.h
77
end

libexec/build-libv8

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set -e
44
set -u
55

66
version="${1}"
7+
libexec="$(cd "$(dirname "$0")"; pwd)"
8+
top="${libexec}/.."
9+
src="${2:-"${top}/src"}"
710

811
platform=$(uname)
912

@@ -12,7 +15,7 @@ NJOBS="${NJOBS:-1}"
1215

1316
echo "parallel job count: ${NJOBS}"
1417

15-
cd "src/node-${version}"
18+
cd "${src}/node-${version}"
1619

1720
if which python3 >/dev/null 2>&1; then
1821
PYTHON="${PYTHON:-python3}"

0 commit comments

Comments
 (0)