Skip to content

Commit

Permalink
internal: add node-embedder-api port (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Sep 19, 2024
1 parent aa958c1 commit 61dc135
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/actions/pr_base/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ runs:
$cmake_command_full += "$vcpkg_triplet_arg "
$cmake_command_full += "$vcpkg_root_arg "
$cmake_command_full += "-DUNIT_DATA_DIR=skyrim_data_files "
$cmake_command_full += "-DBUILD_NODEJS_PLUGIN=ON "
$cmake_command_full += "$prepare_nexus_archives_arg "
$cmake_command_full += "-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} "
$cmake_command_full += "-DSKYRIM_SE=${{ inputs.SKYRIM_SE_FLAG }} "
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ if(NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}/build")
message(FATAL_ERROR "${msg}")
endif()

# Bool options (Part 1)
option(SKYRIM_SE "Legacy Skyrim SE (1.5) build" OFF)
option(BUILD_NODEJS_PLUGIN "Build a NodeJS plugin for Skyrim if ON, use a pre-built from ./client-deps otherwise" OFF)

if(SKYRIM_SE)
list(APPEND VCPKG_MANIFEST_FEATURES "skyrim-se")
else()
list(APPEND VCPKG_MANIFEST_FEATURES "skyrim-ae")
endif()

if(BUILD_NODEJS_PLUGIN)
list(APPEND VCPKG_MANIFEST_FEATURES "build-nodejs")
endif()

cmake_minimum_required(VERSION 3.19)
project(skymp)
enable_testing()
Expand All @@ -74,7 +80,7 @@ if(MSVC)
endif()
endif()

# Bool options
# Bool options (Part 2)
option(JS_ENGINE_TRACING_ENABLED "Useful for JsEngine debugging. See JsEngine.h" OFF)
option(PREPARE_NEXUS_ARCHIVES "Prepare SP and other archives during build or not" OFF)
option(BUILD_UNIT_TESTS "Build unit tests (excluded from build when off - workaround for #1182)" ON)
Expand All @@ -89,6 +95,7 @@ message(STATUS BUILD_UNIT_TESTS=${BUILD_UNIT_TESTS})
message(STATUS INSTALL_CLIENT_DIST=${INSTALL_CLIENT_DIST})
message(STATUS BUILD_GAMEMODE=${BUILD_GAMEMODE})
message(STATUS OFFLINE_MODE=${OFFLINE_MODE})
message(STATUS BUILD_NODEJS_PLUGIN=${BUILD_NODEJS_PLUGIN})

if(PREPARE_NEXUS_ARCHIVES AND EMSCRIPTEN)
message(FATAL_ERROR "PREPARE_NEXUS_ARCHIVES is not supported on Emscripten")
Expand Down
169 changes: 169 additions & 0 deletions overlay_ports/node-embedder-api/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nodejs/node
REF "v${VERSION}"
SHA512 cb88b3576ac810ceace7d5824d5a6e1c4181a9327f1420d6eb1546a03a22f5f80bdddcbef6bc478ce4cb62dcd724b7a04eda707845a4003b96a5d6aed5463b37
HEAD_REF main
)

# Fixes arm64-windows host building x64-windows target
vcpkg_replace_string("${SOURCE_PATH}/configure.py" "'ARM64' : 'arm64'" "'ARM64' : 'x64'")

vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_EXE_PATH ${PYTHON3} DIRECTORY)
vcpkg_add_to_path(PREPEND "${PYTHON3_EXE_PATH}")

if(VCPKG_TARGET_IS_WINDOWS)
set(nodejs_options openssl-no-asm static ${VCPKG_TARGET_ARCHITECTURE})

if(NOT "${VCPKG_BUILD_TYPE}" STREQUAL "release")
message(STATUS "Building nodejs Debug")

execute_process(
COMMAND "${SOURCE_PATH}/vcbuild.bat" debug ${nodejs_options}
WORKING_DIRECTORY "${SOURCE_PATH}"

OUTPUT_VARIABLE NODE_BUILD_SH_OUT
ERROR_VARIABLE NODE_BUILD_SH_ERR
RESULT_VARIABLE NODE_BUILD_SH_RES
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
)
if(NOT NODE_BUILD_SH_RES EQUAL 0)
message(FATAL_ERROR "Failed to build nodejs Debug (code ${NODE_BUILD_SH_RES})")
endif()
endif()

message(STATUS "Building nodejs Release")

execute_process(
COMMAND "${SOURCE_PATH}/vcbuild.bat" release ${nodejs_options}
WORKING_DIRECTORY "${SOURCE_PATH}"

OUTPUT_VARIABLE NODE_BUILD_SH_OUT
ERROR_VARIABLE NODE_BUILD_SH_ERR
RESULT_VARIABLE NODE_BUILD_SH_RES
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
)

if(NOT NODE_BUILD_SH_RES EQUAL 0)
message(FATAL_ERROR "Failed to build nodejs Release (code ${NODE_BUILD_SH_RES})")
endif()

