Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into gl-icudata
Browse files Browse the repository at this point in the history
  • Loading branch information
Genevieve L'Esperance committed Nov 3, 2021
2 parents 85a9e13 + 24e3ca7 commit b2bb68f
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 61 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ jobs:
name: Tests on ${{ matrix.go-version }} ${{ matrix.platform }}
strategy:
matrix:
go-version: [1.12.17, 1.16.4]
platform: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.16.8, 1.17.1]
# We use macos-11 over macos-latest because macos-latest defaults to Catalina(10.15) and not Big Sur(11.0)
# We can switch to macos-latest whenever Big Sur becomes the default
# See https://github.com/actions/virtual-environments#available-environments
# platform: [ubuntu-latest, macos-11, windows-latest]
platform: [ubuntu-latest, macos-11]
runs-on: ${{ matrix.platform }}

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout
uses: actions/checkout@v2
- name: Add MINGW to PATH
if: matrix.platform == 'windows-latest'
run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
shell: bash
# - name: Add MINGW to PATH
# if: matrix.platform == 'windows-latest'
# run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
# shell: bash
- name: Go Test
run: go test -v -coverprofile c.out ./...
- name: Upload coverage to Codecov
Expand Down
62 changes: 34 additions & 28 deletions .github/workflows/v8build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ on: workflow_dispatch

jobs:
build:
name: Build V8 for ${{ matrix.platform }}
name: Build V8 for ${{ matrix.platform }} ${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-18.04, macos-latest, windows-latest]
# We use macos-11 over macos-latest because macos-latest defaults to Catalina(10.15) and not Big Sur(11.0)
# We can switch to macos-latest whenever Big Sur becomes the default
# See https://github.com/actions/virtual-environments#available-environments
#
# We need xcode 12.4 or newer to cross compile between arm64/amd64
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
# platform: [ubuntu-18.04, macos-11, windows-latest]
platform: [ubuntu-18.04, macos-11]
arch: [x86_64, arm64]
exclude:
- platform: ubuntu-18.04
arch: arm64
# - platform: windows-latest
# arch: arm64
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
Expand All @@ -19,34 +32,27 @@ jobs:
- name: Update depot_tools fetch config
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
shell: bash
# - name: Build V8 linux
# if: matrix.platform == 'ubuntu-18.04'
# run: cd deps && ./build.py --no-clang
# - name: Build V8 macOS
# if: matrix.platform == 'macos-latest'
# run: cd deps && ./build.py
- name: Add MSYS2 to PATH
if: matrix.platform == 'windows-latest'
run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
shell: bash
- name: Run python2 for windows
if: matrix.platform == 'windows-latest'
uses: actions/setup-python@v2
with:
python-version: '2.x'
- name: Build V8 windows
if: matrix.platform == 'windows-latest'
run: cd deps; python build.py --no-clang
env:
MSYSTEM: MINGW64
DEPOT_TOOLS_WIN_TOOLCHAIN: 0
- name: Build V8 linux
if: matrix.platform == 'ubuntu-18.04'
run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }}
- name: Build V8 macOS
if: matrix.platform == 'macos-11'
run: cd deps && ./build.py --arch ${{ matrix.arch }}
# - name: Add MSYS2 to PATH
# if: matrix.platform == 'windows-latest'
# run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
# shell: bash
# - name: Build V8 windows
# if: matrix.platform == 'windows-latest'
# run: cd deps; python build.py --no-clang --arch ${{ matrix.arch }}
# env:
# MSYSTEM: MINGW64
# DEPOT_TOOLS_WIN_TOOLCHAIN: 0
- name: Create PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update V8 static library for ${{ matrix.platform }}
branch: v8-lib
commit-message: Update V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
branch-suffix: random
delete-branch: true
title: V8 static library for ${{ matrix.platform }}
body: Auto-generated pull request to build V8 for ${{ matrix.platform }}

title: V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
body: Auto-generated pull request to build V8 for ${{ matrix.platform }} ${{ matrix.arch }}
2 changes: 0 additions & 2 deletions .github/workflows/v8upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ jobs:
delete-branch: true
title: ${{steps.pr_metadata.outputs.pr_commit_message}}
body: ${{steps.pr_metadata.outputs.pr_body}}


1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for calling `IsExecutionTerminating` on isolate to check if execution is still terminating.
- Support for setting and getting internal fields for template object instances
- Support for CPU profiling
- Add V8 build for Apple Silicon

### Changed
- Removed error return value from NewIsolate which never fails
Expand Down
4 changes: 3 additions & 1 deletion cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ package v8go

