Skip to content
Merged
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
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ file(GLOB JS_SOURCE_FILES
# Copy all JS/TS files to build directory
file(COPY ${JS_SOURCE_FILES} DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/build")

set(NODEJS_LBUG_LINK_DEPS "")
if(NOT TARGET lbug)
if(NOT LBUG_NODEJS_USE_PRECOMPILED_LIB)
message(FATAL_ERROR "The Node.js addon requires the lbug target or LBUG_NODEJS_USE_PRECOMPILED_LIB=TRUE.")
endif()
if(NOT LBUG_NODEJS_PRECOMPILED_LIB_PATH)
message(FATAL_ERROR "LBUG_NODEJS_PRECOMPILED_LIB_PATH must point to a precompiled static liblbug archive.")
endif()
if(NOT EXISTS "${LBUG_NODEJS_PRECOMPILED_LIB_PATH}")
message(FATAL_ERROR "Precompiled liblbug archive not found: ${LBUG_NODEJS_PRECOMPILED_LIB_PATH}")
endif()
add_library(lbug STATIC IMPORTED GLOBAL)
set_target_properties(lbug PROPERTIES IMPORTED_LOCATION "${LBUG_NODEJS_PRECOMPILED_LIB_PATH}")
target_include_directories(lbug INTERFACE
"${PROJECT_SOURCE_DIR}/src/include"
"${PROJECT_BINARY_DIR}/src/include")
if(WIN32)
target_compile_definitions(lbug INTERFACE LBUG_STATIC_DEFINE)
endif()
set(NODEJS_LBUG_LINK_DEPS "$<LINK_ONLY:lbug_link_deps>")
endif()

add_library(lbugjs SHARED ${CPP_SOURCE_FILES})
if(CMAKE_JS_SRC)
target_sources(lbugjs PRIVATE "${CMAKE_JS_SRC}")
Expand All @@ -94,4 +116,4 @@ if(APPLE)
else()
target_link_options(lbugjs PRIVATE -Wl,--export-dynamic)
endif()
target_link_libraries(lbugjs PRIVATE lbug ${CMAKE_JS_LIB})
target_link_libraries(lbugjs PRIVATE lbug ${NODEJS_LBUG_LINK_DEPS} ${CMAKE_JS_LIB})
15 changes: 15 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ const THREADS = require("os").cpus().length;

console.log(`Using ${THREADS} threads to build Lbug.`);

const env = { ...process.env };
const precompiledLibPath = env.LBUG_NODEJS_PRECOMPILED_LIB_PATH;
if (precompiledLibPath) {
const extraFlags = [
env.EXTRA_CMAKE_FLAGS,
"-DBUILD_LBUG=FALSE",
"-DBUILD_SHELL=FALSE",
"-DLBUG_NODEJS_USE_PRECOMPILED_LIB=TRUE",
`-DLBUG_NODEJS_PRECOMPILED_LIB_PATH=${precompiledLibPath}`,
].filter(Boolean).join(" ");
env.EXTRA_CMAKE_FLAGS = extraFlags;
console.log(`Using precompiled liblbug from ${precompiledLibPath}.`);
}

execSync("npm run clean", { stdio: "inherit" });
execSync(`make nodejs NUM_THREADS=${THREADS}`, {
cwd: SRC_PATH,
env,
stdio: "inherit",
});
17 changes: 16 additions & 1 deletion install.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ if (process.platform === "win32") {
);

for (let key in env) {
const lowerKey = key.toLowerCase();
if (
key.toLowerCase().includes("node" || key.toLowerCase().includes("npm"))
(lowerKey.includes("node") || lowerKey.includes("npm")) &&
lowerKey !== "lbug_nodejs_precompiled_lib_path"
) {
delete env[key];
}
Expand All @@ -126,6 +128,19 @@ if (process.platform === "win32") {
);
}

if (env.LBUG_NODEJS_PRECOMPILED_LIB_PATH) {
env.EXTRA_CMAKE_FLAGS = [
env.EXTRA_CMAKE_FLAGS,
"-DBUILD_LBUG=FALSE",
"-DBUILD_SHELL=FALSE",
"-DLBUG_NODEJS_USE_PRECOMPILED_LIB=TRUE",
`-DLBUG_NODEJS_PRECOMPILED_LIB_PATH=${env.LBUG_NODEJS_PRECOMPILED_LIB_PATH}`,
].filter(Boolean).join(" ");
console.log(
`Using precompiled liblbug from '${env.LBUG_NODEJS_PRECOMPILED_LIB_PATH}'.`
);
}

childProcess.execSync("make nodejs NUM_THREADS=" + THREADS, {
env,
cwd: path.join(__dirname, "lbug-source"),
Expand Down
1 change: 1 addition & 0 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PLATFORM_MAP = {
"lbugjs-linux-x64.node": { os: "linux", cpu: "x64" },
"lbugjs-linux-arm64.node": { os: "linux", cpu: "arm64" },
"lbugjs-darwin-arm64.node": { os: "darwin", cpu: "arm64" },
"lbugjs-darwin-x64.node": { os: "darwin", cpu: "x64" },
"lbugjs-win32-x64.node": { os: "win32", cpu: "x64" },
};

Expand Down
Loading