Skip to content

Commit c942cbb

Browse files
authored
Merge pull request #46 from seanmakesgames/node-18-test-port
Port tests and fixes from Node 17 to Node 18
2 parents 51ffc8e + e202ffe commit c942cbb

17 files changed

+265
-38
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
rubocop:
77
name: Lint (Rubocop)
88
runs-on: ubuntu-20.04
9-
container: ruby:2.6
9+
container: ruby:2.7
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v2
@@ -30,8 +30,12 @@ jobs:
3030
outputs:
3131
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
3232
runs-on: ubuntu-20.04
33-
container: ruby:2.6
33+
container: ruby:2.7
3434
steps:
35+
- name: Update Rubygems and Bundler
36+
run: |
37+
gem update --system 3.3.26
38+
gem install bundler -v '~> 2.3.26'
3539
- name: Checkout
3640
uses: actions/checkout@v2
3741
- name: Bundle
@@ -118,6 +122,14 @@ jobs:
118122
- name: Inject V8
119123
run: |
120124
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
125+
- name: Test V8 in C++
126+
if: matrix.platform != 'arm64'
127+
run: |
128+
cd test/gtest
129+
cmake -S . -B build
130+
cd build
131+
cmake --build .
132+
./c_v8_tests
121133
- name: Build binary gem
122134
run: |
123135
bundle exec rake binary
@@ -191,10 +203,10 @@ jobs:
191203
run: |
192204
case ${{ matrix.libc }} in
193205
gnu)
194-
echo 'ruby:2.6'
206+
echo 'ruby:2.7'
195207
;;
196208
musl)
197-
echo 'ruby:2.6-alpine'
209+
echo 'ruby:2.7-alpine'
198210
;;
199211
esac | tee container_image
200212
echo "::set-output name=image::$(cat container_image)"
@@ -203,12 +215,20 @@ jobs:
203215
echo "::set-output name=id::$(cat container_id)"
204216
- name: Install Alpine system dependencies
205217
if: ${{ matrix.libc == 'musl' }}
206-
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python3 git curl tar
218+
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python3 git curl tar cmake
219+
- name: Install Debian system dependencies
220+
if: ${{ matrix.libc == 'gnu' }}
221+
run: |
222+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
223+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y cmake
207224
- name: Install Debian cross-compiler
208225
if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }}
209226
run: |
210-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
211227
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
228+
- name: Update Rubygems and Bundler
229+
run: |
230+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system 3.3.26
231+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install bundler -v '~> 2.3.26'
212232
- name: Checkout
213233
uses: actions/checkout@v2
214234
- name: Bundle
@@ -245,6 +265,10 @@ jobs:
245265
- name: Inject V8
246266
run: |
247267
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
268+
- name: Test V8 in C++
269+
if: matrix.platform != 'arm64'
270+
run: |
271+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bash -c "cd test/gtest && cmake -S . -B build && cd build && cmake --build . && ctest"
248272
- name: Build binary gem
249273
run: |
250274
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake binary[${{ steps.platform.outputs.ruby_target_platform }}]
@@ -266,12 +290,6 @@ jobs:
266290
- amd64
267291
# other platforms would need emulation, which is way too slow
268292
container:
269-
- image: ruby:2.6
270-
version: '2.6'
271-
libc: gnu
272-
- image: ruby:2.6-alpine
273-
version: '2.6'
274-
libc: musl
275293
- image: ruby:2.7
276294
version: '2.7'
277295
libc: gnu
@@ -298,6 +316,10 @@ jobs:
298316
- name: Install Alpine system dependencies
299317
if: ${{ matrix.container.libc == 'musl' }}
300318
run: apk add --no-cache build-base linux-headers bash python3 git curl tar
319+
- name: Update Rubygems and Bundler
320+
run: |
321+
gem update --system 3.3.26
322+
gem install bundler -v '~> 2.3.26'
301323
- name: Set metadata
302324
id: set-metadata
303325
run: |
@@ -312,6 +334,7 @@ jobs:
312334
run: gem install --verbose pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.gem
313335
- name: Test with mini_racer
314336
run: |
337+
export BUNDLE_FORCE_RUBY_PLATFORM=y
315338
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
316339
cd test/mini_racer
317340
git fetch origin refs/pull/261/head
@@ -364,7 +387,6 @@ jobs:
364387
fail-fast: false
365388
matrix:
366389
version:
367-
- '2.6'
368390
- '2.7'
369391
- '3.0'
370392
- '3.1'
@@ -378,9 +400,6 @@ jobs:
378400
- gnu
379401
- musl
380402
include:
381-
- version: '2.6'
382-
platform: 'arm64'
383-
libc: 'gnu'
384403
- version: '2.7'
385404
platform: 'arm64'
386405
libc: 'gnu'
@@ -418,6 +437,10 @@ jobs:
418437
- name: Install Alpine system dependencies
419438
if: ${{ matrix.libc == 'musl' }}
420439
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base git libstdc++
440+
- name: Update Rubygems and Bundler
441+
run: |
442+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system 3.3.26
443+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install bundler -v '~> 2.3.26'
421444
- name: Set metadata
422445
id: set-metadata
423446
run: |

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
AllCops:
2+
SuggestExtensions: false
3+
NewCops: disable
24
TargetRubyVersion: 2.0
35
Exclude:
46
- src/**/*
57
- pkg/**/*
68
- vendor/**/*
9+
- test/**/*
710

