forked from ruslo/hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) 2016-2019, Ruslan Baratov | ||
# All rights reserved. | ||
|
||
# !!! DO NOT PLACE HEADER GUARDS HERE !!! | ||
|
||
include(hunter_add_version) | ||
include(hunter_cacheable) | ||
include(hunter_download) | ||
include(hunter_pick_scheme) | ||
|
||
hunter_add_version( | ||
PACKAGE_NAME | ||
v8 | ||
VERSION | ||
7.4.98-p1 | ||
URL | ||
"https://github.com/hunter-packages/v8/archive/v7.4.98-p1.tar.gz" | ||
SHA1 | ||
44805a2abbfc65fa73dbbfaa0383135dae9d05af | ||
) | ||
|
||
hunter_pick_scheme(DEFAULT url_sha1_cmake) | ||
hunter_cacheable(v8) | ||
hunter_download(PACKAGE_NAME v8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. spelling:: | ||
|
||
v8 | ||
|
||
.. index:: | ||
single: unsorted ; v8 | ||
|
||
.. _pkg.v8: | ||
|
||
v8 | ||
== | ||
|
||
- https://v8.dev/ | ||
- `Official GitHub <https://github.com/v8/v8>`__ | ||
- `Hunterized <https://github.com/hunter-packages/v8>`__ | ||
- `Example <https://github.com/ruslo/hunter/blob/master/examples/v8/CMakeLists.txt>`__ | ||
|
||
.. literalinclude:: /../examples/v8/CMakeLists.txt | ||
:language: cmake | ||
:start-after: # DOCUMENTATION_START { | ||
:end-before: # DOCUMENTATION_END } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) 2016-2018, Ruslan Baratov | ||
# All rights reserved. | ||
|
||
cmake_minimum_required(VERSION 3.2) | ||
|
||
# Emulate HunterGate: | ||
# * https://github.com/hunter-packages/gate | ||
include("../common.cmake") | ||
|
||
project(download-v8) | ||
|
||
# DOCUMENTATION_START { | ||
hunter_add_package(v8) | ||
find_package(v8 CONFIG REQUIRED) | ||
|
||
add_executable(boo boo.cpp) | ||
target_link_libraries(boo PUBLIC v8::v8_libplatform v8::v8_base) | ||
# DOCUMENTATION_END } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright 2015 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. | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <libplatform/libplatform.h> | ||
#include <v8.h> | ||
|
||
int main(int argc, char* argv[]) { | ||
// Initialize V8. | ||
v8::V8::InitializeICUDefaultLocation(argv[0]); | ||
v8::V8::InitializeExternalStartupData(argv[0]); | ||
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform(); | ||
v8::V8::InitializePlatform(platform.get()); | ||
v8::V8::Initialize(); | ||
|
||
// Create a new Isolate and make it the current one. | ||
v8::Isolate::CreateParams create_params; | ||
|
||
create_params.array_buffer_allocator = | ||
v8::ArrayBuffer::Allocator::NewDefaultAllocator(); | ||
v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
{ | ||
v8::Isolate::Scope isolate_scope(isolate); | ||
|
||
// Create a stack-allocated handle scope. | ||
v8::HandleScope handle_scope(isolate); | ||
|
||
// Create a new context. | ||
v8::Local<v8::Context> context = v8::Context::New(isolate); | ||
|
||
// Enter the context for compiling and running the hello world script. | ||
v8::Context::Scope context_scope(context); | ||
|
||
{ | ||
// Create a string containing the JavaScript source code. | ||
v8::Local<v8::String> source = | ||
v8::String::NewFromUtf8(isolate, "'Hello' + ', World!'", | ||
v8::NewStringType::kNormal) | ||
.ToLocalChecked(); | ||
|
||
// Compile the source code. | ||
v8::Local<v8::Script> script = | ||
v8::Script::Compile(context, source).ToLocalChecked(); | ||
|
||
// Run the script to get the result. | ||
v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); | ||
|
||
// Convert the result to an UTF8 string and print it. | ||
v8::String::Utf8Value utf8(isolate, result); | ||
printf("%s\n", *utf8); | ||
} | ||
|
||
{ | ||
// Use the JavaScript API to generate a WebAssembly module. | ||
// | ||
// |bytes| contains the binary format for the following module: | ||
// | ||
// (func (export "add") (param i32 i32) (result i32) | ||
// get_local 0 | ||
// get_local 1 | ||
// i32.add) | ||
// | ||
const char* csource = R"( | ||
let bytes = new Uint8Array([ | ||
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, | ||
0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, | ||
0x07, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01, | ||
0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b | ||
]); | ||
let module = new WebAssembly.Module(bytes); | ||
let instance = new WebAssembly.Instance(module); | ||
instance.exports.add(3, 4); | ||
)"; | ||
|
||
// Create a string containing the JavaScript source code. | ||
v8::Local<v8::String> source = | ||
v8::String::NewFromUtf8(isolate, csource, v8::NewStringType::kNormal) | ||
.ToLocalChecked(); | ||
|
||
// Compile the source code. | ||
v8::Local<v8::Script> script = | ||
v8::Script::Compile(context, source).ToLocalChecked(); | ||
|
||
// Run the script to get the result. | ||
v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); | ||
|
||
// Convert the result to a uint32 and print it. | ||
uint32_t number = result->Uint32Value(context).ToChecked(); | ||
printf("3 + 4 = %u\n", number); | ||
} | ||
} | ||
|
||
// Dispose the isolate and tear down V8. | ||
isolate->Dispose(); | ||
v8::V8::Dispose(); | ||
v8::V8::ShutdownPlatform(); | ||
delete create_params.array_buffer_allocator; | ||
return 0; | ||
} |