Skip to content

Commit 8d6cd81

Browse files
authored
Reorganize CoreCLR native build to reduce CMake reconfigures when the build system is untouched (#49906)
1 parent 4965383 commit 8d6cd81

File tree

71 files changed

+450
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+450
-380
lines changed

eng/Subsets.props

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</PropertyGroup>
4343

4444
<PropertyGroup>
45-
<DefaultCoreClrSubsets>clr.runtime+clr.jit+clr.alljits+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.iltools+clr.packages</DefaultCoreClrSubsets>
45+
<DefaultCoreClrSubsets>clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages</DefaultCoreClrSubsets>
4646

4747
<DefaultMonoSubsets Condition="'$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
4848
<DefaultMonoSubsets Condition="'$(MonoAOTEnableLLVM)' == 'true' and '$(MonoAOTLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
@@ -81,8 +81,9 @@
8181
<SubsetName Include="Clr.DacTools" Description="Managed tools that support building a runtime that supports debugging (such as DacTableGen)." />
8282
<SubsetName Include="Clr.ILTools" Description="The CoreCLR IL tools." />
8383
<SubsetName Include="Clr.Runtime" Description="The CoreCLR .NET runtime." />
84-
<SubsetName Include="Clr.PalTests" Description="The CoreCLR PAL tests." />
85-
<SubsetName Include="Clr.PalTestList" Description="Generate the list of the CoreCLR PAL tests. When using the command line, use Clr.PalTests instead." />
84+
<SubsetName Include="Clr.Native" Description="All CoreCLR native non-test components, including the runtime, jits, and other native tools." />
85+
<SubsetName Include="Clr.PalTests" OnDemand="true" Description="The CoreCLR PAL tests." />
86+
<SubsetName Include="Clr.PalTestList" OnDemand="true" Description="Generate the list of the CoreCLR PAL tests. When using the command line, use Clr.PalTests instead." />
8687
<SubsetName Include="Clr.Jit" Description="The JIT for the CoreCLR .NET runtime." />
8788
<SubsetName Include="Clr.AllJits" Description="All of the cross-targeting JIT compilers for the CoreCLR .NET runtime." />
8889
<SubsetName Include="Clr.CoreLib" Description="The managed System.Private.CoreLib library for CoreCLR." />
@@ -146,14 +147,18 @@
146147
<ProjectToBuild Include="$(CoreClrProjectRoot)System.Private.CoreLib\System.Private.CoreLib.csproj" Category="clr" />
147148
</ItemGroup>
148149

149-
<ItemGroup Condition="'$(TargetOS)' == 'windows' and ($(_subset.Contains('+clr.dactools+')) or $(_subset.Contains('+clr.runtime+')))">
150+
<ItemGroup Condition="'$(TargetOS)' == 'windows' and ($(_subset.Contains('+clr.dactools+')) or $(_subset.Contains('+clr.runtime+')) or $(_subset.Contains('+clr.native+')))">
150151
<ProjectToBuild Include="$(CoreClrProjectRoot)ToolBox\SOS\DacTableGen\DacTableGen.csproj;
151152
$(CoreClrProjectRoot)ToolBox\SOS\DIALib\DIALib.ilproj"
152153
Category="clr"/>
153154
</ItemGroup>
154155

155156
<PropertyGroup Condition="$(_subset.Contains('+clr.runtime+'))">
156-
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrRuntimeSubset=true;ClrJitSubset=true</ClrRuntimeBuildSubsets>
157+
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrRuntimeSubset=true</ClrRuntimeBuildSubsets>
158+
</PropertyGroup>
159+
160+
<PropertyGroup Condition="$(_subset.Contains('+clr.native+'))">
161+
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrFullNativeBuild=true</ClrRuntimeBuildSubsets>
157162
</PropertyGroup>
158163

159164
<PropertyGroup Condition="$(_subset.Contains('+clr.jit+'))">
@@ -165,7 +170,7 @@
165170
</PropertyGroup>
166171

167172
<PropertyGroup Condition="$(_subset.Contains('+clr.alljits+'))">
168-
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrAllJitsSubset=true;ClrJitSubset=true</ClrRuntimeBuildSubsets>
173+
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrAllJitsSubset=true</ClrRuntimeBuildSubsets>
169174
</PropertyGroup>
170175

171176
<PropertyGroup Condition="$(_subset.Contains('+clr.iltools+'))">

eng/native/build-commons.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ build_native()
7272
platformArch="$2"
7373
cmakeDir="$3"
7474
intermediatesDir="$4"
75-
cmakeArgs="$5"
76-
message="$6"
75+
target="$5"
76+
cmakeArgs="$6"
77+
message="$7"
7778

7879
# All set to commence the build
79-
echo "Commencing build of \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"
80+
echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"
8081

8182
if [[ "$targetOS" == OSX || "$targetOS" == MacCatalyst ]]; then
8283
if [[ "$platformArch" == x64 ]]; then
@@ -188,20 +189,29 @@ EOF
188189
pushd "$intermediatesDir"
189190

190191
buildTool="$SCAN_BUILD_COMMAND -o $__BinDir/scan-build-log $buildTool"
191-
echo "Executing $buildTool install -j $__NumProc"
192-
"$buildTool" install -j "$__NumProc"
192+
echo "Executing $buildTool $target -j $__NumProc"
193+
"$buildTool" $target -j "$__NumProc"
193194
exit_code="$?"
194195

195196
popd
196197
else
197198
cmake_command=cmake
198199
if [[ "$build_arch" == "wasm" ]]; then
199-
cmake_command="emcmake $cmake_command"
200-
fi
200+
cmake_command="emcmake cmake"
201+
echo "Executing $cmake_command --build \"$intermediatesDir\" --target $target -- -j $__NumProc"
202+
$cmake_command --build "$intermediatesDir" --target $target -- -j "$__NumProc"
203+
exit_code="$?"
204+
else
205+
# For non-wasm Unix scenarios, we may have to use an old version of CMake that doesn't support
206+
# multiple targets. Instead, directly invoke the build tool to build multiple targets in one invocation.
207+
pushd "$intermediatesDir"
201208

202-
echo "Executing $cmake_command --build \"$intermediatesDir\" --target install -- -j $__NumProc"
203-
$cmake_command --build "$intermediatesDir" --target install -- -j "$__NumProc"
204-
exit_code="$?"
209+
echo "Executing $buildTool $target -j $__NumProc"
210+
"$buildTool" $target -j "$__NumProc"
211+
exit_code="$?"
212+
213+
popd
214+
fi
205215
fi
206216

207217
CFLAGS="${SAVED_CFLAGS}"

eng/native/functions.cmake

Lines changed: 95 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ function(compile_asm)
206206
set(${COMPILE_ASM_OUTPUT_OBJECTS} ${ASSEMBLED_OBJECTS} PARENT_SCOPE)
207207
endfunction()
208208

209+
# add_component(componentName [targetName] [EXCLUDE_FROM_ALL])
210+
function(add_component componentName)
211+
if (${ARGC} GREATER 2 OR ${ARGC} EQUAL 2)
212+
set(componentTargetName "${ARGV1}")
213+
else()
214+
set(componentTargetName "${componentName}")
215+
endif()
216+
if (${ARGC} EQUAL 3 AND "${ARG2}" STREQUAL "EXCLUDE_FROM_ALL")
217+
set(exclude_from_all_flag "EXCLUDE_FROM_ALL")
218+
endif()
219+
get_property(definedComponents GLOBAL PROPERTY CLR_CMAKE_COMPONENTS)
220+
list (FIND definedComponents "${componentName}" componentIndex)
221+
if (${componentIndex} EQUAL -1)
222+
list (APPEND definedComponents "${componentName}")
223+
add_custom_target("${componentTargetName}"
224+
COMMAND "${CMAKE_COMMAND}" "-DCMAKE_INSTALL_COMPONENT=${componentName}" "-DBUILD_TYPE=$<CONFIG>" -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
225+
${exclude_from_all_flag})
226+
set_property(GLOBAL PROPERTY CLR_CMAKE_COMPONENTS ${definedComponents})
227+
endif()
228+
endfunction()
229+
209230
function(generate_exports_file)
210231
set(INPUT_LIST ${ARGN})
211232
list(GET INPUT_LIST -1 outputFilename)
@@ -248,12 +269,29 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix)
248269
PROPERTIES GENERATED TRUE)
249270
endfunction()
250271

272+
function (get_symbol_file_name targetName outputSymbolFilename)
273+
if (CLR_CMAKE_HOST_UNIX)
274+
if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
275+
set(strip_destination_file $<TARGET_FILE:${targetName}>.dwarf)
276+
else ()
277+
set(strip_destination_file $<TARGET_FILE:${targetName}>.dbg)
278+
endif ()
279+
280+
set(${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE)
281+
else(CLR_CMAKE_HOST_UNIX)
282+
# We can't use the $<TARGET_PDB_FILE> generator expression here since
283+
# the generator expression isn't supported on resource DLLs.
284+
set(${outputSymbolFilename} $<TARGET_FILE_DIR:${targetName}>/$<TARGET_FILE_PREFIX:${targetName}>$<TARGET_FILE_BASE_NAME:${targetName}>.pdb PARENT_SCOPE)
285+
endif(CLR_CMAKE_HOST_UNIX)
286+
endfunction()
287+
251288
function(strip_symbols targetName outputFilename)
289+
get_symbol_file_name(${targetName} strip_destination_file)
290+
set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
252291
if (CLR_CMAKE_HOST_UNIX)
253292
set(strip_source_file $<TARGET_FILE:${targetName}>)
254293

255294
if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
256-
set(strip_destination_file ${strip_source_file}.dwarf)
257295

258296
# Ensure that dsymutil and strip are present
259297
find_program(DSYMUTIL dsymutil)
@@ -282,7 +320,6 @@ function(strip_symbols targetName outputFilename)
282320
COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file}"
283321
)
284322
else (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
285-
set(strip_destination_file ${strip_source_file}.dbg)
286323

287324
add_custom_command(
288325
TARGET ${targetName}
@@ -294,26 +331,13 @@ function(strip_symbols targetName outputFilename)
294331
COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file}"
295332
)
296333
endif (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
297-
298-
set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
299-
else(CLR_CMAKE_HOST_UNIX)
300-
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
301-
if(is_multi_config)
302-
# We can't use the $<TARGET_PDB_FILE> generator expression here since
303-
# the generator expression isn't supported on resource DLLs.
304-
set(${outputFilename} ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb PARENT_SCOPE)
305-
else()
306-
# We can't use the $<TARGET_PDB_FILE> generator expression here since
307-
# the generator expression isn't supported on resource DLLs.
308-
set(${outputFilename} ${CMAKE_CURRENT_BINARY_DIR}/${targetName}.pdb PARENT_SCOPE)
309-
endif()
310334
endif(CLR_CMAKE_HOST_UNIX)
311335
endfunction()
312336

313337
function(install_with_stripped_symbols targetName kind destination)
314338
if(NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
315339
strip_symbols(${targetName} symbol_file)
316-
install_symbols(${symbol_file} ${destination})
340+
install_symbol_file(${symbol_file} ${destination} ${ARGN})
317341
endif()
318342

319343
if ((CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) AND ("${kind}" STREQUAL "TARGETS"))
@@ -328,59 +352,75 @@ function(install_with_stripped_symbols targetName kind destination)
328352
else()
329353
message(FATAL_ERROR "The `kind` argument has to be either TARGETS or PROGRAMS, ${kind} was provided instead")
330354
endif()
331-
install(${kind} ${install_source} DESTINATION ${destination})
355+
install(${kind} ${install_source} DESTINATION ${destination} ${ARGN})
332356
endfunction()
333357

334-
function(install_symbols symbol_file destination_path)
358+
function(install_symbol_file symbol_file destination_path)
335359
if(CLR_CMAKE_TARGET_WIN32)
336-
install(FILES ${symbol_file} DESTINATION ${destination_path}/PDB)
360+
install(FILES ${symbol_file} DESTINATION ${destination_path}/PDB ${ARGN})
337361
else()
338-
install(FILES ${symbol_file} DESTINATION ${destination_path})
362+
install(FILES ${symbol_file} DESTINATION ${destination_path} ${ARGN})
339363
endif()
340364
endfunction()
341365

342-
# install_clr(TARGETS TARGETS targetName [targetName2 ...] [ADDITIONAL_DESTINATIONS destination])
366+
# install_clr(TARGETS targetName [targetName2 ...] [DESTINATIONS destination [destination2 ...]] [COMPONENT componentName])
343367
function(install_clr)
344-
set(multiValueArgs TARGETS ADDITIONAL_DESTINATIONS)
345-
cmake_parse_arguments(INSTALL_CLR "" "" "${multiValueArgs}" ${ARGV})
368+
set(multiValueArgs TARGETS DESTINATIONS)
369+
set(singleValueArgs COMPONENT)
370+
set(options "")
371+
cmake_parse_arguments(INSTALL_CLR "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGV})
346372

347373
if ("${INSTALL_CLR_TARGETS}" STREQUAL "")
348374
message(FATAL_ERROR "At least one target must be passed to install_clr(TARGETS )")
349375
endif()
350376

351-
set(destinations ".")
377+
if ("${INSTALL_CLR_DESTINATIONS}" STREQUAL "")
378+
message(FATAL_ERROR "At least one destination must be passed to install_clr.")
379+
endif()
380+
381+
set(destinations "")
382+
383+
if (NOT "${INSTALL_CLR_DESTINATIONS}" STREQUAL "")
384+
list(APPEND destinations ${INSTALL_CLR_DESTINATIONS})
385+
endif()
352386

353-
if (NOT "${INSTALL_CLR_ADDITIONAL_DESTINATIONS}" STREQUAL "")
354-
list(APPEND destinations ${INSTALL_CLR_ADDITIONAL_DESTINATIONS})
387+
if ("${INSTALL_CLR_COMPONENT}" STREQUAL "")
388+
set(INSTALL_CLR_COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
355389
endif()
356390

357391
foreach(targetName ${INSTALL_CLR_TARGETS})
358-
list(FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
359-
if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
360-
if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
361-
strip_symbols(${targetName} symbol_file)
362-
endif()
392+
if (NOT "${INSTALL_CLR_COMPONENT}" STREQUAL "${targetName}")
393+
get_property(definedComponents GLOBAL PROPERTY CLR_CMAKE_COMPONENTS)
394+
list(FIND definedComponents "${INSTALL_CLR_COMPONENT}" componentIdx)
395+
if (${componentIdx} EQUAL -1)
396+
message(FATAL_ERROR "The ${INSTALL_CLR_COMPONENT} component is not defined. Add a call to `add_component(${INSTALL_CLR_COMPONENT})` to define the component in the build.")
397+
endif()
398+
add_dependencies(${INSTALL_CLR_COMPONENT} ${targetName})
399+
endif()
400+
get_target_property(targetType ${targetName} TYPE)
401+
if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType}" STREQUAL "STATIC")
402+
get_symbol_file_name(${targetName} symbol_file)
403+
endif()
363404

364-
foreach(destination ${destinations})
365-
# We don't need to install the export libraries for our DLLs
366-
# since they won't be directly linked against.
367-
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${destination})
368-
if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
369-
install_symbols(${symbol_file} ${destination})
370-
endif()
405+
foreach(destination ${destinations})
406+
# We don't need to install the export libraries for our DLLs
407+
# since they won't be directly linked against.
408+
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT})
409+
if (NOT "${symbolFile}" STREQUAL "")
410+
install_symbol_file(${symbol_file} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT})
411+
endif()
371412