file(GLOB libs_debug "${SOURCE_PATH}/Debug/*.lib")
foreach(path ${libs_debug})
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/node-embedder-api")
file(COPY "${path}" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib/node-embedder-api")
endforeach()

file(GLOB libs "${SOURCE_PATH}/Release/*.lib")
foreach(path ${libs})
if(NOT "${path}" MATCHES ".*cctest\.lib|.*embedtest\.lib")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/node-embedder-api")
file(COPY "${path}" DESTINATION "${CURRENT_PACKAGES_DIR}/lib/node-embedder-api")
endif()
endforeach()
else()
find_program(MAKE make REQUIRED)

if(NOT "${VCPKG_BUILD_TYPE}" STREQUAL "release")
message(STATUS "Configuring nodejs Debug")

execute_process(
COMMAND "${SOURCE_PATH}/configure" "--debug"
WORKING_DIRECTORY "${SOURCE_PATH}"

OUTPUT_VARIABLE NODE_BUILD_SH_OUT
ERROR_VARIABLE NODE_BUILD_SH_ERR
RESULT_VARIABLE NODE_BUILD_SH_RES
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
)

if(NOT NODE_BUILD_SH_RES EQUAL 0)
message(FATAL_ERROR "Failed to configure nodejs debug (code ${NODE_BUILD_SH_RES})")
endif()

message(STATUS "Building nodejs Debug")

vcpkg_execute_build_process(
COMMAND "${MAKE}" "-j${VCPKG_CONCURRENCY}" ${MAKE_OPTIONS}
NO_PARALLEL_COMMAND "${MAKE}" "-j1" ${MAKE_OPTIONS}
WORKING_DIRECTORY "${SOURCE_PATH}"
LOGNAME "build-${TARGET_TRIPLET}-dbg"
)

file(GLOB libs "${SOURCE_PATH}/Debug/*.a")
foreach(path ${libs})
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/node-embedder-api")
file(COPY "${path}" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib/node-embedder-api")
endforeach()
endif()

message(STATUS "Configuring nodejs Release")

execute_process(
COMMAND "${SOURCE_PATH}/configure"
WORKING_DIRECTORY "${SOURCE_PATH}"

OUTPUT_VARIABLE NODE_BUILD_SH_OUT
ERROR_VARIABLE NODE_BUILD_SH_ERR
RESULT_VARIABLE NODE_BUILD_SH_RES
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
)

if(NOT NODE_BUILD_SH_RES EQUAL 0)
message(FATAL_ERROR "Failed to configure nodejs release (code ${NODE_BUILD_SH_RES})")
endif()

message(STATUS "Building nodejs Release")

vcpkg_execute_build_process(
COMMAND "${MAKE}" "-j${VCPKG_CONCURRENCY}" ${MAKE_OPTIONS}
NO_PARALLEL_COMMAND "${MAKE}" "-j1" ${MAKE_OPTIONS}
WORKING_DIRECTORY "${SOURCE_PATH}"
LOGNAME "build-${TARGET_TRIPLET}-rel"
)

file(GLOB libs "${SOURCE_PATH}/Release/*.a")
foreach(path ${libs})
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/node-embedder-api")
file(COPY "${path}" DESTINATION "${CURRENT_PACKAGES_DIR}/lib/node-embedder-api")
endforeach()

endif()

file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")

# main header
file(COPY "${SOURCE_PATH}/src/node.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")

# node.h requirements
file(COPY "${SOURCE_PATH}/src/node_api.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")
file(COPY "${SOURCE_PATH}/src/node_version.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")

file(GLOB v8_headers "${SOURCE_PATH}/src/deps/v8/include/*.h")
foreach(v8_header ${v8_headers})
file(COPY "${v8_header}" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")
endforeach()

file(GLOB v8_headers "${SOURCE_PATH}/src/deps/v8/include/cppgc/*.h")
foreach(v8_header ${v8_headers})
file(COPY "${v8_header}" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api/cppgc")
endforeach()

file(GLOB v8_headers "${SOURCE_PATH}/src/deps/v8/include/libplatform/*.h")
foreach(v8_header ${v8_headers})
file(COPY "${v8_header}" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api/libplatform")
endforeach()

# node_api.h requirements
file(COPY "${SOURCE_PATH}/src/js_native_api.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")
file(COPY "${SOURCE_PATH}/src/node_api_types.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")

# js_native_api.h requirements
file(COPY "${SOURCE_PATH}/src/js_native_api_types.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/node-embedder-api")

file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
20 changes: 20 additions & 0 deletions overlay_ports/node-embedder-api/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "node-embedder-api",
"version": "22.0.0",
"description": "NodeJS API for embedding NodeJS in your C++ applications",
"homepage": "https://nodejs.org/api/embedding.html",
"license": "MIT",
"supports": "(windows & x64 & !uwp) | linux | osx",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true,
"platform": "windows"
},
{
"name": "vcpkg-cmake-config",
"host": true,
"platform": "windows"
}
]
}
9 changes: 9 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@
},
"skyrim-vr": {
"description": "Build platform for Skyrim VR."
},
"build-nodejs": {
"description": "",
"dependencies": [
{
"name": "node-embedder-api",
"platform": "windows"
}
]
}
}
}

0 comments on commit 61dc135

Please sign in to comment.