Skip to content

Commit

Permalink
Improve support and verbosity for NodeJS dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Feb 23, 2021
1 parent 230c7bf commit 7d5200a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
24 changes: 17 additions & 7 deletions cmake/FindNodeJS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ if(NOT NODEJS_INCLUDE_DIR OR NOT NODEJS_V8_INCLUDE_DIR OR NOT NODEJS_UV_INCLUDE_
# Download node if needed
if(NOT EXISTS "${NODEJS_DOWNLOAD_FILE}")
message(STATUS "Downloading NodeJS headers")
file(DOWNLOAD ${NODEJS_DOWNLOAD_URL} ${NODEJS_DOWNLOAD_FILE})
file(DOWNLOAD ${NODEJS_DOWNLOAD_URL} ${NODEJS_DOWNLOAD_FILE} SHOW_PROGRESS)
endif()

# Decompress node if needed
Expand Down Expand Up @@ -325,18 +325,24 @@ if(NODEJS_MODULE_VERSION AND NOT NODEJS_BUILD_FROM_SOURCE)
set(NODEJS_LIBRARY_PATH "/usr/local/lib")
endif()

set(NODEJS_SYSTEM_LIBRARY_PATH "/lib/x86_64-linux-gnu") # TODO: Add others
set(NODEJS_SYSTEM_LIBRARY_PATH "/lib/x86_64-linux-gnu" "/usr/lib/x86_64-linux-gnu") # TODO: Add others

# Find library
find_library(NODEJS_LIBRARY
NAMES ${NODEJS_LIBRARY_NAMES}
PATHS ${NODEJS_COMPILE_PATH} ${NODEJS_LIBRARY_PATH} ${NODEJS_SYSTEM_LIBRARY_PATH}
DOC "NodeJS JavaScript Runtime Library"
)

if(NODEJS_LIBRARY)
message(STATUS "NodeJS Library Found")
endif()
endif()

# Install NodeJS library in case it is not distributed
if(NOT NODEJS_LIBRARY)
message(STATUS "NodeJS library not found, trying to build it from source")

# NodeJS download and output path (workaround to compile node as a shared library)
set(NODEJS_DOWNLOAD_URL "https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}.tar.gz")
set(NODEJS_BASE_PATH "${CMAKE_CURRENT_BINARY_DIR}/sources")
Expand All @@ -346,7 +352,7 @@ if(NOT NODEJS_LIBRARY)
# Download node if needed
if(NOT EXISTS "${NODEJS_DOWNLOAD_FILE}")
message(STATUS "Downloading NodeJS distribution v${NODEJS_VERSION}")
file(DOWNLOAD ${NODEJS_DOWNLOAD_URL} ${NODEJS_DOWNLOAD_FILE})
file(DOWNLOAD ${NODEJS_DOWNLOAD_URL} ${NODEJS_DOWNLOAD_FILE} SHOW_PROGRESS)
endif()

# Decompress node if needed
Expand Down Expand Up @@ -391,7 +397,7 @@ if(NOT NODEJS_LIBRARY)
message(STATUS "Install NodeJS shared library")

# TODO: Implement install command
#execute_process(COMMAND msiexec /a "node-v${NODEJS_VERSION}-${NODEJS_COMPILE_ARCH}.msi" WORKING_DIRECTORY "${NODEJS_COMPILE_PATH}" OUTPUT_QUIET)
#execute_process(COMMAND msiexec /a "node-v${NODEJS_VERSION}-${NODEJS_COMPILE_ARCH}.msi" WORKING_DIRECTORY "${NODEJS_COMPILE_PATH}")
endif()

# TODO: Delete this workaround after implementing the install command
Expand Down Expand Up @@ -421,14 +427,14 @@ if(NOT NODEJS_LIBRARY)
ProcessorCount(N)

if(NOT N EQUAL 0)
execute_process(COMMAND sh -c "alias python=`which python2.7`; make -j${N} -C out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1" WORKING_DIRECTORY "${NODEJS_OUTPUT_PATH}" OUTPUT_QUIET)
execute_process(COMMAND sh -c "alias python=`which python2.7`; make -j${N} -C out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1" WORKING_DIRECTORY "${NODEJS_OUTPUT_PATH}")
else()
execute_process(COMMAND sh -c "alias python=`which python2.7`; make -C out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1" WORKING_DIRECTORY "${NODEJS_OUTPUT_PATH}" OUTPUT_QUIET)
execute_process(COMMAND sh -c "alias python=`which python2.7`; make -C out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1" WORKING_DIRECTORY "${NODEJS_OUTPUT_PATH}")
endif()

message(STATUS "Install NodeJS shared library")

execute_process(COMMAND sh -c "make install" WORKING_DIRECTORY "${NODEJS_OUTPUT_PATH}" OUTPUT_QUIET)
execute_process(COMMAND sh -c "make install" WORKING_DIRECTORY "${NODEJS_OUTPUT_PATH}")
endif()
endif()

Expand All @@ -448,6 +454,10 @@ if(NOT NODEJS_LIBRARY)
DOC "NodeJS JavaScript Runtime Library"
)
endif()

