Skip to content

Commit dbd2e76

Browse files
authored
Build MAGE modules with ninja (#694)
Save about 3 seconds per build by using Ninja to build C++ modules! Also fix a few deprecation warnings from Rust.
1 parent 517e835 commit dbd2e76

File tree

5 files changed

+44
-48
lines changed

5 files changed

+44
-48
lines changed

cpp/CMakeLists.txt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,16 @@ include(ExternalProject)
4141
include(cugraph)
4242

4343
# Install testing dependencies (gtest)
44-
set(GTEST_ROOT ${PROJECT_BINARY_DIR}/gtest)
45-
ExternalProject_Add(gtest-proj
46-
PREFIX ${GTEST_ROOT}
47-
INSTALL_DIR ${GTEST_ROOT}
44+
FetchContent_Declare(googletest
4845
GIT_REPOSITORY https://github.com/google/googletest.git
4946
GIT_TAG v1.16.0
50-
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
51-
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
52-
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
53-
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
54-
set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
55-
set(GTEST_LIBRARY_PATH ${GTEST_ROOT}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
56-
set(GTEST_DEBUG_LIBRARY_PATH ${GTEST_ROOT}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtestd.a)
57-
add_library(mage_gtest STATIC IMPORTED)
58-
set_target_properties(mage_gtest PROPERTIES
59-
IMPORTED_LOCATION "${GTEST_LIBRARY_PATH}"
60-
IMPORTED_LOCATION_DEBUG "${GTEST_DEBUG_LIBRARY_PATH}"
61-
INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
62-
include_directories("${GTEST_INCLUDE_DIR}")
63-
add_dependencies(mage_gtest gtest-proj)
47+
)
48+
# For Windows: Prevent overriding the parent project's compiler/linker settings
49+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
50+
FetchContent_MakeAvailable(googletest)
51+
52+
# Create an alias for consistency with existing code
53+
add_library(mage_gtest ALIAS gtest)
6454

6555
# Add OpenMP compiling option
6656
find_package(OpenMP)

cpp/betweenness_centrality_module/CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,23 @@ endif()
2929
set(betweenness_centrality_online_src
3030
betweenness_centrality_online_module.cpp
3131
algorithm/betweenness_centrality.cpp
32-
algorithm_online/betweenness_centrality_online.cpp
33-
../biconnected_components_module/algorithm/biconnected_components.cpp)
32+
algorithm_online/betweenness_centrality_online.cpp)
3433

3534
add_query_module(betweenness_centrality_online 1 "${betweenness_centrality_online_src}")
3635

3736
# Link external libraries
38-
target_link_libraries(betweenness_centrality_online PRIVATE mg_utility)
37+
target_link_libraries(betweenness_centrality_online PRIVATE mg_utility biconnected_components_algorithm)
3938
target_include_directories(betweenness_centrality_online PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
4039

4140
# Module tests
4241
if (NOT MAGE_CUGRAPH_ENABLE)
4342
include(GoogleTest)
44-
set(betweenness_centrality_online_src
43+
set(betweenness_centrality_online_test_src
4544
betweenness_centrality_online_test.cpp
4645
algorithm/betweenness_centrality.cpp
47-
algorithm_online/betweenness_centrality_online.cpp
48-
../biconnected_components_module/algorithm/biconnected_components.cpp)
46+
algorithm_online/betweenness_centrality_online.cpp)
4947

50-
add_executable(betweenness_centrality_online_test "${betweenness_centrality_online_src}")
51-
target_link_libraries(betweenness_centrality_online_test PRIVATE mg_utility mage_gtest)
48+
add_executable(betweenness_centrality_online_test "${betweenness_centrality_online_test_src}")
49+
target_link_libraries(betweenness_centrality_online_test PRIVATE mg_utility mage_gtest biconnected_components_algorithm)
5250
gtest_add_tests(TARGET betweenness_centrality_online_test)
5351
endif()
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
set(biconnected_components_module_src
2-
biconnected_components_module.cpp
1+
# Create a static library for the shared algorithm code
2+
add_library(biconnected_components_algorithm STATIC
33
algorithm/biconnected_components.cpp)
4+
target_include_directories(biconnected_components_algorithm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
5+
target_link_libraries(biconnected_components_algorithm PRIVATE mg_utility)
6+
7+
set(biconnected_components_module_src
8+
biconnected_components_module.cpp)
49

510
add_query_module(biconnected_components 1 "${biconnected_components_module_src}")
611

712
# Link external libraries
8-
target_link_libraries(biconnected_components PRIVATE mg_utility)
13+
target_link_libraries(biconnected_components PRIVATE mg_utility biconnected_components_algorithm)
914
target_include_directories(biconnected_components PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
1015

1116
# Module tests
1217
if (NOT MAGE_CUGRAPH_ENABLE)
1318
include(GoogleTest)
1419
set(biconnected_components_test_src
15-
biconnected_components_test.cpp
16-
algorithm/biconnected_components.cpp)
20+
biconnected_components_test.cpp)
1721

1822
add_executable(biconnected_components_test "${biconnected_components_test_src}")
19-
target_link_libraries(biconnected_components_test PRIVATE mg_utility mage_gtest)
23+
target_link_libraries(biconnected_components_test PRIVATE mg_utility mage_gtest biconnected_components_algorithm)
2024
gtest_add_tests(TARGET biconnected_components_test)
21-
endif()
25+
endif()

rust/rsmgp-sys/src/temporal/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl Date {
7676
}
7777

7878
pub fn to_naive_date(&self) -> NaiveDate {
79-
NaiveDate::from_ymd(self.year(), self.month(), self.day())
79+
NaiveDate::from_ymd_opt(self.year(), self.month(), self.day())
80+
.expect("Invalid date parameters from Memgraph")
8081
}
8182

8283
pub fn mgp_ptr(&self) -> *mut mgp_date {
@@ -106,12 +107,13 @@ fn create_naive_time(
106107
millisecond: u32,
107108
microsecond: u32,
108109
) -> NaiveTime {
109-
NaiveTime::from_hms_micro(
110+
NaiveTime::from_hms_micro_opt(
110111
hour,
111112
minute,
112113
second,
113114
millisecond * MICROS_PER_MILLIS + microsecond,
114115
)
116+
.expect("Invalid time parameters from Memgraph")
115117
}
116118

117119
fn create_mgp_local_time_parameters(from: &NaiveTime) -> mgp_local_time_parameters {
@@ -177,7 +179,8 @@ impl LocalTime {
177179
let timestamp = self.timestamp();
178180
let seconds = (timestamp / MICROS_PER_SECOND) as u32;
179181
let micros = (timestamp % MICROS_PER_SECOND) as u32;
180-
NaiveTime::from_num_seconds_from_midnight(seconds, micros * NANOS_PER_MICROS)
182+
NaiveTime::from_num_seconds_from_midnight_opt(seconds, micros * NANOS_PER_MICROS)
183+
.expect("Invalid time parameters from Memgraph")
181184
}
182185

183186
pub fn mgp_ptr(&self) -> *mut mgp_local_time {
@@ -272,13 +275,15 @@ impl LocalDateTime {
272275
}
273276

274277
pub fn to_naive_date_time(&self) -> NaiveDateTime {
275-
NaiveDate::from_ymd(self.year(), self.month(), self.day()).and_time(create_naive_time(
276-
self.hour(),
277-
self.minute(),
278-
self.second(),
279-
self.millisecond(),
280-
self.microsecond(),
281-
))
278+
NaiveDate::from_ymd_opt(self.year(), self.month(), self.day())
279+
.expect("Invalid date parameters from Memgraph")
280+
.and_time(create_naive_time(
281+
self.hour(),
282+
self.minute(),
283+
self.second(),
284+
self.millisecond(),
285+
self.microsecond(),
286+
))
282287
}
283288

284289
pub fn mgp_ptr(&self) -> *mut mgp_local_date_time {

setup

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,23 @@ def build_and_copy_cpp_modules(args: Dict[str, Any]) -> bool:
191191
os.makedirs(CPP_BUILD_DIRECTORY, exist_ok=True)
192192

193193
# Prepare CMake flags
194-
os.chdir(CPP_BUILD_DIRECTORY)
195-
cmake_args = [".."]
194+
os.chdir(CPP_DIRECTORY)
195+
cmake_args = [".", "-B", CPP_BUILD_DIRECTORY]
196196
if args[Parameter.GPU.value]:
197197
cmake_args.append(f"-D{MAGE_GPU_BUILD}")
198198
if args[Parameter.CPP_BUILD_FLAGS.value] is not None:
199199
cmake_args += [f"-D{flag}" for flag in args[Parameter.CPP_BUILD_FLAGS.value]]
200200
else:
201201
cmake_args += [f"-DCMAKE_BUILD_TYPE={BuildType.RELEASE}"]
202202

203-
cmake_command = ["cmake"] + cmake_args
203+
cmake_command = ["cmake"] + cmake_args + ["-GNinja"]
204204

205205
cmake_status = run_command(cmake_command)
206206
if not cmake_status:
207207
logger.error("[Terminal] (1/7) Building C++ modules failed.")
208208
return False
209209

210-
core_count = mp.cpu_count()
211-
make_command = ["make", f"-j{core_count}"]
210+
make_command = ["cmake", "--build", CPP_BUILD_DIRECTORY]
212211

213212
make_status = run_command(make_command)
214213
if not make_status:

0 commit comments

Comments
 (0)