From 2e94fc288ed3014243cdf7bdc70f4c340c5fa585 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Mon, 24 Jan 2022 15:53:58 +0100 Subject: [PATCH 01/47] Fix repo address --- libv8-node.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libv8-node.gemspec b/libv8-node.gemspec index 240f6a1..920f547 100644 --- a/libv8-node.gemspec +++ b/libv8-node.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.authors = [''] s.email = [''] - s.homepage = 'https://github.com/sqreen/ruby-libv8-node' + s.homepage = 'https://github.com/rubyjs/libv8-node' s.summary = "Node.JS's V8 JavaScript engine" s.description = "Node.JS's V8 JavaScript engine for multiplatform goodness" s.license = 'MIT' From 21eeb92bea74b0b180fd9b04fb2cb23539a4f34f Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Mon, 24 Jan 2022 16:03:32 +0100 Subject: [PATCH 02/47] Pin mini_racer test version --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a5b8cd..a666dba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -312,8 +312,8 @@ jobs: run: | git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 cd test/mini_racer - git fetch origin refs/pull/210/head - git checkout FETCH_HEAD + git fetch origin + git checkout 746bfdd git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-darwin.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb @@ -395,8 +395,8 @@ jobs: run: | git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 cd test/mini_racer - git fetch origin refs/pull/210/head - git checkout FETCH_HEAD + git fetch origin + git checkout 746bfdd git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-linux.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb From a6cc61ec5dd4660494ecb0b6013ac2cadd56dda3 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Mon, 18 Oct 2021 12:53:54 +0200 Subject: [PATCH 03/47] Patch platform for musl tests with old rubygems --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a666dba..678f39f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -382,7 +382,7 @@ jobs: - name: Set metadata id: set-metadata run: | - docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform + docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ruby -e 'puts Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }.to_s' | tee gem_platform echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)" - name: Download a single artifact uses: actions/download-artifact@v2 From f55ed74191f75f1098ed22b66745d4183e8dc5ce Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 19 Oct 2021 18:41:33 +0200 Subject: [PATCH 04/47] Fix library path for old rubygems --- ext/libv8-node/paths.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/libv8-node/paths.rb b/ext/libv8-node/paths.rb index 79abbc0..a51a000 100644 --- a/ext/libv8-node/paths.rb +++ b/ext/libv8-node/paths.rb @@ -20,7 +20,7 @@ def object_paths end def platform - Gem::Platform.local.to_s.gsub(/-darwin-?\d+/, '-darwin') + Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }.to_s.gsub(/-darwin-?\d+/, '-darwin') end def config From 90b7d78e99d90336f5e47138dfe0cbc898024cfb Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 18:04:49 +0200 Subject: [PATCH 05/47] Improve local building - Add make targets for local building and testing This is especially useful for building and testing on Darwin - Split makefile in two: one direct and one for docker This is necessary because direct targets and dockerized targets overlap on Linux. - Fix a few Dockerfile oversights due to updates in libexec --- .gitignore | 1 + Dockerfile | 2 ++ Makefile | 64 +++++++++++++++++++++++++----------------------- Makefile.docker | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 Makefile.docker diff --git a/.gitignore b/.gitignore index 2844876..363d565 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ Makefile /ext/libv8-node/.location.yml /test/mini_racer +/test/bundle *.nix *.vim .envrc diff --git a/Dockerfile b/Dockerfile index b2f7a29..dfbed55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,13 @@ WORKDIR /code ARG NODE_VERSION=16.10.0 +COPY sums/v${NODE_VERSION}.sum /code/sums/ COPY libexec/download-node /code/libexec/ RUN ./libexec/download-node ${NODE_VERSION} COPY libexec/extract-node /code/libexec/ COPY patch/* /code/patch/ RUN ./libexec/extract-node ${NODE_VERSION} +COPY libexec/platform /code/libexec/ COPY libexec/build-libv8 /code/libexec/ RUN ./libexec/build-libv8 ${NODE_VERSION} COPY libexec/build-monolith /code/libexec/ diff --git a/Makefile b/Makefile index 29338e0..2fc1dca 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,47 @@ PWD := $(shell pwd) +OS := $(shell uname -s | tr '[A-Z]' '[a-z]') +CPU := $(shell uname -m) VERSION := $(shell ./libexec/metadata version) NODE_VERSION := $(shell ./libexec/metadata node_version) +RUBY_VERSION = $(shell ruby -e 'puts RUBY_VERSION.gsub(/\d+$$/, "0")') -all: +vars: + @echo $(PWD) + @echo $(OS) $(CPU) + @echo $(VERSION) $(NODE_VERSION) + @echo $(RUBY_VERSION) -pkg/libv8-node-$(VERSION)-x86_64-linux.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --progress plain -t libv8-node:gnu . - docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:gnu cp $@ /pkg/ +all: gem test -pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4-alpine --progress plain -t libv8-node:musl . - docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:musl cp $@ /pkg/ +build: src/node-v$(NODE_VERSION)/out/Release/node -pkg/libv8-node-$(VERSION)-aarch64-linux.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4 --progress plain -t libv8-node:gnu . - docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:gnu cp $@ /pkg/ +lib: src/node-v$(NODE_VERSION)/out/Release/libv8_monolith.a -pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4-alpine --progress plain -t libv8-node:musl . - docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:musl cp $@ /pkg/ +gem: pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem -test/x86_64-linux: pkg/libv8-node-$(VERSION)-x86_64-linux.gem - test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/186/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x - ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb - docker run --platform linux/amd64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:gnu sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' +test: test/$(CPU)-$(OS) -test/x86_64-linux-musl: pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem - test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/186/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x - ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb - docker run --platform linux/amd64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:musl sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' +src/node-v$(NODE_VERSION).tar.gz: + ./libexec/download-node $(NODE_VERSION) -test/aarch64-linux: pkg/libv8-node-$(VERSION)-aarch64-linux.gem - test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/186/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x - ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb - docker run --platform linux/arm64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:gnu sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' +src/node-v$(NODE_VERSION): src/node-v$(NODE_VERSION).tar.gz + ./libexec/extract-node $(NODE_VERSION) + +src/node-v$(NODE_VERSION)/out/Release/node: src/node-v$(NODE_VERSION) + ./libexec/build-libv8 $(NODE_VERSION) + +src/node-v$(NODE_VERSION)/out/Release/libv8_monolith.a: src/node-v$(NODE_VERSION)/out/Release/node + ./libexec/build-monolith $(NODE_VERSION) + +vendor/v8: src/node-v$(NODE_VERSION)/out/Release/libv8_monolith.a + ./libexec/inject-libv8 $(NODE_VERSION) + +pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem: vendor/v8 + bundle exec rake binary -test/aarch64-linux-musl: pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem +test/$(CPU)-$(OS): pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/186/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb - docker run --platform linux/arm64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:musl sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' + ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec + cd test/mini_racer && env TOP="$(PWD)" GEM_HOME="$(PWD)/test/bundle/ruby/$(RUBY_VERSION)" BUNDLE_PATH="$(PWD)/test/bundle" sh -c 'rm -rf "$${GEM_HOME}" && gem install $${TOP}/$< && bundle install && bundle exec rake compile && bundle exec rake test' diff --git a/Makefile.docker b/Makefile.docker new file mode 100644 index 0000000..e24b6c7 --- /dev/null +++ b/Makefile.docker @@ -0,0 +1,65 @@ +PWD := $(shell pwd) +OS := $(shell uname -s | tr '[A-Z]' '[a-z]') +CPU := $(shell uname -m) +VERSION := $(shell ./libexec/metadata version) +NODE_VERSION := $(shell ./libexec/metadata node_version) +RUBY_VERSION = $(shell ruby -e 'puts RUBY_VERSION.gsub(/\d+$$/, "0")') + +vars: + @echo $(PWD) + @echo $(OS) $(CPU) + @echo $(VERSION) $(NODE_VERSION) + @echo $(RUBY_VERSION) + +all: gem test + +gem: pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem + +test: test/$(CPU)-$(OS) + +test/linux: test/$(CPU)-linux +test/linux-musl: test/$(CPU)-linux-musl + +pkg/libv8-node-$(VERSION)-x86_64-linux.gem: + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ + +pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem: + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ + +pkg/libv8-node-$(VERSION)-aarch64-linux.gem: + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ + +pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem: + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ + +test/x86_64-linux: pkg/libv8-node-$(VERSION)-x86_64-linux.gem + test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 + cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb + ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec + docker run --platform linux/amd64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-gnu sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' + +test/x86_64-linux-musl: pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem + test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 + cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb + ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec + docker run --platform linux/amd64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-musl sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' + +test/aarch64-linux: pkg/libv8-node-$(VERSION)-aarch64-linux.gem + test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 + cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb + ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec + docker run --platform linux/arm64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-gnu sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' + +test/aarch64-linux-musl: pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem + test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 + cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb + ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec + docker run --platform linux/arm64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-musl sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' From 5c54319fbfa9242fdaffe8bfadb5c324a295adec Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 18:19:22 +0200 Subject: [PATCH 06/47] Transpose CPU to aarch64 for Docker on Darwin --- Makefile.docker | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.docker b/Makefile.docker index e24b6c7..338117e 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -17,8 +17,8 @@ gem: pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem test: test/$(CPU)-$(OS) -test/linux: test/$(CPU)-linux -test/linux-musl: test/$(CPU)-linux-musl +test/linux: test/$(subst arm64,aarch64,$(CPU))-linux +test/linux-musl: test/$(subst arm64,aarch64,$(CPU))-linux-musl pkg/libv8-node-$(VERSION)-x86_64-linux.gem: docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . From f6a5708237ca8b9906edc448ebc0735ebbc8cb80 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 20:25:22 +0200 Subject: [PATCH 07/47] Relax mini_racer Ruby version check for CI testing --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 678f39f..caa48e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -282,6 +282,7 @@ jobs: git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-ruby.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb + ruby -i -ne '$_ =~ /spec.required_ruby_version/ ? "" : print' mini_racer.gemspec bundle install bundle exec rake compile bundle exec rake test @@ -317,6 +318,7 @@ jobs: git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-darwin.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb + ruby -i -ne '$_ =~ /spec.required_ruby_version/ ? "" : print' mini_racer.gemspec bundle install bundle exec rake compile bundle exec rake test @@ -400,6 +402,7 @@ jobs: git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-linux.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb + ruby -i -ne '$_ =~ /spec.required_ruby_version/ ? "" : print' mini_racer.gemspec docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake compile docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake test From f4d6da80a4d5f533f211dfd692360b60af70fb9b Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 20:26:41 +0200 Subject: [PATCH 08/47] Use Ruby 2.6 as base compiling environment --- .github/workflows/build.yml | 4 ++-- Dockerfile | 2 +- Makefile.docker | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index caa48e1..6209b88 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -188,10 +188,10 @@ jobs: run: | case ${{ matrix.libc }} in gnu) - echo 'ruby:2.4' + echo 'ruby:2.6' ;; musl) - echo 'ruby:2.4-alpine' + echo 'ruby:2.6-alpine' ;; esac | tee container_image echo "::set-output name=image::$(cat container_image)" diff --git a/Dockerfile b/Dockerfile index dfbed55..5f93ced 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG RUBY_VERSION=2.4 +ARG RUBY_VERSION=2.6 FROM ruby:${RUBY_VERSION} RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar diff --git a/Makefile.docker b/Makefile.docker index 338117e..e15e7f7 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -21,19 +21,19 @@ test/linux: test/$(subst arm64,aarch64,$(CPU))-linux test/linux-musl: test/$(subst arm64,aarch64,$(CPU))-linux-musl pkg/libv8-node-$(VERSION)-x86_64-linux.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.6 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.6-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ pkg/libv8-node-$(VERSION)-aarch64-linux.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.6 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.6-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ test/x86_64-linux: pkg/libv8-node-$(VERSION)-x86_64-linux.gem From 13280053fc26c00a52b70c00e45165ddc710468a Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 22:13:05 +0200 Subject: [PATCH 09/47] Remove Ruby 2.5 --- .github/workflows/build.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6209b88..a032c93 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -259,7 +259,7 @@ jobs: name: Test (ruby) needs: build-ruby runs-on: ubuntu-20.04 - container: ruby:2.5 + container: ruby:2.6 steps: - name: Set metadata id: set-metadata @@ -327,7 +327,6 @@ jobs: fail-fast: false matrix: version: - - '2.5' - '2.6' - '2.7' - '3.0' @@ -341,9 +340,6 @@ jobs: - gnu - musl include: - - version: '2.5' - platform: 'arm64' - libc: 'gnu' - version: '2.6' platform: 'arm64' libc: 'gnu' From fe34cc60fe10a8266e9e6139614826b9794e5c73 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 22:15:47 +0200 Subject: [PATCH 10/47] Add Ruby 3.1 --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a032c93..6689900 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -330,6 +330,7 @@ jobs: - '2.6' - '2.7' - '3.0' + - '3.1' platform: - amd64 # arm64 @@ -349,6 +350,9 @@ jobs: - version: '3.0' platform: 'arm64' libc: 'gnu' + - version: '3.1' + platform: 'arm64' + libc: 'gnu' name: Test (linux) needs: build-linux runs-on: ubuntu-20.04 From 4460470f627ad9da5e570de37400efa877ed220d Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 25 Aug 2022 22:21:00 +0200 Subject: [PATCH 11/47] Fix lint --- ext/libv8-node/paths.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/libv8-node/paths.rb b/ext/libv8-node/paths.rb index a51a000..469ad5f 100644 --- a/ext/libv8-node/paths.rb +++ b/ext/libv8-node/paths.rb @@ -20,7 +20,7 @@ def object_paths end def platform - Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }.to_s.gsub(/-darwin-?\d+/, '-darwin') + Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? && p.instance_eval { @version = 'musl' } }.to_s.gsub(/-darwin-?\d+/, '-darwin') end def config From 690c03faa90514aaa813b647fb11f242420c6de1 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 13:01:36 +0200 Subject: [PATCH 12/47] Test ruby platform on musl too --- .github/workflows/build.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6689900..c85bad5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -256,11 +256,25 @@ jobs: name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }} path: pkg test-ruby: - name: Test (ruby) + strategy: + fail-fast: false + matrix: + platform: + - amd64 + # other platforms would need emulation, which is way too slow + container: + - image: ruby:2.6 + libc: gnu + - image: ruby:2.6-alpine + libc: musl + name: Test (ruby, ${{ matrix.container.libc }}) needs: build-ruby runs-on: ubuntu-20.04 - container: ruby:2.6 + container: ${{ matrix.container.image }} steps: + - name: Install Alpine system dependencies + if: ${{ matrix.container.libc == 'musl' }} + run: apk add --no-cache build-base linux-headers bash python2 python3 git curl tar - name: Set metadata id: set-metadata run: | From ff6449f4642180ff6e62412074636f6489a3aa3a Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 13:32:38 +0200 Subject: [PATCH 13/47] Test more versions for `ruby` platform --- .github/workflows/build.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c85bad5..42ae6d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -264,10 +264,30 @@ jobs: # 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 - name: Test (ruby, ${{ matrix.container.libc }}) + - image: ruby:2.7 + version: '2.7' + libc: gnu + - image: ruby:2.7-alpine + version: '2.7' + libc: musl + - image: ruby:3.0 + version: '3.0' + libc: gnu + - image: ruby:3.0-alpine + version: '3.0' + libc: musl + - image: ruby:3.1 + version: '3.1' + libc: gnu + - image: ruby:3.1-alpine + version: '3.1' + libc: musl + name: Test (ruby) (${{ matrix.container.version }}, ${{ matrix.platform }}, ${{ matrix.container.libc }}) needs: build-ruby runs-on: ubuntu-20.04 container: ${{ matrix.container.image }} From b5a47ed6e6e654369f995c51254824390564c43a Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 16:30:54 +0200 Subject: [PATCH 14/47] Move CI to macOS 12 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42ae6d7..1de09c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,7 @@ jobs: name: Build (darwin) outputs: GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }} - runs-on: macos-10.15 + runs-on: macos-12 steps: - name: Checkout uses: actions/checkout@v2 @@ -329,7 +329,7 @@ jobs: # arm64 name: Test (darwin) needs: build-darwin - runs-on: macos-10.15 + runs-on: macos-12 steps: - name: Set metadata id: set-metadata From 3be6699d66877cee7dc0f10e5832273a2e23dd79 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 16:32:11 +0200 Subject: [PATCH 15/47] Remove python2 from alpine --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1de09c8..e5b0d35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -200,7 +200,7 @@ 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 python2 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 - name: Install Debian cross-compiler if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }} run: | @@ -294,7 +294,7 @@ jobs: steps: - name: Install Alpine system dependencies if: ${{ matrix.container.libc == 'musl' }} - run: apk add --no-cache build-base linux-headers bash python2 python3 git curl tar + run: apk add --no-cache build-base linux-headers bash python3 git curl tar - name: Set metadata id: set-metadata run: | From 7d3ed362f861c47f8f3da023dc2de3abdc231f3e Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 19:05:02 +0200 Subject: [PATCH 16/47] Add ccache support --- libexec/platform | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libexec/platform b/libexec/platform index 85ed12d..13cf729 100755 --- a/libexec/platform +++ b/libexec/platform @@ -102,6 +102,18 @@ fi # ;; # esac +if command -v ccache >/dev/null 2>&1; then + if [ -n "${CC:-}" ]; then + CC="ccache ${CC}" + CXX="ccache ${CXX}" + fi + + if [ -n "${CC_host:-}" ]; then + CC_host="ccache ${CC_host}" + CXX_host="ccache ${CXX_host}" + fi +fi + cat < Date: Fri, 26 Aug 2022 19:06:01 +0200 Subject: [PATCH 17/47] Add more cross-compilation options - arm64-darwin from x86_64-darwin (also added to CI) - x86_64-darwin from arm64-darwin - x86_64-linux from aarch64-linux --- .github/workflows/build.yml | 5 ++++- libexec/build-libv8 | 4 ++-- libexec/platform | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e5b0d35..6bf0004 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,11 +73,14 @@ jobs: matrix: platform: - x86_64 - # arm64 + - arm64 name: Build (darwin) outputs: GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }} runs-on: macos-12 + env: + TARGET_PLATFORM: ${{ matrix.platform }}-darwin + RUBY_TARGET_PLATFORM: ${{ matrix.platform }}-darwin steps: - name: Checkout uses: actions/checkout@v2 diff --git a/libexec/build-libv8 b/libexec/build-libv8 index 0511122..07bb500 100755 --- a/libexec/build-libv8 +++ b/libexec/build-libv8 @@ -29,8 +29,8 @@ eval "$("${libexec}/platform")" echo "configure: ${configure_flags}" echo "compilers: CC='${CC}' CXX='${CXX}' CC_host='${CC_host:-}' CXX_host='${CXX_host:-}'" -"${CC}" -v -"${CXX}" -v +${CC} -v +${CXX} -v # shellcheck disable=SC2086 "${PYTHON}" configure ${configure_flags} diff --git a/libexec/platform b/libexec/platform index 13cf729..dd25081 100755 --- a/libexec/platform +++ b/libexec/platform @@ -16,7 +16,7 @@ fi STRIP="${STRIP:-strip}" -triple=$("${CC}" -dumpmachine) +triple=$(${CC} -dumpmachine) host_platform="${triple}" target_platform="${TARGET_PLATFORM:-${1:-}}" target_platform="${target_platform:-${host_platform}}" @@ -42,14 +42,17 @@ case "${target_platform}" in ;; x86_64*-darwin*) # not for cross compilation - RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s.gsub(/-darwin-?\d+/, "-darwin")')" + RUBY_TARGET_PLATFORM='x86_64-darwin' ;; arm64*-darwin*) # not for cross compilation - RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s.gsub(/-darwin-?\d+/, "-darwin")')" + RUBY_TARGET_PLATFORM='arm64-darwin' ;; *) - # not for cross compilation + if [ "${host_platform}" != "${target_platform}" ]; then + echo 'cross compilation not supported' + exit 1 + fi RUBY_TARGET_PLATFORM="$(ruby -e 'puts Gem::Platform.local.to_s')" ;; esac @@ -81,6 +84,30 @@ if [ "${host_platform}" != "${target_platform}" ]; then STRIP='arm-linux-gnueabihf-strip' configure_flags='--dest-cpu=arm --cross-compiling --dest-os=linux --with-arm-float-abi=hard --with-arm-fpu=neon' ;; + x86_64-*linux*) + CC='x86_64-linux-gnu-gcc' + CXX='x86_64-linux-gnu-g++' + CC_host='gcc' + CXX_host='g++' + STRIP='x86_64-linux-gnu-strip' + configure_flags='--dest-cpu=x86_64 --cross-compiling --dest-os=linux' + ;; + x86_64*-darwin*) + CC='clang -arch x86_64' + CXX='clang++ -arch x86_64' + CC_host='clang' + CXX_host='clang++' + STRIP='strip' + configure_flags='--dest-cpu=x86_64 --cross-compiling --dest-os=mac' + ;; + arm64*-darwin*) + CC='clang -arch arm64' + CXX='clang++ -arch arm64' + CC_host='clang' + CXX_host='clang++' + STRIP='strip' + configure_flags='--dest-cpu=arm64 --cross-compiling --dest-os=mac' + ;; *) configure_flags='' ;; From f53bf1e104c88cbfaf7cca99edd4aa2d1e3a94c7 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 21:18:31 +0200 Subject: [PATCH 18/47] Update to node 16.17.0 --- Dockerfile | 2 +- lib/libv8/node/version.rb | 6 +++--- sums/v16.17.0.sum | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 sums/v16.17.0.sum diff --git a/Dockerfile b/Dockerfile index 5f93ced..01c3a35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 RUN mkdir -p /code WORKDIR /code -ARG NODE_VERSION=16.10.0 +ARG NODE_VERSION=16.17.0 COPY sums/v${NODE_VERSION}.sum /code/sums/ COPY libexec/download-node /code/libexec/ diff --git a/lib/libv8/node/version.rb b/lib/libv8/node/version.rb index 1160d71..7428636 100644 --- a/lib/libv8/node/version.rb +++ b/lib/libv8/node/version.rb @@ -1,7 +1,7 @@ module Libv8; end module Libv8::Node - VERSION = '16.10.0.0'.freeze - NODE_VERSION = '16.10.0'.freeze - LIBV8_VERSION = '9.3.345.19'.freeze # from v8/include/v8-version.h + VERSION = '16.17.0.0'.freeze + NODE_VERSION = '16.17.0'.freeze + LIBV8_VERSION = '9.4.146.26'.freeze # from v8/include/v8-version.h end diff --git a/sums/v16.17.0.sum b/sums/v16.17.0.sum new file mode 100644 index 0000000..a8c2aa7 --- /dev/null +++ b/sums/v16.17.0.sum @@ -0,0 +1 @@ +2a2e6262739741f98ab81648a50891861dbf66f12413b93f1a97b4c71570611e From 6b7f57d3c54ccb822cc82e2845c30f7ba64a323e Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 26 Aug 2022 21:26:10 +0200 Subject: [PATCH 19/47] Move back to macOS 11 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6bf0004..9680031 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,7 @@ jobs: name: Build (darwin) outputs: GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }} - runs-on: macos-12 + runs-on: macos-11 env: TARGET_PLATFORM: ${{ matrix.platform }}-darwin RUBY_TARGET_PLATFORM: ${{ matrix.platform }}-darwin @@ -332,7 +332,7 @@ jobs: # arm64 name: Test (darwin) needs: build-darwin - runs-on: macos-12 + runs-on: macos-11 steps: - name: Set metadata id: set-metadata From 98078bc07bad7801d5729f4cfe8ee09de87adb6d Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Sat, 27 Aug 2022 19:39:03 +0200 Subject: [PATCH 20/47] Build with Ruby 2.4 --- .github/workflows/build.yml | 4 ++-- Dockerfile | 2 +- Makefile.docker | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9680031..650de8b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -191,10 +191,10 @@ jobs: run: | case ${{ matrix.libc }} in gnu) - echo 'ruby:2.6' + echo 'ruby:2.4' ;; musl) - echo 'ruby:2.6-alpine' + echo 'ruby:2.4-alpine' ;; esac | tee container_image echo "::set-output name=image::$(cat container_image)" diff --git a/Dockerfile b/Dockerfile index 01c3a35..eac2d67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG RUBY_VERSION=2.6 +ARG RUBY_VERSION=2.4 FROM ruby:${RUBY_VERSION} RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar diff --git a/Makefile.docker b/Makefile.docker index e15e7f7..338117e 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -21,19 +21,19 @@ test/linux: test/$(subst arm64,aarch64,$(CPU))-linux test/linux-musl: test/$(subst arm64,aarch64,$(CPU))-linux-musl pkg/libv8-node-$(VERSION)-x86_64-linux.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.6 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.6-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ pkg/libv8-node-$(VERSION)-aarch64-linux.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.6 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.6-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ test/x86_64-linux: pkg/libv8-node-$(VERSION)-x86_64-linux.gem From 98c92583b66b54ee8bac139ca57d0c1a79700db5 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Sat, 27 Aug 2022 19:40:03 +0200 Subject: [PATCH 21/47] Test with mini_racer 0.6.3 --- .github/workflows/build.yml | 12 ++++++------ Makefile | 2 +- Makefile.docker | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 650de8b..1c521a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -314,8 +314,8 @@ jobs: run: | git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 cd test/mini_racer - git fetch origin refs/pull/210/head - git checkout FETCH_HEAD + git fetch origin v0.6.3 + git checkout -f FETCH_HEAD git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-ruby.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb @@ -350,8 +350,8 @@ jobs: run: | git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 cd test/mini_racer - git fetch origin - git checkout 746bfdd + git fetch origin v0.6.3 + git checkout -f FETCH_HEAD git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-darwin.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb @@ -434,8 +434,8 @@ jobs: run: | git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 cd test/mini_racer - git fetch origin - git checkout 746bfdd + git fetch origin v0.6.3 + git checkout -f FETCH_HEAD git reset --hard git clean -f -d -x ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-linux.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb diff --git a/Makefile b/Makefile index 2fc1dca..08aa933 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem: vendor/v8 test/$(CPU)-$(OS): pkg/libv8-node-$(VERSION)-$(CPU)-$(OS).gem test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + cd test/mini_racer && git fetch origin v0.6.3 && git checkout -f FETCH_HEAD && git reset --hard && git clean -f -d -x ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec cd test/mini_racer && env TOP="$(PWD)" GEM_HOME="$(PWD)/test/bundle/ruby/$(RUBY_VERSION)" BUNDLE_PATH="$(PWD)/test/bundle" sh -c 'rm -rf "$${GEM_HOME}" && gem install $${TOP}/$< && bundle install && bundle exec rake compile && bundle exec rake test' diff --git a/Makefile.docker b/Makefile.docker index 338117e..4739807 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -38,28 +38,28 @@ pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem: test/x86_64-linux: pkg/libv8-node-$(VERSION)-x86_64-linux.gem test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + cd test/mini_racer && git fetch origin v0.6.3 && git checkout -f FETCH_HEAD && git reset --hard && git clean -f -d -x ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec docker run --platform linux/amd64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-gnu sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' test/x86_64-linux-musl: pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + cd test/mini_racer && git fetch origin v0.6.3 && git checkout -f FETCH_HEAD && git reset --hard && git clean -f -d -x ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec docker run --platform linux/amd64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-musl sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' test/aarch64-linux: pkg/libv8-node-$(VERSION)-aarch64-linux.gem test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + cd test/mini_racer && git fetch origin v0.6.3 && git checkout -f FETCH_HEAD && git reset --hard && git clean -f -d -x ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec docker run --platform linux/arm64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-gnu sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' test/aarch64-linux-musl: pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem test -d test/mini_racer || git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1 - cd test/mini_racer && git fetch origin refs/pull/232/head && git checkout FETCH_HEAD && git reset --hard && git clean -f -d -x + cd test/mini_racer && git fetch origin v0.6.3 && git checkout -f FETCH_HEAD && git reset --hard && git clean -f -d -x ruby -i -ne '$$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"$(VERSION)\"\n") : print' test/mini_racer/lib/mini_racer/version.rb ruby -i -ne '$$_ =~ /spec.required_ruby_version/ ? "" : print' test/mini_racer/mini_racer.gemspec docker run --platform linux/arm64 --rm -it -v "$(PWD)/test:/code/test" -w "/code/test/mini_racer" libv8-node:$(VERSION)-musl sh -c 'gem install ../../$< && bundle install && bundle exec rake compile && bundle exec rake test' From 7fa4743091d8c5b8317a1b36c5b627bc2cf493b2 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Sat, 27 Aug 2022 19:41:11 +0200 Subject: [PATCH 22/47] Add ccache only once --- libexec/platform | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/platform b/libexec/platform index dd25081..582ec8b 100755 --- a/libexec/platform +++ b/libexec/platform @@ -130,12 +130,12 @@ fi # esac if command -v ccache >/dev/null 2>&1; then - if [ -n "${CC:-}" ]; then + if [ -n "${CC:-}" ] && [ "${CC}" = "${CC#ccache}" ]; then CC="ccache ${CC}" CXX="ccache ${CXX}" fi - if [ -n "${CC_host:-}" ]; then + if [ -n "${CC_host:-}" ] && [ "${CC_host}" = "${CC_host#ccache}" ]; then CC_host="ccache ${CC_host}" CXX_host="ccache ${CXX_host}" fi From e35a4faa60c2e5e3e61b3e9bcde05531a701d16a Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Sun, 8 Jan 2023 16:04:39 +0100 Subject: [PATCH 23/47] Update to node 16.19.0 --- Dockerfile | 2 +- lib/libv8/node/version.rb | 4 ++-- sums/v16.19.0.sum | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 sums/v16.19.0.sum diff --git a/Dockerfile b/Dockerfile index eac2d67..ab7b567 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 RUN mkdir -p /code WORKDIR /code -ARG NODE_VERSION=16.17.0 +ARG NODE_VERSION=16.19.0 COPY sums/v${NODE_VERSION}.sum /code/sums/ COPY libexec/download-node /code/libexec/ diff --git a/lib/libv8/node/version.rb b/lib/libv8/node/version.rb index 7428636..4a5390a 100644 --- a/lib/libv8/node/version.rb +++ b/lib/libv8/node/version.rb @@ -1,7 +1,7 @@ module Libv8; end module Libv8::Node - VERSION = '16.17.0.0'.freeze - NODE_VERSION = '16.17.0'.freeze + VERSION = '16.19.0.0'.freeze + NODE_VERSION = '16.19.0'.freeze LIBV8_VERSION = '9.4.146.26'.freeze # from v8/include/v8-version.h end diff --git a/sums/v16.19.0.sum b/sums/v16.19.0.sum new file mode 100644 index 0000000..ea3f21b --- /dev/null +++ b/sums/v16.19.0.sum @@ -0,0 +1 @@ +8b8a2939fa5f654ff61cae29b12118c24109273458ecbe6162ad8a8858309e0d From d742196f16e1623592fa90d2e44ce74d6adfc219 Mon Sep 17 00:00:00 2001 From: Fayti1703 Date: Sun, 8 Jan 2023 21:16:15 +0100 Subject: [PATCH 24/47] Optimize 'libexec/build-monolith' on Linux Use `xargs` to build the `ar` command line instead of running `ar` manually to reduce startup costs. Build the symbol table after adding each file instead of continually rebuilding it. --- libexec/build-monolith | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libexec/build-monolith b/libexec/build-monolith index 16c0bac..4e4a903 100755 --- a/libexec/build-monolith +++ b/libexec/build-monolith @@ -33,9 +33,8 @@ case "${platform}" in /usr/bin/ranlib "${LIBV8_MONOLITH}" ;; "Linux") - find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | while read -r obj; do - ar -cq "${LIBV8_MONOLITH}" "${obj}" - done + find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar -cqS "${LIBV8_MONOLITH}" + ranlib "${LIBV8_MONOLITH}" ;; *) echo "Unsupported platform: ${platform}" From abae20efae1b93ee686f2c0a7b5a7197e386b83a Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 10 Jan 2023 14:17:24 +0100 Subject: [PATCH 25/47] Skip compilation on TruffleRuby * Running libv8 on GraalVM LLVM is unlikely to ever work, instead using Graal.js makes more sense. This is already the case in mini_racer. libv8-node is a necessary dependency of mini_racer on CRuby, so for TruffleRuby the extconf.rb simply creates a dummy Makefile. --- .github/workflows/build.yml | 10 ++++++++++ ext/libv8-node/extconf.rb | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c521a2..b4039c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,6 +25,16 @@ jobs: run: apt-get update && apt-get install -y shellcheck - name: Shellcheck run: shellcheck libexec/* + compile-truffleruby: + name: Compile on truffleruby + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: truffleruby + bundler-cache: true + - run: bundle exec rake compile build-ruby: name: Build (ruby) outputs: diff --git a/ext/libv8-node/extconf.rb b/ext/libv8-node/extconf.rb index 20bc370..c2d97d3 100644 --- a/ext/libv8-node/extconf.rb +++ b/ext/libv8-node/extconf.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true require 'mkmf' + +if RUBY_ENGINE == "truffleruby" + File.write("Makefile", dummy_makefile($srcdir).join("")) + return +end + create_makefile('libv8-node') require File.expand_path('location', __dir__) From db76c057c55521c1cc3cef8700b6a42b3e42239d Mon Sep 17 00:00:00 2001 From: Fayti1703 Date: Mon, 9 Jan 2023 22:15:46 +0100 Subject: [PATCH 26/47] Ignore stubdata object This fixes an issue where functions that require ICU data segfault the process due to an unexpected lack of ICU data. The actual ICU data is provided by the icudt71_dat object. --- libexec/build-monolith | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/build-monolith b/libexec/build-monolith index 4e4a903..97d9f45 100755 --- a/libexec/build-monolith +++ b/libexec/build-monolith @@ -21,19 +21,19 @@ 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 | while read -r obj; do + /usr/xpg4/bin/find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -and '(' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" ')' | sort | uniq | while read -r obj; do ar cqS "${LIBV8_MONOLITH}" "${obj}" done ranlib "${LIBV8_MONOLITH}" ;; "Darwin") - /usr/bin/find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | while read -r obj; do + /usr/bin/find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -and '(' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" ')' | sort | uniq | while read -r obj; do /usr/bin/ar -cqS "${LIBV8_MONOLITH}" "${obj}" done /usr/bin/ranlib "${LIBV8_MONOLITH}" ;; "Linux") - find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs ar -cqS "${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 -cqS "${LIBV8_MONOLITH}" ranlib "${LIBV8_MONOLITH}" ;; *) From d8c6b5826f577f5991a10a2af8a5e75ee40314c8 Mon Sep 17 00:00:00 2001 From: Sean Mann Date: Mon, 9 Jan 2023 22:10:10 -0800 Subject: [PATCH 27/47] googletest 'hello test' --- test/gtest/.gitignore | 14 ++++++++++++++ test/gtest/CMakeLists.txt | 28 ++++++++++++++++++++++++++++ test/gtest/hello_test.cc | 9 +++++++++ 3 files changed, 51 insertions(+) create mode 100644 test/gtest/.gitignore create mode 100644 test/gtest/CMakeLists.txt create mode 100644 test/gtest/hello_test.cc diff --git a/test/gtest/.gitignore b/test/gtest/.gitignore new file mode 100644 index 0000000..86201ed --- /dev/null +++ b/test/gtest/.gitignore @@ -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 diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt new file mode 100644 index 0000000..f8d6024 --- /dev/null +++ b/test/gtest/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.14) +project(gtest) + +# GoogleTest requires at least C++14 +set(CMAKE_CXX_STANDARD 14) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable( + hello_test + hello_test.cc +) +target_link_libraries( + hello_test + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(hello_test) diff --git a/test/gtest/hello_test.cc b/test/gtest/hello_test.cc new file mode 100644 index 0000000..5a57e13 --- /dev/null +++ b/test/gtest/hello_test.cc @@ -0,0 +1,9 @@ +#include + +// Demonstrate some basic assertions. +TEST(HelloTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); +} From f17c16022906d05378c884858a55e2d3612f4b84 Mon Sep 17 00:00:00 2001 From: Sean Mann Date: Thu, 12 Jan 2023 21:56:30 -0800 Subject: [PATCH 28/47] get test to reference built libv8 --- test/gtest/CMakeLists.txt | 3 +++ test/gtest/hello_test.cc | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index f8d6024..e7f0740 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -15,6 +15,8 @@ FetchContent_MakeAvailable(googletest) enable_testing() +include_directories(${CMAKE_SOURCE_DIR}/../../vendor/v8/include/) + add_executable( hello_test hello_test.cc @@ -22,6 +24,7 @@ add_executable( target_link_libraries( hello_test GTest::gtest_main + ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a ) include(GoogleTest) diff --git a/test/gtest/hello_test.cc b/test/gtest/hello_test.cc index 5a57e13..525baac 100644 --- a/test/gtest/hello_test.cc +++ b/test/gtest/hello_test.cc @@ -1,7 +1,12 @@ #include +#include +#include + // Demonstrate some basic assertions. TEST(HelloTest, BasicAssertions) { + std::shared_ptr platform = v8::platform::NewDefaultPlatform(); + // Expect two strings not to be equal. EXPECT_STRNE("hello", "world"); // Expect equality. From fdd9edfc806b4b8c1bb20440a08e6b3143abdd1c Mon Sep 17 00:00:00 2001 From: Sean Mann Date: Thu, 12 Jan 2023 22:35:33 -0800 Subject: [PATCH 29/47] actually use v8 in the test --- test/gtest/CMakeLists.txt | 8 +++--- test/gtest/Framework.h | 53 +++++++++++++++++++++++++++++++++++++++ test/gtest/c_v8_tests.cc | 18 +++++++++++++ test/gtest/hello_test.cc | 14 ----------- 4 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 test/gtest/Framework.h create mode 100644 test/gtest/c_v8_tests.cc delete mode 100644 test/gtest/hello_test.cc diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index e7f0740..58f9876 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -18,14 +18,14 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/../../vendor/v8/include/) add_executable( - hello_test - hello_test.cc + c_v8_tests + c_v8_tests.cc ) target_link_libraries( - hello_test + c_v8_tests GTest::gtest_main ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a ) include(GoogleTest) -gtest_discover_tests(hello_test) +gtest_discover_tests(c_v8_tests) diff --git a/test/gtest/Framework.h b/test/gtest/Framework.h new file mode 100644 index 0000000..ed54c59 --- /dev/null +++ b/test/gtest/Framework.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include + +struct Framework { + typedef std::function basic_main; + typedef std::function iso_main; + typedef std::function&)> ctx_main; + + inline static void run(basic_main main) { + std::shared_ptr platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); + v8::V8::Initialize(); + main(); + + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + } + + inline static void runWithIsolateRaw(iso_main main) { + Framework::run([main]() -> void { + v8::Isolate::CreateParams p; + p.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + v8::Isolate* iso = v8::Isolate::New(p); + + main(iso); + + iso->Dispose(); + delete p.array_buffer_allocator; + }); + } + + inline static void runWithIsolate(iso_main main) { + Framework::runWithIsolateRaw([main](v8::Isolate* iso) -> void { + v8::Locker lock { iso }; + v8::Isolate::Scope iScope { iso }; + v8::HandleScope hScope { iso }; + + main(iso); + }); + } + + inline static void runWithContext(ctx_main main) { + Framework::runWithIsolate([main](v8::Isolate* iso) -> void { + v8::Local ctx = v8::Context::New(iso); + v8::Context::Scope cScope { ctx }; + + main(ctx); + }); + } +}; \ No newline at end of file diff --git a/test/gtest/c_v8_tests.cc b/test/gtest/c_v8_tests.cc new file mode 100644 index 0000000..28d4345 --- /dev/null +++ b/test/gtest/c_v8_tests.cc @@ -0,0 +1,18 @@ +#include + +#include +#include + +#include "Framework.h" + +// Demonstrate some basic assertions. +TEST(FRLocaleTest, LocaleTests) { + Framework::runWithContext([](v8::Local& ctx) -> void { + v8::Local script = v8::Script::Compile(ctx, v8::String::NewFromUtf8Literal(ctx->GetIsolate(), "new Date('April 28 2021').toLocaleDateString('fr-FR');")).ToLocalChecked(); + v8::Local result = script->Run(ctx).ToLocalChecked(); + v8::Local resultStr = result->ToString(ctx).ToLocalChecked(); + v8::String::Utf8Value resultUTF8(ctx->GetIsolate(), resultStr); + + EXPECT_STREQ(*resultUTF8, "28/04/2021"); + }); +} diff --git a/test/gtest/hello_test.cc b/test/gtest/hello_test.cc deleted file mode 100644 index 525baac..0000000 --- a/test/gtest/hello_test.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include -#include - -// Demonstrate some basic assertions. -TEST(HelloTest, BasicAssertions) { - std::shared_ptr platform = v8::platform::NewDefaultPlatform(); - - // Expect two strings not to be equal. - EXPECT_STRNE("hello", "world"); - // Expect equality. - EXPECT_EQ(7 * 6, 42); -} From 261889cdac3f85ebbe3b94f6f44e1d0dc5428d71 Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Fri, 13 Jan 2023 16:44:18 +0000 Subject: [PATCH 30/47] Add initial multi-platform support for test. Linking on Linux currently errors with `undefined reference to `'dlsym'` --- test/gtest/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 58f9876..97143a9 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -24,8 +24,13 @@ add_executable( target_link_libraries( c_v8_tests GTest::gtest_main - ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a ) +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + target_link_libraries(c_v8_tests ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a) +else() + target_link_libraries(c_v8_tests ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a) +endif() + include(GoogleTest) gtest_discover_tests(c_v8_tests) From bf1dff5ea06d9d7d6067ec7fdb6fa1d5ef89b419 Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Sun, 15 Jan 2023 15:49:29 +0000 Subject: [PATCH 31/47] Add ctest to makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 08aa933..3779cdb 100644 --- a/Makefile +++ b/Makefile @@ -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) From d8d15675d7f0bc3372a6af91efd29232bfe5e603 Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Sun, 15 Jan 2023 17:08:36 +0000 Subject: [PATCH 32/47] fix building test on linux on some build setups (including our codespace) --- test/gtest/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 97143a9..b0d7e21 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -32,5 +32,8 @@ else() target_link_libraries(c_v8_tests ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a) endif() +# This has to be after the v8 monolith for some build setups. +target_link_libraries(c_v8_tests dl) + include(GoogleTest) gtest_discover_tests(c_v8_tests) From f803993f8bef2c95401c0bc7e99c4e63f45acfbf Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Sun, 15 Jan 2023 16:37:12 +0000 Subject: [PATCH 33/47] integrate test into actions --- .github/workflows/build.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c521a2..32308db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -118,6 +118,13 @@ jobs: - name: Inject V8 run: | ./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }} + - name: Test V8 in C++ + run: | + cd test/gtest + cmake -S . -B build + cd build + cmake --build . + ./c_v8_tests - name: Build binary gem run: | bundle exec rake binary @@ -245,6 +252,9 @@ 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++ + 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 }}] From 024888357a7f8a0b683e6e26e73b50adfed447b6 Mon Sep 17 00:00:00 2001 From: Fayti1703 Date: Mon, 16 Jan 2023 00:38:46 +0100 Subject: [PATCH 34/47] CI: Install CMake in docker container --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 32308db..5bfb8a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -210,11 +210,15 @@ 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: Checkout uses: actions/checkout@v2 From 02f6af37706da3e6def8341c8ce554d127bbf3fc Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Mon, 16 Jan 2023 18:00:26 +0000 Subject: [PATCH 35/47] attempt to move forward docker image to newer version and one that supports the newer cmake. --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5bfb8a2..40bc697 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -198,10 +198,10 @@ jobs: run: | case ${{ matrix.libc }} in gnu) - echo 'ruby:2.4' + echo 'ruby:2.6' ;; musl) - echo 'ruby:2.4-alpine' + echo 'ruby:2.6-alpine' ;; esac | tee container_image echo "::set-output name=image::$(cat container_image)" From fd333f51680428a62f4e018c2bb082032def795e Mon Sep 17 00:00:00 2001 From: Fayti1703 Date: Mon, 16 Jan 2023 23:45:38 +0100 Subject: [PATCH 36/47] Auto-detect vendor dir in GTest CMake Configuration --- test/gtest/CMakeLists.txt | 20 ++++++++++++++++---- test/gtest/check_glibc.c | 10 ++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/gtest/check_glibc.c diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index b0d7e21..915947c 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -26,12 +26,24 @@ target_link_libraries( GTest::gtest_main ) -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - target_link_libraries(c_v8_tests ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a) -else() - target_link_libraries(c_v8_tests ${CMAKE_SOURCE_DIR}/../../vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a) +string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name) +string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} system_arch) + +set(vendor_arch "${system_arch}-${system_name}") + +if(${system_name} STREQUAL "linux") + try_compile(is_glibc ${CMAKE_BINARY_DIR}/check_glibc ${CMAKE_SOURCE_DIR}/check_glibc.c) + if(NOT is_glibc) + # assume non-glibc is musl-libc + string(APPEND vendor_arch "-musl") + endif() endif() +message(STATUS "Detected vendor architecture directory: ${vendor_arch}") + +# TODO?: Detect and support ruby-arch builds? +target_link_libraries(c_v8_tests ${CMAKE_SOURCE_DIR}/../../vendor/v8/${vendor_arch}/libv8/obj/libv8_monolith.a) + # This has to be after the v8 monolith for some build setups. target_link_libraries(c_v8_tests dl) diff --git a/test/gtest/check_glibc.c b/test/gtest/check_glibc.c new file mode 100644 index 0000000..38e7e4b --- /dev/null +++ b/test/gtest/check_glibc.c @@ -0,0 +1,10 @@ +#warning "This is not a source file -- it exists purely to allow CMake to distinguish between glibc and musl-libc. If you see this message, you are likely doing something incorrectly." + +#include + +#ifndef __GLIBC__ +#error "__GLIBC__ is undef -- not glibc!" +#endif + +int main() { } + From d016d237ce9db4bfc1e31f080e7f6b9b73ee13bb Mon Sep 17 00:00:00 2001 From: Fayti1703 Date: Wed, 18 Jan 2023 00:23:40 +0100 Subject: [PATCH 37/47] Use pathed archives on Linux Alpine Linux's `ar` program doesn't support having objects with the same name in the archive twice, so we have to use the GNU extension for including paths. This commit *should* honestly be split into multiple separate commits, but unfortunately pretty much all of these changes have to be applied as a unit or a build step fails. --- libexec/build-monolith | 4 ++-- libexec/inject-libv8 | 31 +++++++++++++++++++++++++++++-- libexec/platform | 21 +++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/libexec/build-monolith b/libexec/build-monolith index 97d9f45..600697d 100755 --- a/libexec/build-monolith +++ b/libexec/build-monolith @@ -33,8 +33,8 @@ case "${platform}" in /usr/bin/ranlib "${LIBV8_MONOLITH}" ;; "Linux") - 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 -cqS "${LIBV8_MONOLITH}" - ranlib "${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}" diff --git a/libexec/inject-libv8 b/libexec/inject-libv8 index 353d4ed..2142e1e 100755 --- a/libexec/inject-libv8 +++ b/libexec/inject-libv8 @@ -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" diff --git a/libexec/platform b/libexec/platform index 582ec8b..91343aa 100755 --- a/libexec/platform +++ b/libexec/platform @@ -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}" @@ -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 @@ -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 < Date: Wed, 18 Jan 2023 17:01:49 +0100 Subject: [PATCH 38/47] Fix aarch64 cross-compile by dropping -msign-return-address on host --- libexec/build-libv8 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libexec/build-libv8 b/libexec/build-libv8 index 07bb500..c3303b9 100755 --- a/libexec/build-libv8 +++ b/libexec/build-libv8 @@ -38,5 +38,13 @@ ${CXX} -v 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 From 29c7341eddad454baa31f3a68f6807110f1054e1 Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Wed, 18 Jan 2023 17:27:42 +0000 Subject: [PATCH 39/47] skip arm64 c test on mac and lin --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40bc697..6c123de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -119,6 +119,7 @@ jobs: 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 @@ -257,6 +258,7 @@ jobs: 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 From 9a61bacb15561abb3751af00b57175f45e3fa11d Mon Sep 17 00:00:00 2001 From: seanmakesgames Date: Thu, 19 Jan 2023 05:58:14 +0000 Subject: [PATCH 40/47] 2.6 is EOL -- remove and bump --- .github/workflows/build.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c123de..f24a3d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -30,7 +30,7 @@ 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: Checkout uses: actions/checkout@v2 @@ -199,10 +199,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)" @@ -282,12 +282,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 @@ -380,7 +374,6 @@ jobs: fail-fast: false matrix: version: - - '2.6' - '2.7' - '3.0' - '3.1' @@ -394,9 +387,6 @@ jobs: - gnu - musl include: - - version: '2.6' - platform: 'arm64' - libc: 'gnu' - version: '2.7' platform: 'arm64' libc: 'gnu' From 97560d6854ac32d350e18fb7fb01c56dc7874ba5 Mon Sep 17 00:00:00 2001 From: Fayti1703 Date: Sun, 22 Jan 2023 15:16:12 +0100 Subject: [PATCH 41/47] Force ruby platform when testing ruby gem --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f24a3d9..61532cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -322,6 +322,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 v0.6.3 From 0d462cb0009c82537e30f13d1f1f1f434be05c56 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 24 Jan 2023 23:20:22 +0100 Subject: [PATCH 42/47] Use Ruby 2.7 in Makefile and Dockerfile --- Dockerfile | 2 +- Makefile.docker | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab7b567..c2a4057 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG RUBY_VERSION=2.4 +ARG RUBY_VERSION=2.7 FROM ruby:${RUBY_VERSION} RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar diff --git a/Makefile.docker b/Makefile.docker index 4739807..e66a188 100644 --- a/Makefile.docker +++ b/Makefile.docker @@ -21,19 +21,19 @@ test/linux: test/$(subst arm64,aarch64,$(CPU))-linux test/linux-musl: test/$(subst arm64,aarch64,$(CPU))-linux-musl pkg/libv8-node-$(VERSION)-x86_64-linux.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.7 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem: - docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.7-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ pkg/libv8-node-$(VERSION)-aarch64-linux.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.7 --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-gnu . docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-gnu cp $@ /pkg/ pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem: - docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . + docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.7-alpine --build-arg NODE_VERSION=$(NODE_VERSION) --progress plain -t libv8-node:$(VERSION)-musl . docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:$(VERSION)-musl cp $@ /pkg/ test/x86_64-linux: pkg/libv8-node-$(VERSION)-x86_64-linux.gem From f38ca6df883424e9228d20a711a4ab135163176a Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 24 Jan 2023 23:21:12 +0100 Subject: [PATCH 43/47] Use ccache in Dockerfile --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c2a4057..3585835 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ ARG RUBY_VERSION=2.7 FROM ruby:${RUBY_VERSION} -RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar +RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python3 git curl tar ccache +RUN test -f /etc/alpine-release || (apt-get update && apt-get install -y ccache) +ENV CCACHE_DIR=/ccache RUN mkdir -p /code WORKDIR /code @@ -16,7 +18,7 @@ COPY patch/* /code/patch/ RUN ./libexec/extract-node ${NODE_VERSION} COPY libexec/platform /code/libexec/ COPY libexec/build-libv8 /code/libexec/ -RUN ./libexec/build-libv8 ${NODE_VERSION} +RUN --mount=type=cache,id=ccache,target=/ccache/ ./libexec/build-libv8 ${NODE_VERSION} COPY libexec/build-monolith /code/libexec/ RUN ./libexec/build-monolith ${NODE_VERSION} COPY libexec/inject-libv8 /code/libexec/ From 0fad62766de5eb1321b7e298670842904e672e9c Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 24 Jan 2023 23:28:12 +0100 Subject: [PATCH 44/47] Pin Rubygems and Bundler --- .github/workflows/build.yml | 16 ++++++++++++++++ Dockerfile | 2 ++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36a2787..7fa2f35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,10 @@ jobs: runs-on: ubuntu-20.04 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 @@ -231,6 +235,10 @@ jobs: if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }} run: | 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 @@ -318,6 +326,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: | @@ -435,6 +447,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: | diff --git a/Dockerfile b/Dockerfile index 3585835..293af83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,8 @@ RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python3 RUN test -f /etc/alpine-release || (apt-get update && apt-get install -y ccache) ENV CCACHE_DIR=/ccache +RUN gem update --system 3.3.26 && gem install bundler -v '~> 2.3.26' + RUN mkdir -p /code WORKDIR /code From dcb3894a790b2e274c339553047780ddc06c2aa5 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Wed, 25 Jan 2023 02:51:46 +0100 Subject: [PATCH 45/47] Add Ruby 3.2 --- .github/workflows/build.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7fa2f35..d1a8d55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -318,6 +318,12 @@ jobs: - image: ruby:3.1-alpine version: '3.1' libc: musl + - image: ruby:3.2 + version: '3.2' + libc: gnu + - image: ruby:3.2-alpine + version: '3.2' + libc: musl name: Test (ruby) (${{ matrix.container.version }}, ${{ matrix.platform }}, ${{ matrix.container.libc }}) needs: build-ruby runs-on: ubuntu-20.04 @@ -400,6 +406,7 @@ jobs: - '2.7' - '3.0' - '3.1' + - '3.2' platform: - amd64 # arm64 @@ -419,6 +426,9 @@ jobs: - version: '3.1' platform: 'arm64' libc: 'gnu' + - version: '3.2' + platform: 'arm64' + libc: 'gnu' name: Test (linux) needs: build-linux runs-on: ubuntu-20.04 From 4db6396edce91a5c17224c7c41a4b514dea1c85e Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Wed, 25 Jan 2023 03:08:58 +0100 Subject: [PATCH 46/47] Fix and bump Rubocop --- .rubocop.yml | 6 ++++++ Rakefile | 8 ++------ ext/libv8-node/builder.rb | 2 +- ext/libv8-node/extconf.rb | 4 ++-- ext/libv8-node/location.rb | 2 +- libv8-node.gemspec | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a3ec089..e57f216 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,12 @@ AllCops: + SuggestExtensions: false + NewCops: disable TargetRubyVersion: 2.0 Exclude: - src/**/* - pkg/**/* - vendor/**/* + - test/**/* Naming/FileName: Exclude: @@ -26,3 +29,6 @@ Style/WordArray: Style/PerlBackrefs: Enabled: false + +Gemspec/RequiredRubyVersion: + Enabled: false diff --git a/Rakefile b/Rakefile index ade35ea..99467ee 100644 --- a/Rakefile +++ b/Rakefile @@ -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}" @@ -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}" diff --git a/ext/libv8-node/builder.rb b/ext/libv8-node/builder.rb index 84eae98..dab2771 100644 --- a/ext/libv8-node/builder.rb +++ b/ext/libv8-node/builder.rb @@ -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' diff --git a/ext/libv8-node/extconf.rb b/ext/libv8-node/extconf.rb index c2d97d3..31b9692 100644 --- a/ext/libv8-node/extconf.rb +++ b/ext/libv8-node/extconf.rb @@ -2,8 +2,8 @@ require 'mkmf' -if RUBY_ENGINE == "truffleruby" - File.write("Makefile", dummy_makefile($srcdir).join("")) +if RUBY_ENGINE == 'truffleruby' + File.write('Makefile', dummy_makefile($srcdir).join('')) # rubocop:disable Style/GlobalVars return end diff --git a/ext/libv8-node/location.rb b/ext/libv8-node/location.rb index 9b4cf68..07acff8 100644 --- a/ext/libv8-node/location.rb +++ b/ext/libv8-node/location.rb @@ -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 diff --git a/libv8-node.gemspec b/libv8-node.gemspec index 920f547..3c4f98b 100644 --- a/libv8-node.gemspec +++ b/libv8-node.gemspec @@ -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| @@ -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 From f6a5a865ee965a211a42509b5abc85967a56f960 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Sun, 30 Oct 2022 01:21:16 +0900 Subject: [PATCH 47/47] Fix Libv8::Node::Paths with RubyGems >=3.3.21 on *-linux-gnu platforms RubyGems 3.3.21 changed the value format of `Gem::Platform.local` for Ruby configured with `*-linux-gnu` as the platform name. ```console $ ruby -ve 'p Gem::VERSION; p Gem::Platform.local.to_s' ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux-gnu] "3.3.20" "x86_64-linux" $ ruby -ve 'p Gem::VERSION; p Gem::Platform.local.to_s' ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux-gnu] "3.3.21" "x86_64-linux-gnu" $ ruby -ve 'p Gem::VERSION; p Gem::Platform.local.to_s' ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux-gnu] "3.3.24" "x86_64-linux-gnu" ``` As you can see, it now has the `-gnu` prefix and `Libv8::Node::Paths.object_paths` thus has it when the built binary actually lives in the directory `x86_64-linux`, breaking the build of the gems like mini_racer on those platforms. [`RUBY_TARGET_PLATFORM` is set to `*-linux`](https://github.com/knu/libv8-node/blob/ad9105562185571f7b486f7770986f6a160318b2/libexec/platform#L28-L29), so `Libv8::Node::Paths.platform` needs to align with that. --- ext/libv8-node/paths.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/libv8-node/paths.rb b/ext/libv8-node/paths.rb index 469ad5f..0fe38cc 100644 --- a/ext/libv8-node/paths.rb +++ b/ext/libv8-node/paths.rb @@ -20,7 +20,7 @@ def object_paths end def platform - Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? && p.instance_eval { @version = 'musl' } }.to_s.gsub(/-darwin-?\d+/, '-darwin') + Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? && p.instance_eval { @version = 'musl' } }.to_s.sub(/-darwin\K-?\d+|-linux\K-gnu\z/, '') end def config