if(NOT NODEJS_LIBRARY)
message(SEND_ERROR "NodeJS library not found and it could not be built from source")
endif()
endif()

set(NODEJS_INCLUDE_DIRS "${NODEJS_INCLUDE_DIR}")
Expand Down
4 changes: 2 additions & 2 deletions source/loaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ option(OPTION_BUILD_LOADERS_JSM "Build JavaScript SpiderMonkey 4.8 loader plugin
option(OPTION_BUILD_LOADERS_JS "Build JavaScript V8 5.1+ loader plugin." OFF)
option(OPTION_BUILD_LOADERS_LUA "Build LuaJIT2 v2.1 (OpenResty fork) loader plugin." OFF)
option(OPTION_BUILD_LOADERS_MOCK "Build mock loader loader plugin." ON)
option(OPTION_BUILD_LOADERS_NODE "Build NodeJS 10.22.0 JavaScript Runtime loader plugin." OFF)
option(OPTION_BUILD_LOADERS_NODE "Build NodeJS 10.23.1 JavaScript Runtime loader plugin." OFF)
option(OPTION_BUILD_LOADERS_PY "Build Python 3.7 C API loader plugin." OFF)
option(OPTION_BUILD_LOADERS_RB "Build Ruby 2.5 C API loader plugin." OFF)
option(OPTION_BUILD_LOADERS_RPC "Build cURL Remote Procedure Call loader plugin." OFF)
Expand All @@ -55,7 +55,7 @@ add_subdirectory(jsm_loader) # Mozilla's SpiderMonkey 4.8 JavaScript Engine
add_subdirectory(js_loader) # Google's V8 5.1 JavaScript Engine
add_subdirectory(lua_loader) # LuaJIT2 v2.1 (OpenResty fork) Runtime
add_subdirectory(mock_loader) # Mock loader plugin without dependencies (core testing)
add_subdirectory(node_loader) # NodeJS 10.22.0 JavaScript Runtime
add_subdirectory(node_loader) # NodeJS 10.23.1 JavaScript Runtime
add_subdirectory(py_loader) # Python 3.7 C API
add_subdirectory(rb_loader) # Ruby 2.5 C API
add_subdirectory(rpc_loader) # cURL Remote Procedure Call
Expand Down
2 changes: 1 addition & 1 deletion source/loaders/node_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif()
# External dependencies
#

find_package(NodeJS 10.22.0)
find_package(NodeJS 10.23.1)

if(NOT NODEJS_FOUND)
message(STATUS "NodeJS libraries not found")
Expand Down
2 changes: 1 addition & 1 deletion source/loaders/ts_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif()
# External dependencies
#

find_package(NodeJS 10.22.0)
find_package(NodeJS 10.23.1)

if(NOT NODEJS_FOUND)
message(STATUS "NodeJS libraries not found")
Expand Down
2 changes: 1 addition & 1 deletion source/ports/node_port/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ return()
# Detect exec with MetaCall CLI when this is being run with node
set(NODEJS_EXECUTABLE_ONLY ON)

find_package(NodeJS 10.22.0)
find_package(NodeJS 10.23.1)

if(NOT NODEJS_FOUND)
message(STATUS "NodeJS libraries not found")
Expand Down
2 changes: 1 addition & 1 deletion source/scripts/typescript/templating/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

set(NODEJS_EXECUTABLE_ONLY ON)

find_package(NodeJS 10.22.0)
find_package(NodeJS 10.23.1)

if(NOT NODEJS_FOUND)
message(STATUS "NodeJS executable not found")
Expand Down
2 changes: 1 addition & 1 deletion source/tests/metacall_rpc_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ add_dependencies(${target}

set(NODEJS_EXECUTABLE_ONLY ON)

find_package(NodeJS 10.22.0)
find_package(NodeJS 10.23.1)

if(NOT NODEJS_FOUND)
message(STATUS "NodeJS executable not found, skipping RPC loader test")
Expand Down
2 changes: 1 addition & 1 deletion source/tests/metacall_typescript_tsx_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif()

set(NODEJS_EXECUTABLE_ONLY ON)

find_package(NodeJS 10.22.0)
find_package(NodeJS 10.23.1)

if(NOT NODEJS_FOUND)
message(STATUS "NodeJS executable not found")
Expand Down

0 comments on commit 7d5200a

Please sign in to comment.