Skip to content

Port tests and fixes from Node 17 to Node 18 #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
rubocop:
name: Lint (Rubocop)
runs-on: ubuntu-20.04
container: ruby:2.6
container: ruby:2.7
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -30,8 +30,12 @@ jobs:
outputs:
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
runs-on: ubuntu-20.04
container: ruby:2.6
container: ruby:2.7
steps:
- name: Update Rubygems and Bundler
run: |
gem update --system 3.3.26
gem install bundler -v '~> 2.3.26'
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
Expand Down Expand Up @@ -118,6 +122,14 @@ jobs:
- name: Inject V8
run: |
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Test V8 in C++
if: matrix.platform != 'arm64'
run: |
cd test/gtest
cmake -S . -B build
cd build
cmake --build .
./c_v8_tests
- name: Build binary gem
run: |
bundle exec rake binary
Expand Down Expand Up @@ -191,10 +203,10 @@ jobs:
run: |
case ${{ matrix.libc }} in
gnu)
echo 'ruby:2.6'
echo 'ruby:2.7'
;;
musl)
echo 'ruby:2.6-alpine'
echo 'ruby:2.7-alpine'
;;
esac | tee container_image
echo "::set-output name=image::$(cat container_image)"
Expand All @@ -203,12 +215,20 @@ jobs:
echo "::set-output name=id::$(cat container_id)"
- name: Install Alpine system dependencies
if: ${{ matrix.libc == 'musl' }}
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python3 git curl tar
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python3 git curl tar cmake
- name: Install Debian system dependencies
if: ${{ matrix.libc == 'gnu' }}
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y cmake
- name: Install Debian cross-compiler
if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }}
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Update Rubygems and Bundler
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system 3.3.26
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install bundler -v '~> 2.3.26'
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
Expand Down Expand Up @@ -245,6 +265,10 @@ jobs:
- name: Inject V8
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Test V8 in C++
if: matrix.platform != 'arm64'
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bash -c "cd test/gtest && cmake -S . -B build && cd build && cmake --build . && ctest"
- name: Build binary gem
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake binary[${{ steps.platform.outputs.ruby_target_platform }}]
Expand All @@ -266,12 +290,6 @@ jobs:
- amd64
# other platforms would need emulation, which is way too slow
container:
- image: ruby:2.6
version: '2.6'
libc: gnu
- image: ruby:2.6-alpine
version: '2.6'
libc: musl
- image: ruby:2.7
version: '2.7'
libc: gnu
Expand All @@ -298,6 +316,10 @@ jobs:
- name: Install Alpine system dependencies
if: ${{ matrix.container.libc == 'musl' }}
run: apk add --no-cache build-base linux-headers bash python3 git curl tar
- name: Update Rubygems and Bundler
run: |
gem update --system 3.3.26
gem install bundler -v '~> 2.3.26'
- name: Set metadata
id: set-metadata
run: |
Expand All @@ -312,6 +334,7 @@ jobs:
run: gem install --verbose pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.gem
- name: Test with mini_racer
run: |
export BUNDLE_FORCE_RUBY_PLATFORM=y
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
cd test/mini_racer
git fetch origin refs/pull/261/head
Expand Down Expand Up @@ -364,7 +387,6 @@ jobs:
fail-fast: false
matrix:
version:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
Expand All @@ -378,9 +400,6 @@ jobs:
- gnu
- musl
include:
- version: '2.6'
platform: 'arm64'
libc: 'gnu'
- version: '2.7'
platform: 'arm64'
libc: 'gnu'
Expand Down Expand Up @@ -418,6 +437,10 @@ jobs:
- name: Install Alpine system dependencies
if: ${{ matrix.libc == 'musl' }}
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base git libstdc++
- name: Update Rubygems and Bundler
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system 3.3.26
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install bundler -v '~> 2.3.26'
- name: Set metadata
id: set-metadata
run: |
Expand Down
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
AllCops:
SuggestExtensions: false
NewCops: disable
TargetRubyVersion: 2.0
Exclude:
- src/**/*
- pkg/**/*
- vendor/**/*
- test/**/*

