зеркало из https://github.com/microsoft/napajs.git
Added a script for building napa in embed mode (#47)
* Added a script for building napa in embed mode * Break embed build scripts into modules and combine with existing build.js
This commit is contained in:
Родитель
4f35004a96
Коммит
6ad7541395
|
@ -0,0 +1,10 @@
|
|||
:: Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
:: Licensed under the MIT license.
|
||||
@echo off
|
||||
|
||||
set NODE_EXE=%~dp0\node.exe
|
||||
if not exist "%NODE_EXE%" (
|
||||
set NODE_EXE=node
|
||||
)
|
||||
|
||||
%NODE_EXE% %~dp0\build.js %*
|
30
build.js
30
build.js
|
@ -1,4 +1,32 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
exports.paths = require('./scripts/paths');
|
||||
// Distinguish between running this file as a script or loading it as a module.
|
||||
if (module.parent) {
|
||||
// Loaded as a module - 'require('./build.js')
|
||||
exports.paths = require('./scripts/paths');
|
||||
}
|
||||
else {
|
||||
// Loaded as a script - 'node build.js'
|
||||
|
||||
// Remove first two parameters which are node executable and this javascript file.
|
||||
// Transform all parameters to lowercase for easier handling.
|
||||
let params = process.argv.slice(2).map((item) => item.toLowerCase());
|
||||
|
||||
// Specify wheater cleanup is needed.
|
||||
if (params.indexOf('clean') != -1) {
|
||||
require('./scripts/clean').clean();
|
||||
}
|
||||
|
||||
// Only build if embed was specified as a parameter.
|
||||
if (params.indexOf('embed') != -1) {
|
||||
let embedded = require('./scripts/embedded');
|
||||
|
||||
if (params.indexOf('debug') != -1) {
|
||||
embedded.build('debug');
|
||||
}
|
||||
else {
|
||||
embedded.build('release');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
"use strict";
|
||||
var fs = require('fs');
|
||||
var path = require("path");
|
||||
|
||||
exports.clean = function() {
|
||||
console.log('Cleaning up build files.');
|
||||
|
||||
// Remove build folder
|
||||
var buildDir = path.join(__dirname, "../build");
|
||||
console.log(`Removing ${buildDir}.`);
|
||||
removeDirectory(buildDir);
|
||||
|
||||
// Remove bin folder
|
||||
var binDir = path.join(__dirname, "../bin");
|
||||
console.log(`Removing ${binDir}.`);
|
||||
removeDirectory(binDir);
|
||||
}
|
||||
|
||||
// Helper function for removing all files from a directory.
|
||||
function removeDirectory(dirPath) {
|
||||
if (fs.existsSync(dirPath)) {
|
||||
fs.readdirSync(dirPath).forEach((file, index) => {
|
||||
var currentPath = dirPath + "/" + file;
|
||||
if (fs.lstatSync(currentPath).isDirectory()) {
|
||||
// Recursive call
|
||||
removeDirectory(currentPath);
|
||||
}
|
||||
else {
|
||||
// delete a file
|
||||
fs.unlinkSync(currentPath);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove the empty directory.
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
"use strict";
|
||||
var childProcess = require('child_process');
|
||||
var os = require("os");
|
||||
var path = require("path");
|
||||
|
||||
exports.build = function (buildType) {
|
||||
var napaRoot = path.join(__dirname, "..");
|
||||
var nodeVersion = "v6.10.3"; // Stable node version that can build as a dll.
|
||||
var nodeCloneRoot = path.join(napaRoot, "build/node-" + nodeVersion);
|
||||
|
||||
console.log("\x1b[1m\x1b[32m", `Building napa in embed mode (${buildType}) based on Node.JS ${nodeVersion}`,'\x1b[0m');
|
||||
|
||||
// Refer to https://github.com/nodejs/node/blob/master/BUILDING.md#windows-1 for prerequisites.
|
||||
childProcess.execSync(`git clone --branch ${nodeVersion} https://github.com/nodejs/node.git ${nodeCloneRoot}.`, {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
if (os.platform() === "win32") {
|
||||
console.log("\x1b[1m\x1b[32m", "Building Node.JS as dll.",'\x1b[0m');
|
||||
|
||||
// Build node shared library to extract intermediate v8 static libraries to build napa.dll.
|
||||
childProcess.execSync(`vcbuild.bat x64 ${buildType} nosign dll`, {
|
||||
cwd: nodeCloneRoot,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
}
|
||||
// TODO (asib): support other platforms
|
||||
|
||||
// Create platform specific build files using cmake.
|
||||
console.log("\x1b[1m\x1b[32m", "Running cmake to generate build files.",'\x1b[0m');
|
||||
childProcess.execSync(`cmake -A x64 -DNODE_ROOT=${nodeCloneRoot} -DCMAKE_BUILD_TYPE=${buildType} ..`, {
|
||||
cwd: path.join(napaRoot, "build"),
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
// Build.
|
||||
console.log("\x1b[1m\x1b[32m", "Building napa.",'\x1b[0m');
|
||||
childProcess.execSync(`cmake --build . --config ${buildType}`, {
|
||||
cwd: path.join(napaRoot, "build"),
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
// Install napa dependencies and compile typescript files..
|
||||
console.log("\x1b[1m\x1b[32m", "Running npm install to compile typescript files.",'\x1b[0m');
|
||||
childProcess.execSync("npm install --no-fetch --no-build", {
|
||||
cwd: napaRoot,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
}
|
|
@ -26,27 +26,50 @@ if (CMAKE_JS_VERSION)
|
|||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_JS_INC})
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_JS_LIB})
|
||||
|
||||
|
||||
# Using the V8 functions exported from node.exe
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE USING_V8_SHARED)
|
||||
else()
|
||||
# Building Napa for embed scenarios (static linking with v8)
|
||||
|
||||
if (NOT DEFINED V8_INC)
|
||||
message(FATAL_ERROR "V8_INC must be set to the v8 include directory")
|
||||
if (NOT DEFINED NODE_ROOT)
|
||||
message(FATAL_ERROR "NODE_ROOT must be set to the node sources root directory")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED V8_LIB_PATH)
|
||||
message(FATAL_ERROR "V8_LIB_PATH must be set to the v8 libraries directory")
|
||||
endif()
|
||||
|
||||
file(GLOB V8_LIBRARIES "${V8_LIB_PATH}/*.lib")
|
||||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${V8_INC})
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE ${V8_LIBRARIES})
|
||||
|
||||
# Using the V8 functions exported from node.exe
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE BUILDING_V8_SHARED)
|
||||
set(NODE_BUILD_TYPE "Release")
|
||||
if ((DEFINED CMAKE_BUILD_TYPE) AND (CMAKE_BUILD_TYPE STREQUAL "debug"))
|
||||
set(NODE_BUILD_TYPE "Debug")
|
||||
endif()
|
||||
|
||||
find_library(V8_BASE_0_LIBRARY NAMES v8_base_0 PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(V8_BASE_1_LIBRARY NAMES v8_base_1 PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(V8_BASE_2_LIBRARY NAMES v8_base_2 PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(V8_BASE_3_LIBRARY NAMES v8_base_3 PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(V8_LIBBASE_LIBRARY NAMES v8_libbase PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(V8_LIBPLATFORM_LIBRARY NAMES v8_libplatform PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(V8_NOSNAPSHOT_LIBRARY NAMES v8_nosnapshot PATHS ${NODE_ROOT}/build/${NODE_BUILD_TYPE}/lib)
|
||||
|
||||
find_library(ICUI18N_LIBRARY NAMES icui18n PATHS ${NODE_ROOT}/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(ICUSTUBDATA_LIBRARY NAMES icustubdata PATHS ${NODE_ROOT}/${NODE_BUILD_TYPE}/lib)
|
||||
find_library(ICUUCX_LIBRARY NAMES icuucx PATHS ${NODE_ROOT}/${NODE_BUILD_TYPE}/lib)
|
||||
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "/LTCG")
|
||||
|
||||
# V8 header files
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${NODE_ROOT}/deps/v8/include)
|
||||
|
||||
# V8 static libraries
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE
|
||||
${V8_BASE_0_LIBRARY}
|
||||
${V8_BASE_1_LIBRARY}
|
||||
${V8_BASE_2_LIBRARY}
|
||||
${V8_BASE_3_LIBRARY}
|
||||
${V8_LIBBASE_LIBRARY}
|
||||
${V8_LIBPLATFORM_LIBRARY}
|
||||
${V8_NOSNAPSHOT_LIBRARY}
|
||||
${ICUI18N_LIBRARY}
|
||||
${ICUSTUBDATA_LIBRARY}
|
||||
${ICUUCX_LIBRARY})
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
|
|
|
@ -218,7 +218,8 @@ template<class T, size_t N>
|
|||
constexpr size_t size(T(&)[N]) { return N; }
|
||||
|
||||
const char* napa_result_code_to_string(napa_result_code code) {
|
||||
NAPA_ASSERT(code < size(NAPA_REPONSE_CODE_STRINGS), "result code out of range");
|
||||
NAPA_ASSERT(code >= 0, "result code out of range (%d)", code);
|
||||
NAPA_ASSERT(static_cast<size_t>(code) < size(NAPA_REPONSE_CODE_STRINGS), "result code out of range (%d)", code);
|
||||
|
||||
return NAPA_REPONSE_CODE_STRINGS[code];
|
||||
}
|
||||
|
|
|
@ -61,8 +61,9 @@ namespace settings {
|
|||
bool ParseFromConsole(int argc, char* argv[], SettingsType& settings) {
|
||||
std::vector<std::string> args;
|
||||
|
||||
args.reserve(argc);
|
||||
for (auto i = 0; i < argc; i++) {
|
||||
// Skip first parameter (program name)
|
||||
args.reserve(argc - 1);
|
||||
for (auto i = 1; i < argc; i++) {
|
||||
args.emplace_back(argv[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,9 @@ TEST_CASE("Parsing nothing doesn't fail", "[settings-parser]") {
|
|||
settings::PlatformSettings settings;
|
||||
|
||||
REQUIRE(settings::ParseFromString("", settings));
|
||||
REQUIRE(settings::ParseFromConsole(0, nullptr, settings));
|
||||
|
||||
std::vector<char*> args = { "dummy.exe" };
|
||||
REQUIRE(settings::ParseFromConsole(static_cast<int>(args.size()), args.data(), settings));
|
||||
}
|
||||
|
||||
TEST_CASE("Parsing from string", "[settings-parser]") {
|
||||
|
@ -28,9 +30,9 @@ TEST_CASE("Parsing from console", "[settings-parser]") {
|
|||
settings::PlatformSettings settings;
|
||||
settings.loggingProvider = "";
|
||||
|
||||
std::vector<const char*> args = { "--loggingProvider", "myProvider" };
|
||||
std::vector<char*> args = { "dummy.exe", "--loggingProvider", "myProvider" };
|
||||
|
||||
REQUIRE(settings::ParseFromConsole(static_cast<int>(args.size()), const_cast<char**>(args.data()), settings));
|
||||
REQUIRE(settings::ParseFromConsole(static_cast<int>(args.size()), args.data(), settings));
|
||||
REQUIRE(settings.loggingProvider == "myProvider");
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче