Skip to content

Commit 28224de

Browse files
committed
simple test to make sure v8 cgo is working
1 parent 9aeae08 commit 28224de

27 files changed

+14902
-22
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
*swp
22
.DS_Store
3+
4+
build
5+
.cipd
6+
.gclient_entries

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# v8go provides an API to v8 Javascript Engine

cgo.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package v8go
2+
3+
// #include <stdlib.h>
4+
//
5+
// #cgo CXXFLAGS: -fno-rtti -fpic -std=c++11 -I${SRCDIR}/deps/include
6+
// #cgo LDFLAGS: -pthread -lv8
7+
// #cgo darwin LDFLAGS: -L${SRCDIR}/deps/darwin-x86_64
8+
import "C"

deps/build.py

+25-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import platform
33
import os
44
import subprocess
5+
import shutil
56

67
deps_path = os.path.dirname(os.path.realpath(__file__))
78
v8_path = os.path.join(deps_path, "v8")
@@ -35,26 +36,25 @@
3536
]
3637

3738
gn_args = """
38-
is_component_build=false
39-
is_debug=false
40-
symbol_level=0
41-
strip_debug_info=true
42-
treat_warnings_as_errors=false
43-
use_custom_libcxx=false
44-
use_sysroot=false
45-
v8_deprecation_warnings=false
46-
v8_embedder_string="-v8worker2"
47-
v8_enable_gdbjit=false
48-
v8_enable_i18n_support=false
49-
v8_enable_test_features=false
50-
v8_extra_library_files=[]
51-
v8_imminent_deprecation_warnings=false
52-
v8_monolithic=true
53-
v8_static_library=true
54-
v8_target_cpu="x64"
55-
v8_untrusted_code_mitigations=false
56-
v8_use_external_startup_data=false
57-
v8_use_snapshot=true
39+
clang_use_chrome_plugins=false
40+
linux_use_bundled_binutils=false
41+
use_custom_libcxx=false
42+
use_sysroot=false
43+
is_debug=false
44+
symbol_level=0
45+
is_component_build=false
46+
v8_monolithic=true
47+
v8_static_library=true
48+
v8_use_external_startup_data=false
49+
treat_warnings_as_errors=false
50+
v8_embedder_string="-v8go"
51+
strip_debug_info=true
52+
v8_enable_gdbjit=false
53+
v8_enable_i18n_support=false
54+
v8_enable_test_features=false
55+
v8_extra_library_files=[]
56+
v8_untrusted_code_mitigations=false
57+
v8_use_snapshot=true
5858
"""
5959

6060
def v8deps():
@@ -87,5 +87,10 @@ def main():
8787
cwd=v8_path,
8888
env=env)
8989

90+
lib_fn = os.path.join(build_path, "obj/libv8_monolith.a")
91+
dest_fn = os.path.join(deps_path, os_arch(), 'libv8.a')
92+
shutil.copy(lib_fn, dest_fn)
93+
94+
9095
if __name__ == "__main__":
9196
main()

deps/depot_tools

Submodule depot_tools updated from 217195c to ee8d9ce
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
6+
#define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
7+
8+
#if defined(_WIN32)
9+
10+
#ifdef BUILDING_V8_PLATFORM_SHARED
11+
#define V8_PLATFORM_EXPORT __declspec(dllexport)
12+
#elif USING_V8_PLATFORM_SHARED
13+
#define V8_PLATFORM_EXPORT __declspec(dllimport)
14+
#else
15+
#define V8_PLATFORM_EXPORT
16+
#endif // BUILDING_V8_PLATFORM_SHARED
17+
18+
#else // defined(_WIN32)
19+
20+
// Setup for Linux shared library export.
21+
#ifdef BUILDING_V8_PLATFORM_SHARED
22+
#define V8_PLATFORM_EXPORT __attribute__((visibility("default")))
23+
#else
24+
#define V8_PLATFORM_EXPORT
25+
#endif
26+
27+
#endif // defined(_WIN32)
28+
29+
#endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2014 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
6+
#define V8_LIBPLATFORM_LIBPLATFORM_H_
7+
8+
#include "libplatform/libplatform-export.h"
9+
#include "libplatform/v8-tracing.h"
10+
#include "v8-platform.h" // NOLINT(build/include)
11+
#include "v8config.h" // NOLINT(build/include)
12+
13+
namespace v8 {
14+
namespace platform {
15+
16+
enum class IdleTaskSupport { kDisabled, kEnabled };
17+
enum class InProcessStackDumping { kDisabled, kEnabled };
18+
19+
enum class MessageLoopBehavior : bool {
20+
kDoNotWait = false,
21+
kWaitForWork = true
22+
};
23+
24+
/**
25+
* Returns a new instance of the default v8::Platform implementation.
26+
*
27+
* The caller will take ownership of the returned pointer. |thread_pool_size|
28+
* is the number of worker threads to allocate for background jobs. If a value
29+
* of zero is passed, a suitable default based on the current number of
30+
* processors online will be chosen.
31+
* If |idle_task_support| is enabled then the platform will accept idle
32+
* tasks (IdleTasksEnabled will return true) and will rely on the embedder
33+
* calling v8::platform::RunIdleTasks to process the idle tasks.
34+
* If |tracing_controller| is nullptr, the default platform will create a
35+
* v8::platform::TracingController instance and use it.
36+
*/
37+
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
38+
int thread_pool_size = 0,
39+
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
40+
InProcessStackDumping in_process_stack_dumping =
41+
InProcessStackDumping::kDisabled,
42+
std::unique_ptr<v8::TracingController> tracing_controller = {});
43+
44+
/**
45+
* Pumps the message loop for the given isolate.
46+
*
47+
* The caller has to make sure that this is called from the right thread.
48+
* Returns true if a task was executed, and false otherwise. Unless requested
49+
* through the |behavior| parameter, this call does not block if no task is
50+
* pending. The |platform| has to be created using |NewDefaultPlatform|.
51+
*/
52+
V8_PLATFORM_EXPORT bool PumpMessageLoop(
53+
v8::Platform* platform, v8::Isolate* isolate,
54+
MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);
55+
56+
/**
57+
* Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
58+
*
59+
* The caller has to make sure that this is called from the right thread.
60+
* This call does not block if no task is pending. The |platform| has to be
61+
* created using |NewDefaultPlatform|.
62+
*/
63+
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
64+
v8::Isolate* isolate,
65+
double idle_time_in_seconds);
66+
67+
/**
68+
* Attempts to set the tracing controller for the given platform.
69+
*
70+
* The |platform| has to be created using |NewDefaultPlatform|.
71+
*
72+
*/
73+
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
74+
"Access the DefaultPlatform directly",
75+
void SetTracingController(
76+
v8::Platform* platform,
77+
v8::platform::tracing::TracingController* tracing_controller));
78+
79+
} // namespace platform
80+
} // namespace v8
81+
82+
#endif // V8_LIBPLATFORM_LIBPLATFORM_H_

0 commit comments

Comments
 (0)