Skip to content

Commit 330d46a

Browse files
authored
Switch mono to use cmake-detected objcopy (#83903)
We use `configuretools.cmake` in `coreclr`, native `libs` (for both runtimes), `corehost` and `tests` to locate tools most suitable for the selected toolchain. However for `mono`, we manually specify a hardcoded list of `objcopy` names which require extra step in _each_ cross Dockerfile (e.g. [when distro package provides cross arch binutils](https://github.com/dotnet/dotnet-buildtools-prereqs-docker/blob/b5ebe26fee6823afc3154d3da8e8540321496ca4/src/ubuntu/22.04/cross/arm64/Dockerfile#L4-L7) and [when distro package doesn't provide one](https://github.com/dotnet/dotnet-buildtools-prereqs-docker/blob/b5ebe26fee6823afc3154d3da8e8540321496ca4/src/ubuntu/22.04/cross/ppc64le-alpine/Dockerfile#L3-L20)). This manual work is redundant and adds complexity for someone working on porting runtime to a new platform or creating a docker image with runtime build prereqs. This PR brings mono to the same plan as rest of the native subsets by re-using `configuretools.cmake` in mono for `objcopy` detection and `install_with_stripped_symbols` function out of `functions.cmake`, which takes care of stripping the binaries without dealing with platform differences at call-sites. ps - moving mono to fully utilize `configurecompiler.cmake` as rest of the native subsets is ultimate goal, but it is non-trivial to accomplish in a single PR.
1 parent e3a80f3 commit 330d46a

File tree

9 files changed

+48
-88
lines changed

9 files changed

+48
-88
lines changed

eng/native/functions.cmake

+5-3
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,11 @@ function (get_symbol_file_name targetName outputSymbolFilename)
373373
endif ()
374374

375375
set(${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE)
376-
else(CLR_CMAKE_HOST_UNIX)
376+
elseif(CLR_CMAKE_HOST_WIN32)
377377
# We can't use the $<TARGET_PDB_FILE> generator expression here since
378378
# the generator expression isn't supported on resource DLLs.
379379
set(${outputSymbolFilename} $<TARGET_FILE_DIR:${targetName}>/$<TARGET_FILE_PREFIX:${targetName}>$<TARGET_FILE_BASE_NAME:${targetName}>.pdb PARENT_SCOPE)
380-
endif(CLR_CMAKE_HOST_UNIX)
380+
endif()
381381
endfunction()
382382

383383
function(strip_symbols targetName outputFilename)
@@ -443,7 +443,9 @@ endfunction()
443443
function(install_with_stripped_symbols targetName kind destination)
444444
if(NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
445445
strip_symbols(${targetName} symbol_file)
446-
install_symbol_file(${symbol_file} ${destination} ${ARGN})
446+
if (NOT "${symbol_file}" STREQUAL "")
447+
install_symbol_file(${symbol_file} ${destination} ${ARGN})
448+
endif()
447449
endif()
448450

449451
if (CLR_CMAKE_TARGET_APPLE AND ("${kind}" STREQUAL "TARGETS"))

src/mono/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(mono)
88

99
include(../../eng/native/configurepaths.cmake)
1010
include(${CLR_ENG_NATIVE_DIR}/functions.cmake)
11+
include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake)
1112

1213
if (MSVC)
1314
# Also set by configurecompiler.cmake, which isn't used by mono yet

src/mono/dlls/dbgshim/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ if(CLR_CMAKE_HOST_UNIX)
8282
endif()
8383

8484
target_link_libraries(dbgshim PRIVATE ${DBGSHIM_LIBRARIES} monoapi)
85-
install(TARGETS dbgshim DESTINATION lib)
85+
install_with_stripped_symbols(dbgshim TARGETS lib)

src/mono/dlls/mscordbi/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ if(CLR_CMAKE_HOST_UNIX)
153153
endif()
154154

155155
target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} monoapi)
156-
install(TARGETS mscordbi DESTINATION lib)
156+
install_with_stripped_symbols(mscordbi TARGETS lib)

src/mono/mono.proj

+35-72
Large diffs are not rendered by default.

src/mono/mono/component/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
192192
target_link_libraries("mono-component-${component}" PRIVATE monosgen-shared)
193193
endif()
194194
target_link_libraries("mono-component-${component}" PRIVATE ${OS_LIBS})
195-
install(TARGETS "mono-component-${component}" LIBRARY)
195+
install_with_stripped_symbols("mono-component-${component}" TARGETS lib)
196196
endforeach()
197197

198198
#define a library for each component and component stub

src/mono/mono/eventpipe/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if(ENABLE_PERFTRACING)
4343
if(ICU_LDFLAGS)
4444
set_target_properties(ep-test PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
4545
endif()
46-
install(TARGETS ep-test RUNTIME)
46+
install_with_stripped_symbols(ep-test TARGETS bin)
4747
else(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES))
4848
message(VERBOSE "Skip building native EventPipe library test runner.")
4949
endif(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES))

src/mono/mono/metadata/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,3 @@ target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT)
208208
target_include_directories(metadata_objects PRIVATE ${PROJECT_BINARY_DIR}/../..
209209
${PROJECT_SOURCE_DIR}/../..
210210
${PROJECT_SOURCE_DIR}/..)
211-

src/mono/mono/mini/CMakeLists.txt

+3-8
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ if(NOT DISABLE_SHARED_LIBS)
410410
# if components are disabled, link the fallback stubs into the runtime
411411
target_sources(monosgen-shared PRIVATE "${mono-components-stub-objects}")
412412
endif()
413-
install(TARGETS monosgen-shared LIBRARY)
413+
install_with_stripped_symbols(monosgen-shared TARGETS lib)
414414
if(HOST_WIN32 AND TARGET_AMD64)
415415
add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c")
416416
target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api)
@@ -452,9 +452,7 @@ if(NOT DISABLE_SHARED_LIBS)
452452
FRAMEWORK_VERSION C
453453
MACOSX_FRAMEWORK_IDENTIFIER net.dot.mono-framework
454454
)
455-
install(TARGETS ${frameworkconfig}
456-
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
457-
)
455+
install_with_stripped_symbols(${frameworkconfig} TARGETS ${CMAKE_INSTALL_LIBDIR})
458456
endforeach()
459457
endif()
460458
endif()
@@ -567,8 +565,5 @@ if(NOT DISABLE_EXECUTABLES)
567565
target_sources(mono-sgen PRIVATE ${mono_validate_apis_source})
568566
endif()
569567

570-
install(TARGETS mono-sgen RUNTIME)
571-
if(HOST_WIN32)
572-
install(FILES $<TARGET_PDB_FILE:mono-sgen> DESTINATION bin OPTIONAL)
573-
endif()
568+
install_with_stripped_symbols(mono-sgen TARGETS bin)
574569
endif()

0 commit comments

Comments
 (0)