Skip to content

Commit db8af85

Browse files
Minimize cuopt_static linkage in tests to avoid package size explosion
PR #1526 switched all tests to link cuopt_static, which inflates libcuopt-tests from ~75 MB to ~5 GB (confirmed from CI artifacts) because each of ~36 test executables embeds the full cuopt object graph. This commit introduces ConfigureInternalTest for tests that genuinely need access to hidden symbols, and keeps ConfigureTest on the shared library for tests that only use the public API. Only routing tests are switched to ConfigureInternalTest: they all include routing_test.cuh which pulls in cuopt::routing::detail types (solution_t, problem_t, fleet_order_constraints_t, md_utils, etc.). MIP, LP, QP, SOCP, dual_simplex, distance engine, CLI, and utility tests use only public cuopt API or raft::detail inline headers (which are compiled into the TU, not linked from cuopt.so), so they stay on the shared library. GRPC tests are left unchanged as they have explicit target_link_libraries and grpc_client.cpp symbols lack CUOPT_EXPORT. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 75773da commit db8af85

2 files changed

Lines changed: 58 additions & 9 deletions

File tree

cpp/tests/CMakeLists.txt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function(ConfigureTest CMAKE_TEST_NAME)
5555

5656
target_link_libraries(${CMAKE_TEST_NAME}
5757
PRIVATE
58-
cuopt_static
58+
cuopt
5959
cuopttestutils
6060
GTest::gmock
6161
GTest::gmock_main
@@ -81,6 +81,52 @@ function(ConfigureTest CMAKE_TEST_NAME)
8181
)
8282
endfunction()
8383

84+
# ConfigureInternalTest(NAME source1.cu ... [LABELS ...])
85+
#
86+
# Like ConfigureTest but links cuopt_static instead of the shared library.
87+
# Use only for tests that access symbols in cuopt::*::detail namespaces or
88+
# include headers from cpp/src/ that are not part of the public API.
89+
function(ConfigureInternalTest CMAKE_TEST_NAME)
90+
cmake_parse_arguments(CT "" "" "LABELS" ${ARGN})
91+
add_executable(${CMAKE_TEST_NAME} ${CT_UNPARSED_ARGUMENTS})
92+
target_include_directories(${CMAKE_TEST_NAME}
93+
PRIVATE
94+
"${CUOPT_TEST_DIR}/../src"
95+
"${CUOPT_TEST_DIR}/../src/io"
96+
"${CUOPT_TEST_DIR}"
97+
"${papilo_SOURCE_DIR}/src"
98+
"${papilo_BINARY_DIR}"
99+
"${pslp_SOURCE_DIR}/include"
100+
"${dejavu_SOURCE_DIR}"
101+
)
102+
103+
target_link_libraries(${CMAKE_TEST_NAME}
104+
PRIVATE
105+
cuopt_static
106+
cuopttestutils
107+
GTest::gmock
108+
GTest::gmock_main
109+
GTest::gtest
110+
GTest::gtest_main
111+
${CUOPT_PRIVATE_CUDA_LIBS}
112+
)
113+
if(NOT DEFINED INSTALL_TARGET OR "${INSTALL_TARGET}" STREQUAL "")
114+
target_link_options(${CMAKE_TEST_NAME} PRIVATE -Wl,--enable-new-dtags)
115+
endif()
116+
117+
add_test(NAME ${CMAKE_TEST_NAME} COMMAND ${CMAKE_TEST_NAME})
118+
119+
if(CT_LABELS)
120+
set_tests_properties(${CMAKE_TEST_NAME} PROPERTIES LABELS "${CT_LABELS}")
121+
endif()
122+
123+
install(
124+
TARGETS ${CMAKE_TEST_NAME}
125+
COMPONENT testing
126+
DESTINATION bin/gtests/libcuopt
127+
EXCLUDE_FROM_ALL
128+
)
129+
endfunction()
84130

85131
# ####################################################################
86132
# - set rapids dataset path ----------------------------------------------------------------------

cpp/tests/routing/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,36 @@
33
# SPDX-License-Identifier: Apache-2.0
44
# cmake-format: on
55

6-
ConfigureTest(ROUTING_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_routing_test.cu
6+
# All routing tests include routing_test.cuh which pulls in cuopt::routing::detail
7+
# types (solution_t, problem_t, fleet_order_constraints_t, md_utils, etc.).
8+
# They must link against cuopt_static to access those hidden symbols.
9+
ConfigureInternalTest(ROUTING_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_routing_test.cu
710
LABELS routing)
8-
ConfigureTest(ROUTING_GES_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_ges_test.cu
11+
ConfigureInternalTest(ROUTING_GES_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_ges_test.cu
912
LABELS routing)
1013

11-
ConfigureTest(VEHICLE_ORDER_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_vehicle_order_match.cu
14+
ConfigureInternalTest(VEHICLE_ORDER_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_vehicle_order_match.cu
1215
LABELS routing)
13-
ConfigureTest(VEHICLE_TYPES_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_vehicle_types_test.cu
16+
ConfigureInternalTest(VEHICLE_TYPES_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_vehicle_types_test.cu
1417
LABELS routing)
15-
ConfigureTest(OBJECTIVE_FUNCTION_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_objective_function_test.cu
18+
ConfigureInternalTest(OBJECTIVE_FUNCTION_TEST ${CMAKE_CURRENT_SOURCE_DIR}/level0/l0_objective_function_test.cu
1619
LABELS routing)
1720

1821
# ##################################################################################################
1922
# - L1 advanced retail tests --------------------------------------------------------------------------
20-
ConfigureTest(RETAIL_L1TEST ${CMAKE_CURRENT_SOURCE_DIR}/level1/l1_retail_test.cu
23+
ConfigureInternalTest(RETAIL_L1TEST ${CMAKE_CURRENT_SOURCE_DIR}/level1/l1_retail_test.cu
2124
LABELS routing)
2225

2326
# ##################################################################################################
2427
# - L1 tests for quick regression check --------------------------------------------------------------------------
25-
ConfigureTest(ROUTING_L1TEST ${CMAKE_CURRENT_SOURCE_DIR}/level1/l1_routing_test.cu
28+
ConfigureInternalTest(ROUTING_L1TEST ${CMAKE_CURRENT_SOURCE_DIR}/level1/l1_routing_test.cu
2629
LABELS routing)
2730

2831
# Disabled: both tests are slow and known to be broken.
2932
set_tests_properties(RETAIL_L1TEST ROUTING_L1TEST PROPERTIES DISABLED TRUE)
3033

3134
# # - ${CMAKE_CURRENT_SOURCE_DIR} unit tests ----------------------------------------------------------------------------
32-
ConfigureTest(ROUTING_UNIT_TEST
35+
ConfigureInternalTest(ROUTING_UNIT_TEST
3336
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_types.cu
3437
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/breaks.cu
3538
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/heterogenous_breaks.cu

0 commit comments

Comments
 (0)