Naming/FileName:
Exclude:
Expand All @@ -26,3 +29,6 @@ Style/WordArray:

Style/PerlBackrefs:
Enabled: false

Gemspec/RequiredRubyVersion:
Enabled: false
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM ruby:${RUBY_VERSION}

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

RUN gem update --system 3.3.26 && gem install bundler -v '~> 2.3.26'

RUN mkdir -p /code
WORKDIR /code

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ gem: pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem

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

ctest: vendor/v8
cd test/gtest && cmake -S . -B build && cd build && cmake --build . && ctest

src/node-v$(NODE_VERSION).tar.gz:
./libexec/download-node $(NODE_VERSION)

Expand Down
8 changes: 2 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ task :compile, [:platform] => [] do |_, args|
local_platform = Gem::Platform.local
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)

if target_platform.os == 'darwin'
target_platform.instance_eval { @version = nil }
end
target_platform.instance_eval { @version = nil } if target_platform.os == 'darwin'

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

if target_platform.os == 'darwin'
target_platform.instance_eval { @version = nil }
end
target_platform.instance_eval { @version = nil } if target_platform.os == 'darwin'

puts "local platform: #{local_platform}"
puts "target platform: #{target_platform}"
Expand Down
2 changes: 1 addition & 1 deletion ext/libv8-node/builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless $LOAD_PATH.include?(File.expand_path('../../lib', __dir__))
unless $LOAD_PATH.include?(File.expand_path('../../lib', __dir__)) # rubocop:disable Style/IfUnlessModifier
$LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
end
require 'libv8/node/version'
Expand Down
2 changes: 1 addition & 1 deletion ext/libv8-node/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def configure(context = MkmfContext.new)
def verify_installation!
include_paths = Libv8::Node::Paths.include_paths

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

Expand Down
16 changes: 9 additions & 7 deletions libexec/build-libv8
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ BUILDTYPE="${BUILDTYPE:-Release}"

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

if command -v python3 >/dev/null 2>&1; then
PYTHON="${PYTHON:-python3}"
else
PYTHON="${PYTHON:-python2}"
fi

configure_flags='--openssl-no-asm --without-npm --shared --with-intl=full-icu'
eval "$("${libexec}/platform")"

Expand All @@ -33,10 +27,18 @@ ${CC} -v
${CXX} -v

# shellcheck disable=SC2086
"${PYTHON}" configure ${configure_flags}
./configure ${configure_flags}

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

# workaround for node specifying `-msign-return-address=all` in ALL `CFLAGS` for aarch64 builds
# (if the host isn't also aarch64, this flag causes a compiler error)

# shellcheck disable=SC2154 # these variables are defined by `eval`ing the output of the platform script above
if [ "$host_platform" != "$target_platform" ] && [ "${target_platform%%-*}" = "aarch64" ]; then
find . -iname "*.host.mk" -exec sed -i '/-msign-return-address/d' {} ';'
fi

export PATH="${PWD}/out/tools/bin:${PATH}"
make -j"${NJOBS}" -C out BUILDTYPE="${BUILDTYPE}" V=0
7 changes: 4 additions & 3 deletions libexec/build-monolith
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ platform=$(uname)
rm -f "${LIBV8_MONOLITH}"
case "${platform}" in
"SunOS")
/usr/xpg4/bin/find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar cq "${LIBV8_MONOLITH}"
/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}"
;;
"Darwin")
/usr/bin/find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs /usr/bin/ar -cq "${LIBV8_MONOLITH}"
/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}"
;;
"Linux")
find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar -cq "${LIBV8_MONOLITH}"
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}"
ar -sP "${LIBV8_MONOLITH}"
;;
*)
echo "Unsupported platform: ${platform}"
Expand Down
31 changes: 29 additions & 2 deletions libexec/inject-libv8
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,35 @@ for lib in libv8_monolith.a; do
mkdir -p "${dir}"
rm -f "${dir}/${lib}"

echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
"${STRIP}" -S -x -o "${dir}/${lib}" "${lib}"
if [ "$STRIP_NEEDS_EXTRACT" = "y" ]; then
# manual extract/strip objects/build archive sequence
# because `strip` can't deal with these
# (presumably due to that folder issue mentioned below)
(
tmpdir="$(mktemp -d)"
trap 'rm -r "$tmpdir"' EXIT
mkdir "$tmpdir/stage"
cd "$tmpdir/stage"

# create folders named in `ar` archive (`ar -x` fails to create these)
"$AR" "$ARLISTFLAGS" "$BASEDIR/out/$BUILDTYPE/$lib" | while read -r path; do
dirname "$path"
done | uniq | xargs mkdir -p
"$AR" "$AREXTRACTFLAGS" "$BASEDIR/out/${BUILDTYPE}/$lib"

# strip all objects
"$FIND" -type f -exec "$STRIP" -Sx {} +

# rebuild the archive
"$FIND" -type f -exec "$AR" "$ARCOLLECTFLAGS" "../$lib" {} +
$ARBUILDSYMBOLS "../$lib"
mv "../$lib" "$dir/$lib"
)
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
else
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
"${STRIP}" -S -x -o "${dir}/${lib}" "${lib}"
fi
done

mkdir -p "${top}/ext/libv8-node"
Expand Down
21 changes: 21 additions & 0 deletions libexec/platform
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ elif command -v cc >/dev/null 2>&1; then
fi

STRIP="${STRIP:-strip}"
AR="${AR:-ar}"
AREXTRACTFLAGS="${AREXTRACTFLAGS:--x}"
ARLISTFLAGS="${ARLISTFLAGS:--t}"
ARCOLLECTFLAGS="${ARCOLLECTFLAGS:-cqS}"
# this is the command to build the symbol table in an ar archive.
ARBUILDSYMBOLS="${ARBUILDSYMBOLS:-ranlib}"
FIND="${FIND:-find}"
STRIP_NEEDS_EXTRACT="${STRIP_NEEDS_EXTRACT:-n}"

triple=$(${CC} -dumpmachine)
host_platform="${triple}"
Expand Down Expand Up @@ -63,6 +71,11 @@ case "${host_platform}" in
CXX="${CXX:-/opt/local/gcc7/bin/g++}"
STRIP="gstrip"
;;
*linux*)
STRIP_NEEDS_EXTRACT="y"
ARCOLLECTFLAGS="-cqSP"
ARBUILDSYMBOLS="${AR} -sP"
;;
esac

if [ "${host_platform}" != "${target_platform}" ]; then
Expand Down Expand Up @@ -146,6 +159,14 @@ export CC='${CC}'
export CXX='${CXX}'
host_platform='${host_platform}'
target_platform='${target_platform}'
STRIP='$STRIP'
AR='$AR'
AREXTRACTFLAGS='$AREXTRACTFLAGS'
ARLISTFLAGS='$ARLISTFLAGS'
ARCOLLECTFLAGS='$ARCOLLECTFLAGS'
ARBUILDSYMBOLS='$ARBUILDSYMBOLS'
FIND='$FIND'
STRIP_NEEDS_EXTRACT='$STRIP_NEEDS_EXTRACT'
EOF

if [ -n "${CC_host:-}" ]; then cat <<EOF; fi
Expand Down
4 changes: 2 additions & 2 deletions libv8-node.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'libv8/node/version'

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

s.add_development_dependency 'rake', '~> 12'
s.add_development_dependency 'rubocop', '~> 0.50.0'
s.add_development_dependency 'rubocop', '~> 1.44.0'
end
14 changes: 14 additions & 0 deletions test/gtest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build
lib
bin
Loading