372-
if(CLR_CMAKE_PGO_INSTRUMENT)
373-
if(WIN32)
374-
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
375-
if(is_multi_config)
376-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL)
377-
else()
378-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL)
379-
endif()
380-
endif()
413+
if(CLR_CMAKE_PGO_INSTRUMENT)
414+
if(WIN32)
415+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
416+
if(is_multi_config)
417+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL COMPONENT ${INSTALL_CLR_COMPONENT})
418+
else()
419+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL COMPONENT ${INSTALL_CLR_COMPONENT})
381420
endif()
382-
endforeach()
383-
endif()
421+
endif()
422+
endif()
423+
endforeach()
384424
endforeach()
385425
endfunction()
386426

@@ -427,45 +467,29 @@ if (CMAKE_VERSION VERSION_LESS "3.16")
427467
endfunction()
428468
endif()
429469

430-
function(_add_executable)
470+
function(add_executable_clr)
431471
if(NOT WIN32)
432472
add_executable(${ARGV} ${VERSION_FILE_PATH})
433473
disable_pax_mprotect(${ARGV})
434474
else()
435475
add_executable(${ARGV})
436476
endif(NOT WIN32)
437-
list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
438-
if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
439-
set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
477+
if(NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
478+
strip_symbols(${ARGV0} symbolFile)
440479
endif()
441480
endfunction()
442481

443-
function(_add_library)
482+
function(add_library_clr)
444483
if(NOT WIN32 AND "${ARGV1}" STREQUAL "SHARED")
445484
add_library(${ARGV} ${VERSION_FILE_PATH})
446485
else()
447486
add_library(${ARGV})
448487
endif(NOT WIN32 AND "${ARGV1}" STREQUAL "SHARED")
449-
list(FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
450-
if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
451-
set_target_properties(${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
452-
endif()
453-
endfunction()
454-
455-
function(_install)
456-
if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
457-
install(${ARGV})
488+
if("${ARGV1}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
489+
strip_symbols(${ARGV0} symbolFile)
458490
endif()
459491
endfunction()
460492

461-
function(add_library_clr)
462-
_add_library(${ARGV})
463-
endfunction()
464-
465-
function(add_executable_clr)
466-
_add_executable(${ARGV})
467-
endfunction()
468-
469493
# add_linker_flag(Flag [Config1 Config2 ...])
470494
function(add_linker_flag Flag)
471495
if (ARGN STREQUAL "")

0 commit comments

Comments
 (0)