811
Naming/FileName:
912
Exclude:
@@ -26,3 +29,6 @@ Style/WordArray:
2629

2730
Style/PerlBackrefs:
2831
Enabled: false
32+
33+
Gemspec/RequiredRubyVersion:
34+
Enabled: false

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ FROM ruby:${RUBY_VERSION}
33

44
RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar
55

6+
RUN gem update --system 3.3.26 && gem install bundler -v '~> 2.3.26'
7+
68
RUN mkdir -p /code
79
WORKDIR /code
810

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ gem: pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem
2121

2222
test: test/$(CPU)-$(OS)
2323

24+
ctest: vendor/v8
25+
cd test/gtest && cmake -S . -B build && cd build && cmake --build . && ctest
26+
2427
src/node-v$(NODE_VERSION).tar.gz:
2528
./libexec/download-node $(NODE_VERSION)
2629

Rakefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ task :compile, [:platform] => [] do |_, args|
2323
local_platform = Gem::Platform.local
2424
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)
2525

26-
if target_platform.os == 'darwin'
27-
target_platform.instance_eval { @version = nil }
28-
end
26+
target_platform.instance_eval { @version = nil } if target_platform.os == 'darwin'
2927

3028
puts "local platform: #{local_platform}"
3129
puts "target platform: #{target_platform}"
@@ -46,9 +44,7 @@ task :binary, [:platform] => [:compile] do |_, args|
4644
local_platform = Gem::Platform.local.dup
4745
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)
4846

49-
if target_platform.os == 'darwin'
50-
target_platform.instance_eval { @version = nil }
51-
end
47+
target_platform.instance_eval { @version = nil } if target_platform.os == 'darwin'
5248

5349
puts "local platform: #{local_platform}"
5450
puts "target platform: #{target_platform}"

ext/libv8-node/builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
unless $LOAD_PATH.include?(File.expand_path('../../lib', __dir__))
1+
unless $LOAD_PATH.include?(File.expand_path('../../lib', __dir__)) # rubocop:disable Style/IfUnlessModifier
22
$LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
33
end
44
require 'libv8/node/version'

ext/libv8-node/location.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def configure(context = MkmfContext.new)
4545
def verify_installation!
4646
include_paths = Libv8::Node::Paths.include_paths
4747

48-
unless include_paths.detect { |p| Pathname(p).join('v8.h').exist? }
48+
unless include_paths.detect { |p| Pathname(p).join('v8.h').exist? } # rubocop:disable Style/IfUnlessModifier
4949
raise(HeaderNotFound, "Unable to locate 'v8.h' in the libv8 header paths: #{include_paths.inspect}")
5050
end
5151

libexec/build-libv8

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ BUILDTYPE="${BUILDTYPE:-Release}"
1717

1818
cd "${src}/node-v${version}"
1919

20-
if command -v python3 >/dev/null 2>&1; then
21-
PYTHON="${PYTHON:-python3}"
22-
else
23-
PYTHON="${PYTHON:-python2}"
24-
fi
25-
2620
configure_flags='--openssl-no-asm --without-npm --shared --with-intl=full-icu'
2721
eval "$("${libexec}/platform")"
2822

@@ -33,10 +27,18 @@ ${CC} -v
3327
${CXX} -v
3428

3529
# shellcheck disable=SC2086
36-
"${PYTHON}" configure ${configure_flags}
30+
./configure ${configure_flags}
3731

3832
make BUILDTYPE="${BUILDTYPE}" config.gypi
3933
make BUILDTYPE="${BUILDTYPE}" "out/Makefile"
4034

35+
# workaround for node specifying `-msign-return-address=all` in ALL `CFLAGS` for aarch64 builds
36+
# (if the host isn't also aarch64, this flag causes a compiler error)
37+
38+
# shellcheck disable=SC2154 # these variables are defined by `eval`ing the output of the platform script above
39+
if [ "$host_platform" != "$target_platform" ] && [ "${target_platform%%-*}" = "aarch64" ]; then
40+
find . -iname "*.host.mk" -exec sed -i '/-msign-return-address/d' {} ';'
41+
fi
42+
4143
export PATH="${PWD}/out/tools/bin:${PATH}"
4244
make -j"${NJOBS}" -C out BUILDTYPE="${BUILDTYPE}" V=0

libexec/build-monolith

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ platform=$(uname)
2121
rm -f "${LIBV8_MONOLITH}"
2222
case "${platform}" in
2323
"SunOS")
24-
/usr/xpg4/bin/find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar cq "${LIBV8_MONOLITH}"
24+
/usr/xpg4/bin/find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar cq "${LIBV8_MONOLITH}"
2525
;;
2626
"Darwin")
27-
/usr/bin/find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs /usr/bin/ar -cq "${LIBV8_MONOLITH}"
27+
/usr/bin/find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs /usr/bin/ar -cq "${LIBV8_MONOLITH}"
2828
;;
2929
"Linux")
30-
find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar -cq "${LIBV8_MONOLITH}"
30+
find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -and '(' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" ')' | sort | uniq | xargs ar -cqSP "${LIBV8_MONOLITH}"
31+
ar -sP "${LIBV8_MONOLITH}"
3132
;;
3233
*)
3334
echo "Unsupported platform: ${platform}"