// #cgo CXXFLAGS: -fno-rtti -fpic -std=c++14 -DV8_COMPRESS_POINTERS -DV8_31BIT_SMIS_ON_64BIT_ARCH -I${SRCDIR}/deps/include
// #cgo LDFLAGS: -pthread -lv8
// #cgo darwin LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64
// #cgo linux LDFLAGS: -L${SRCDIR}/deps/linux_x86_64
// #cgo windows LDFLAGS: -L${SRCDIR}/deps/windows_x86_64 -static -ldbghelp -lssp -lwinmm -lz
import "C"
Expand All @@ -17,6 +18,7 @@ import "C"
// contain V8 libraries and headers which otherwise would be ignored.
// DO NOT REMOVE
import (
_ "rogchap.com/v8go/deps/darwin_arm64"
_ "rogchap.com/v8go/deps/darwin_x86_64"
_ "rogchap.com/v8go/deps/include"
_ "rogchap.com/v8go/deps/linux_x86_64"
Expand Down
29 changes: 24 additions & 5 deletions deps/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
import shutil
import argparse

valid_archs = ['arm64', 'x86_64']
# "x86_64" is called "amd64" on Windows
current_arch = platform.uname()[4].lower().replace("amd64", "x86_64")
default_arch = current_arch if current_arch in valid_archs else None

parser = argparse.ArgumentParser()
parser.add_argument('--debug', dest='debug', action='store_true')
parser.add_argument('--no-clang', dest='clang', action='store_false')
parser.add_argument('--arch',
dest='arch',
action='store',
choices=valid_archs,
default=default_arch,
required=default_arch is None)
parser.set_defaults(debug=False, clang=True)
args = parser.parse_args()

Expand Down Expand Up @@ -40,6 +51,8 @@
gn_args = """
is_debug=%s
is_clang=%s
target_cpu="%s"
v8_target_cpu="%s"
clang_use_chrome_plugins=false
use_custom_libcxx=false
use_sysroot=false
Expand Down Expand Up @@ -71,8 +84,12 @@ def cmd(args):

def os_arch():
u = platform.uname()
# "x86_64" is called "amd64" on Windows
return (u[0] + "_" + u[4]).lower().replace("amd64", "x86_64")
return u[0].lower() + "_" + args.arch

def v8_arch():
if args.arch == "x86_64":
return "x64"
return args.arch

def apply_mingw_patches():
v8_build_path = os.path.join(v8_path, "build")
Expand Down Expand Up @@ -103,7 +120,7 @@ def main():
v8deps()
if is_windows:
apply_mingw_patches()

gn_path = os.path.join(tools_path, "gn")
assert(os.path.exists(gn_path))
ninja_path = os.path.join(tools_path, "ninja" + (".exe" if is_windows else ""))
Expand All @@ -119,9 +136,11 @@ def main():
# compiled library by an order of magnitude and further slow down compilation
symbol_level = 1 if args.debug else 0
strip_debug_info = 'false' if args.debug else 'true'
gnargs = gn_args % (is_debug, is_clang, symbol_level, strip_debug_info)

arch = v8_arch()
gnargs = gn_args % (is_debug, is_clang, arch, arch, symbol_level, strip_debug_info)
gen_args = gnargs.replace('\n', ' ')

subprocess.check_call(cmd([gn_path, "gen", build_path, "--args=" + gen_args]),
cwd=v8_path,
env=env)
Expand Down
Binary file added deps/darwin_arm64/libv8.a
Binary file not shown.
3 changes: 3 additions & 0 deletions deps/darwin_arm64/vendor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package darwin_arm64 is required to provide support for vendoring modules
// DO NOT REMOVE
package darwin_arm64
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module rogchap.com/v8go

go 1.12
go 1.16
34 changes: 20 additions & 14 deletions v8go.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ void CPUProfilerStartProfiling(CPUProfiler* profiler, const char* title) {
Isolate::Scope isolate_scope(profiler->iso);
HandleScope handle_scope(profiler->iso);

Local<String> title_str = String::NewFromUtf8(profiler->iso, title, NewStringType::kNormal).ToLocalChecked();
Local<String> title_str =
String::NewFromUtf8(profiler->iso, title, NewStringType::kNormal)
.ToLocalChecked();
profiler->ptr->StartProfiling(title_str);
}

Expand All @@ -242,13 +244,13 @@ CPUProfileNode* NewCPUProfileNode(const CpuProfileNode* ptr_) {
}

CPUProfileNode* root = new CPUProfileNode{
ptr_,
ptr_->GetScriptResourceNameStr(),
ptr_->GetFunctionNameStr(),
ptr_->GetLineNumber(),
ptr_->GetColumnNumber(),
count,
children,
ptr_,
ptr_->GetScriptResourceNameStr(),
ptr_->GetFunctionNameStr(),
ptr_->GetLineNumber(),
ptr_->GetColumnNumber(),
count,
children,
};
return root;
}
Expand All @@ -263,7 +265,8 @@ CPUProfile* CPUProfilerStopProfiling(CPUProfiler* profiler, const char* title) {
HandleScope handle_scope(profiler->iso);

Local<String> title_str =
String::NewFromUtf8(profiler->iso, title, NewStringType::kNormal).ToLocalChecked();
String::NewFromUtf8(profiler->iso, title, NewStringType::kNormal)
.ToLocalChecked();

CPUProfile* profile = new CPUProfile;
profile->ptr = profiler->ptr->StopProfiling(title_str);
Expand All @@ -286,6 +289,7 @@ void CPUProfileNodeDelete(CPUProfileNode* node) {
CPUProfileNodeDelete(node->children[i]);
}

delete[] node->children;
delete node;
}

Expand All @@ -294,6 +298,7 @@ void CPUProfileDelete(CPUProfile* profile) {
return;
}
profile->ptr->Delete();
free((void*)profile->title);

CPUProfileNodeDelete(profile->root);

Expand Down Expand Up @@ -372,7 +377,8 @@ RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx) {
return rtn;
}

void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr, uint32_t field_count) {
void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr,
uint32_t field_count) {
LOCAL_TEMPLATE(ptr);

Local<ObjectTemplate> obj_tmpl = tmpl.As<ObjectTemplate>();
Expand Down Expand Up @@ -776,7 +782,7 @@ const uint32_t* ValueToArrayIndex(ValuePtr ptr) {
return nullptr;
}

uint32_t* idx = new uint32_t;
uint32_t* idx = (uint32_t*)malloc(sizeof(uint32_t));
*idx = array_index->Value();
return idx;
}
Expand Down Expand Up @@ -838,7 +844,7 @@ ValueBigInt ValueToBigInt(ValuePtr ptr) {

int word_count = bint->WordCount();
int sign_bit = 0;
uint64_t* words = new uint64_t[word_count];
uint64_t* words = (uint64_t*)malloc(sizeof(uint64_t) * word_count);
bint->ToWordsArray(&sign_bit, &word_count, words);
ValueBigInt rtn = {words, word_count, sign_bit};
return rtn;
Expand Down Expand Up @@ -1212,8 +1218,8 @@ ValuePtr ObjectGetInternalField(ValuePtr ptr, uint32_t idx) {
m_value* new_val = new m_value;
new_val->iso = iso;
new_val->ctx = ctx;
new_val->ptr = Persistent<Value, CopyablePersistentTraits<Value>>(
iso, result);
new_val->ptr =
Persistent<Value, CopyablePersistentTraits<Value>>(iso, result);

return tracked_value(ctx, new_val);
}
Expand Down
8 changes: 5 additions & 3 deletions v8go.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct _EXCEPTION_POINTERS;
#endif

#include "libplatform/libplatform.h"
#include "v8.h"
#include "v8-profiler.h"
#include "v8.h"

typedef v8::Isolate* IsolatePtr;
typedef v8::CpuProfiler* CpuProfilerPtr;
Expand Down Expand Up @@ -117,7 +117,8 @@ extern IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr ptr);
extern CPUProfiler* NewCPUProfiler(IsolatePtr iso_ptr);
extern void CPUProfilerDispose(CPUProfiler* ptr);
extern void CPUProfilerStartProfiling(CPUProfiler* ptr, const char* title);
extern CPUProfile* CPUProfilerStopProfiling(CPUProfiler* ptr, const char* title);
extern CPUProfile* CPUProfilerStopProfiling(CPUProfiler* ptr,
const char* title);
extern void CPUProfileDelete(CPUProfile* ptr);

extern ContextPtr NewContext(IsolatePtr iso_ptr,
Expand All @@ -143,7 +144,8 @@ extern void TemplateSetTemplate(TemplatePtr ptr,

extern TemplatePtr NewObjectTemplate(IsolatePtr iso_ptr);
extern RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx_ptr);
extern void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr, uint32_t field_count);
extern void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr,
uint32_t field_count);
extern int ObjectTemplateInternalFieldCount(TemplatePtr ptr);

extern TemplatePtr NewFunctionTemplate(IsolatePtr iso_ptr, int callback_ref);
Expand Down

0 comments on commit b2bb68f

Please sign in to comment.