Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add v8 #2067

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions recipes/v8/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/v8/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"8.2.49":
sha256: bf61bc7ffe556b30464ac0734e18d975fe6a8676d9c2fcb7c215981a46381847
url: https://github.com/bacnet-stack/bacnet-stack/archive/4a916468c63de478b84ef4d0c67d541cd84da27e.zip
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

115 changes: 115 additions & 0 deletions recipes/v8/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from conans import ConanFile, CMake, tools
import os
import shutil

class v8Conan(ConanFile):
name = "v8"
version = "8.2.49"
description = "Javascript Engine"
topics = ("javascript", "C++", "embedded", "google")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://v8.dev"
license = "MIT"
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"

build_requires = [# "depot_tools_installer/master@bincrafters/stable", # does not work, bc always outdated..
# "GN/master@inexorgame/testing", not needed, as its shipped with depot_tools
# "ninja_installer/1.8.2@bincrafters/stable", not needed, as its shipped with depot_tools
# "GNGenerator/0.1@inexorgame/testing" (so dependencies get picked up)
]

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def _set_environment_vars(self):
"""set the environment variables, such that the google tooling is found (including the bundled python2)"""
os.environ["PATH"] = os.path.join(self.source_folder, "depot_tools") + os.pathsep + os.environ["PATH"]
os.environ["DEPOT_TOOLS_PATH"] = os.path.join(self.source_folder, "depot_tools")
if tools.os_info.is_windows:
os.environ["DEPOT_TOOLS_WIN_TOOLCHAIN"] = "0"
if str(self.settings.compiler.version) not in ["15", "16"]:
raise ValueError("not yet supported visual studio version used for v8 build")
os.environ["GYP_MSVS_VERSION"] = "2017" if str(self.settings.compiler.version) == "15" else "2019"


def source(self):
self.run("git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git")
self._set_environment_vars()
self.run("gclient")
self.run("fetch v8")
with tools.chdir("v8"):
self.run("git checkout {}".format(self.version))

@staticmethod
def get_gn_profile(settings):
"""return the profile defined somewhere in v8/infra/mb/mb_config.pyl which corresponds "nearly" to the one we need.. "nearly" as in "not even remotely"..
"""
return "{arch}.{build_type}".format(build_type=str(settings.build_type).lower(),
arch="x64" if str(settings.arch) == "x86_64" else "x86")

def _install_system_requirements_linux(self):
"""some extra script must be executed on linux"""
os.environ["PATH"] += os.pathsep + os.path.join(self.source_folder, "depot_tools")
self.run("chmod +x v8/build/install-build-deps.sh")
#self.run("v8/build/install-build-deps.sh --unsupported --no-arm --no-nacl "
# "--no-backwards-compatible --no-chromeos-fonts --no-prompt "
# + "--syms" if str(self.settings.build_type) == "Debug" else "--no-syms")

def build(self):
self._set_environment_vars()

if tools.os_info.is_linux:
self._install_system_requirements_linux()

# fix gn always detecting the runtime on its own:
if str(self.settings.compiler) == "Visual Studio" and str(self.settings.compiler.runtime) in ["MD", "MDd"]:
build_gn_file = os.path.join("v8", "build", "config", "win", "BUILD.gn")
print("replacing MT / MTd with MD / MDd in gn file." + build_gn_file)
tools.replace_in_file(file_path=build_gn_file, search="MT", replace="MD")

with tools.chdir("v8"):
arguments = ["v8_monolithic = true",
"is_component_build = false",
"v8_static_library = true",
"treat_warnings_as_errors = false",
"v8_use_external_startup_data = false",
"v8_enable_i18n_support = true"
]
# v8_enable_backtrace=false,

if tools.os_info.is_linux:
arguments += ["use_sysroot = false",
"use_custom_libcxx = false",
"use_custom_libcxx_for_host = false",
"use_glib = false",
"is_clang = " + ( "true" if "clang" in str(self.settings.compiler).lower() else "false" ) ]

generator_call = 'gn gen out.gn/x64.release --args="{gn_args}"'.format(profile=self.get_gn_profile(self.settings),
gn_args=" ".join(arguments))
# maybe todo: absolute path..
if tools.os_info.is_windows:
# this is picking up the python shipped via depot_tools, since we got it in the path.
generator_call = "python " + generator_call
self.run("python --version")
self.run(generator_call)
self.run("ninja -C out.gn/{profile} v8_monolith".format(profile=self.get_gn_profile(self.settings)))


def package(self):
self.copy(pattern="LICENSE*", dst="licenses", src="v8")
self.copy(pattern="*v8_monolith.a", dst="lib", keep_path=False)
self.copy(pattern="*v8_monolith.lib", dst="lib", keep_path=False)
self.copy(pattern="*.h", dst="include", src="v8/include", keep_path=True)


def package_info(self):
# fix issue on Windows and OSx not finding the KHR files
# self.cpp_info.includedirs.append(os.path.join("include", "MagnumExternal", "OpenGL"))
# builtLibs = tools.collect_libs(self)
self.cpp_info.libs = ["v8_monolith"] # sort_libs(correct_order=allLibs, libs=builtLibs, lib_suffix=suffix, reverse_result=True)
9 changes: 9 additions & 0 deletions recipes/v8/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 2.8.11)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
18 changes: 18 additions & 0 deletions recipes/v8/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

from conans import ConanFile, CMake, tools


class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
bin_path = self.run(bin_path, run_environment=True)
50 changes: 50 additions & 0 deletions recipes/v8/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 "include/libplatform/libplatform.h"
#include "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);
}
// Dispose the isolate and tear down V8.
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete create_params.array_buffer_allocator;
return 0;
}
4 changes: 4 additions & 0 deletions recipes/v8/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
versions:
"8.2.49":
folder: "all"