libexec/inject-libv8

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,35 @@ for lib in libv8_monolith.a; do
3939
mkdir -p "${dir}"
4040
rm -f "${dir}/${lib}"
4141

42-
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
43-
"${STRIP}" -S -x -o "${dir}/${lib}" "${lib}"
42+
if [ "$STRIP_NEEDS_EXTRACT" = "y" ]; then
43+
# manual extract/strip objects/build archive sequence
44+
# because `strip` can't deal with these
45+
# (presumably due to that folder issue mentioned below)
46+
(
47+
tmpdir="$(mktemp -d)"
48+
trap 'rm -r "$tmpdir"' EXIT
49+
mkdir "$tmpdir/stage"
50+
cd "$tmpdir/stage"
51+
52+
# create folders named in `ar` archive (`ar -x` fails to create these)
53+
"$AR" "$ARLISTFLAGS" "$BASEDIR/out/$BUILDTYPE/$lib" | while read -r path; do
54+
dirname "$path"
55+
done | uniq | xargs mkdir -p
56+
"$AR" "$AREXTRACTFLAGS" "$BASEDIR/out/${BUILDTYPE}/$lib"
57+
58+
# strip all objects
59+
"$FIND" -type f -exec "$STRIP" -Sx {} +
60+
61+
# rebuild the archive
62+
"$FIND" -type f -exec "$AR" "$ARCOLLECTFLAGS" "../$lib" {} +
63+
$ARBUILDSYMBOLS "../$lib"
64+
mv "../$lib" "$dir/$lib"
65+
)
66+
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
67+
else
68+
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
69+
"${STRIP}" -S -x -o "${dir}/${lib}" "${lib}"
70+
fi
4471
done
4572

4673
mkdir -p "${top}/ext/libv8-node"

libexec/platform

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ elif command -v cc >/dev/null 2>&1; then
1515
fi
1616

1717
STRIP="${STRIP:-strip}"
18+
AR="${AR:-ar}"
19+
AREXTRACTFLAGS="${AREXTRACTFLAGS:--x}"
20+
ARLISTFLAGS="${ARLISTFLAGS:--t}"
21+
ARCOLLECTFLAGS="${ARCOLLECTFLAGS:-cqS}"
22+
# this is the command to build the symbol table in an ar archive.
23+
ARBUILDSYMBOLS="${ARBUILDSYMBOLS:-ranlib}"
24+
FIND="${FIND:-find}"
25+
STRIP_NEEDS_EXTRACT="${STRIP_NEEDS_EXTRACT:-n}"
1826

1927
triple=$(${CC} -dumpmachine)
2028
host_platform="${triple}"
@@ -63,6 +71,11 @@ case "${host_platform}" in
6371
CXX="${CXX:-/opt/local/gcc7/bin/g++}"
6472
STRIP="gstrip"
6573
;;
74+
*linux*)
75+
STRIP_NEEDS_EXTRACT="y"
76+
ARCOLLECTFLAGS="-cqSP"
77+
ARBUILDSYMBOLS="${AR} -sP"
78+
;;
6679
esac
6780

6881
if [ "${host_platform}" != "${target_platform}" ]; then
@@ -146,6 +159,14 @@ export CC='${CC}'
146159
export CXX='${CXX}'
147160
host_platform='${host_platform}'
148161
target_platform='${target_platform}'
162+
STRIP='$STRIP'
163+
AR='$AR'
164+
AREXTRACTFLAGS='$AREXTRACTFLAGS'
165+
ARLISTFLAGS='$ARLISTFLAGS'
166+
ARCOLLECTFLAGS='$ARCOLLECTFLAGS'
167+
ARBUILDSYMBOLS='$ARBUILDSYMBOLS'
168+
FIND='$FIND'
169+
STRIP_NEEDS_EXTRACT='$STRIP_NEEDS_EXTRACT'
149170
EOF
150171

151172
if [ -n "${CC_host:-}" ]; then cat <<EOF; fi

libv8-node.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
22
require 'libv8/node/version'
33

44
Gem::Specification.new do |s|
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
2323
s.require_paths = ['lib', 'ext']
2424

2525
s.add_development_dependency 'rake', '~> 12'
26-
s.add_development_dependency 'rubocop', '~> 0.50.0'
26+
s.add_development_dependency 'rubocop', '~> 1.44.0'
2727
end

test/gtest/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CMakeLists.txt.user
2+
CMakeCache.txt
3+
CMakeFiles
4+
CMakeScripts
5+
Testing
6+
Makefile
7+
cmake_install.cmake
8+
install_manifest.txt
9+
compile_commands.json
10+
CTestTestfile.cmake
11+
_deps
12+
build
13+
lib
14+
bin

0 commit comments

Comments
 (0)