Skip to content

Commit

Permalink
Switch mono to use cmake-detected objcopy (#83903)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
am11 committed Apr 14, 2023
1 parent e3a80f3 commit 330d46a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 88 deletions.
8 changes: 5 additions & 3 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ function (get_symbol_file_name targetName outputSymbolFilename)
endif ()

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

function(strip_symbols targetName outputFilename)
Expand Down Expand Up @@ -443,7 +443,9 @@ endfunction()
function(install_with_stripped_symbols targetName kind destination)
if(NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
strip_symbols(${targetName} symbol_file)
install_symbol_file(${symbol_file} ${destination} ${ARGN})
if (NOT "${symbol_file}" STREQUAL "")
install_symbol_file(${symbol_file} ${destination} ${ARGN})
endif()
endif()

if (CLR_CMAKE_TARGET_APPLE AND ("${kind}" STREQUAL "TARGETS"))
Expand Down
1 change: 1 addition & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ project(mono)

include(../../eng/native/configurepaths.cmake)
include(${CLR_ENG_NATIVE_DIR}/functions.cmake)
include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake)

if (MSVC)
# Also set by configurecompiler.cmake, which isn't used by mono yet
Expand Down
2 changes: 1 addition & 1 deletion src/mono/dlls/dbgshim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ if(CLR_CMAKE_HOST_UNIX)
endif()

target_link_libraries(dbgshim PRIVATE ${DBGSHIM_LIBRARIES} monoapi)
install(TARGETS dbgshim DESTINATION lib)
install_with_stripped_symbols(dbgshim TARGETS lib)
2 changes: 1 addition & 1 deletion src/mono/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ if(CLR_CMAKE_HOST_UNIX)
endif()

target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} monoapi)
install(TARGETS mscordbi DESTINATION lib)
install_with_stripped_symbols(mscordbi TARGETS lib)
107 changes: 35 additions & 72 deletions src/mono/mono.proj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/mono/mono/component/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
target_link_libraries("mono-component-${component}" PRIVATE monosgen-shared)
endif()
target_link_libraries("mono-component-${component}" PRIVATE ${OS_LIBS})
install(TARGETS "mono-component-${component}" LIBRARY)
install_with_stripped_symbols("mono-component-${component}" TARGETS lib)
endforeach()

#define a library for each component and component stub
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if(ENABLE_PERFTRACING)
if(ICU_LDFLAGS)
set_target_properties(ep-test PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
endif()
install(TARGETS ep-test RUNTIME)
install_with_stripped_symbols(ep-test TARGETS bin)
else(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES))
message(VERBOSE "Skip building native EventPipe library test runner.")
endif(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES))
Expand Down
1 change: 0 additions & 1 deletion src/mono/mono/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,3 @@ target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT)
target_include_directories(metadata_objects PRIVATE ${PROJECT_BINARY_DIR}/../..
${PROJECT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/..)

11 changes: 3 additions & 8 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ if(NOT DISABLE_SHARED_LIBS)
# if components are disabled, link the fallback stubs into the runtime
target_sources(monosgen-shared PRIVATE "${mono-components-stub-objects}")
endif()
install(TARGETS monosgen-shared LIBRARY)
install_with_stripped_symbols(monosgen-shared TARGETS lib)
if(HOST_WIN32 AND TARGET_AMD64)
add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c")
target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api)
Expand Down Expand Up @@ -452,9 +452,7 @@ if(NOT DISABLE_SHARED_LIBS)
FRAMEWORK_VERSION C
MACOSX_FRAMEWORK_IDENTIFIER net.dot.mono-framework
)
install(TARGETS ${frameworkconfig}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install_with_stripped_symbols(${frameworkconfig} TARGETS ${CMAKE_INSTALL_LIBDIR})
endforeach()
endif()
endif()
Expand Down Expand Up @@ -567,8 +565,5 @@ if(NOT DISABLE_EXECUTABLES)
target_sources(mono-sgen PRIVATE ${mono_validate_apis_source})
endif()

install(TARGETS mono-sgen RUNTIME)
if(HOST_WIN32)
install(FILES $<TARGET_PDB_FILE:mono-sgen> DESTINATION bin OPTIONAL)
endif()
install_with_stripped_symbols(mono-sgen TARGETS bin)
endif()

0 comments on commit 330d46a

Please sign in to comment.