Skip to content

Commit

Permalink
simple test to make sure v8 cgo is working
Browse files Browse the repository at this point in the history
  • Loading branch information
rogchap committed Aug 29, 2019
1 parent 9aeae08 commit 28224de
Show file tree
Hide file tree
Showing 27 changed files with 14,902 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*swp
.DS_Store

build
.cipd
.gclient_entries
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# v8go provides an API to v8 Javascript Engine
8 changes: 8 additions & 0 deletions cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package v8go

// #include <stdlib.h>
//
// #cgo CXXFLAGS: -fno-rtti -fpic -std=c++11 -I${SRCDIR}/deps/include
// #cgo LDFLAGS: -pthread -lv8
// #cgo darwin LDFLAGS: -L${SRCDIR}/deps/darwin-x86_64
import "C"
45 changes: 25 additions & 20 deletions deps/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
import os
import subprocess
import shutil

deps_path = os.path.dirname(os.path.realpath(__file__))
v8_path = os.path.join(deps_path, "v8")
Expand Down Expand Up @@ -35,26 +36,25 @@
]

gn_args = """
is_component_build=false
is_debug=false
symbol_level=0
strip_debug_info=true
treat_warnings_as_errors=false
use_custom_libcxx=false
use_sysroot=false
v8_deprecation_warnings=false
v8_embedder_string="-v8worker2"
v8_enable_gdbjit=false
v8_enable_i18n_support=false
v8_enable_test_features=false
v8_extra_library_files=[]
v8_imminent_deprecation_warnings=false
v8_monolithic=true
v8_static_library=true
v8_target_cpu="x64"
v8_untrusted_code_mitigations=false
v8_use_external_startup_data=false
v8_use_snapshot=true
clang_use_chrome_plugins=false
linux_use_bundled_binutils=false
use_custom_libcxx=false
use_sysroot=false
is_debug=false
symbol_level=0
is_component_build=false
v8_monolithic=true
v8_static_library=true
v8_use_external_startup_data=false
treat_warnings_as_errors=false
v8_embedder_string="-v8go"
strip_debug_info=true
v8_enable_gdbjit=false
v8_enable_i18n_support=false
v8_enable_test_features=false
v8_extra_library_files=[]
v8_untrusted_code_mitigations=false
v8_use_snapshot=true
"""

def v8deps():
Expand Down Expand Up @@ -87,5 +87,10 @@ def main():
cwd=v8_path,
env=env)

lib_fn = os.path.join(build_path, "obj/libv8_monolith.a")
dest_fn = os.path.join(deps_path, os_arch(), 'libv8.a')
shutil.copy(lib_fn, dest_fn)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion deps/depot_tools
Submodule depot_tools updated from 217195 to ee8d9c
29 changes: 29 additions & 0 deletions deps/include/libplatform/libplatform-export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
#define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_

#if defined(_WIN32)

#ifdef BUILDING_V8_PLATFORM_SHARED
#define V8_PLATFORM_EXPORT __declspec(dllexport)
#elif USING_V8_PLATFORM_SHARED
#define V8_PLATFORM_EXPORT __declspec(dllimport)
#else
#define V8_PLATFORM_EXPORT
#endif // BUILDING_V8_PLATFORM_SHARED

#else // defined(_WIN32)

// Setup for Linux shared library export.
#ifdef BUILDING_V8_PLATFORM_SHARED
#define V8_PLATFORM_EXPORT __attribute__((visibility("default")))
#else
#define V8_PLATFORM_EXPORT
#endif

#endif // defined(_WIN32)

#endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
82 changes: 82 additions & 0 deletions deps/include/libplatform/libplatform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
#define V8_LIBPLATFORM_LIBPLATFORM_H_

#include "libplatform/libplatform-export.h"
#include "libplatform/v8-tracing.h"
#include "v8-platform.h" // NOLINT(build/include)
#include "v8config.h" // NOLINT(build/include)

namespace v8 {
namespace platform {

enum class IdleTaskSupport { kDisabled, kEnabled };
enum class InProcessStackDumping { kDisabled, kEnabled };

enum class MessageLoopBehavior : bool {
kDoNotWait = false,
kWaitForWork = true
};

/**
* Returns a new instance of the default v8::Platform implementation.
*
* The caller will take ownership of the returned pointer. |thread_pool_size|
* is the number of worker threads to allocate for background jobs. If a value
* of zero is passed, a suitable default based on the current number of
* processors online will be chosen.
* If |idle_task_support| is enabled then the platform will accept idle
* tasks (IdleTasksEnabled will return true) and will rely on the embedder
* calling v8::platform::RunIdleTasks to process the idle tasks.
* If |tracing_controller| is nullptr, the default platform will create a
* v8::platform::TracingController instance and use it.
*/
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
int thread_pool_size = 0,
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
InProcessStackDumping in_process_stack_dumping =
InProcessStackDumping::kDisabled,
std::unique_ptr<v8::TracingController> tracing_controller = {});

/**
* Pumps the message loop for the given isolate.
*
* The caller has to make sure that this is called from the right thread.
* Returns true if a task was executed, and false otherwise. Unless requested
* through the |behavior| parameter, this call does not block if no task is
* pending. The |platform| has to be created using |NewDefaultPlatform|.
*/
V8_PLATFORM_EXPORT bool PumpMessageLoop(
v8::Platform* platform, v8::Isolate* isolate,
MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);

/**
* Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
*
* The caller has to make sure that this is called from the right thread.
* This call does not block if no task is pending. The |platform| has to be
* created using |NewDefaultPlatform|.
*/
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
v8::Isolate* isolate,
double idle_time_in_seconds);

/**
* Attempts to set the tracing controller for the given platform.
*
* The |platform| has to be created using |NewDefaultPlatform|.
*
*/
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
"Access the DefaultPlatform directly",
void SetTracingController(
v8::Platform* platform,
v8::platform::tracing::TracingController* tracing_controller));

} // namespace platform
} // namespace v8

#endif // V8_LIBPLATFORM_LIBPLATFORM_H_
Loading

0 comments on commit 28224de

Please sign in to comment.