corehost: Build intermediate library to avoid building twice (#2123)
authorLeandro A. F. Pereira <leandro.pereira@microsoft.com>
Sat, 8 Feb 2020 00:29:12 +0000 (16:29 -0800)
committerGitHub <noreply@github.com>
Sat, 8 Feb 2020 00:29:12 +0000 (16:29 -0800)
Some files are built twice in the hosting layer, so create two separate
static libraries that are then linked with all targets that need them.

Fixes [core-setup/8276](https://github.com/dotnet/core-setup/issues/8276).

25 files changed:
src/installer/corehost/cli/CMakeLists.txt
src/installer/corehost/cli/apphost/CMakeLists.txt
src/installer/corehost/cli/comhost/CMakeLists.txt
src/installer/corehost/cli/common.cmake
src/installer/corehost/cli/dotnet/CMakeLists.txt
src/installer/corehost/cli/exe.cmake
src/installer/corehost/cli/fxr/CMakeLists.txt
src/installer/corehost/cli/hostcommon/CMakeLists.txt [new file with mode: 0644]
src/installer/corehost/cli/hostmisc/CMakeLists.txt [new file with mode: 0644]
src/installer/corehost/cli/hostmisc/longfile.h [moved from src/installer/corehost/common/longfile.h with 100% similarity]
src/installer/corehost/cli/hostmisc/longfile.windows.cpp [moved from src/installer/corehost/common/longfile.windows.cpp with 100% similarity]
src/installer/corehost/cli/hostmisc/pal.h [moved from src/installer/corehost/common/pal.h with 100% similarity]
src/installer/corehost/cli/hostmisc/pal.unix.cpp [moved from src/installer/corehost/common/pal.unix.cpp with 100% similarity]
src/installer/corehost/cli/hostmisc/pal.windows.cpp [moved from src/installer/corehost/common/pal.windows.cpp with 100% similarity]
src/installer/corehost/cli/hostmisc/trace.cpp [moved from src/installer/corehost/common/trace.cpp with 100% similarity]
src/installer/corehost/cli/hostmisc/trace.h [moved from src/installer/corehost/common/trace.h with 100% similarity]
src/installer/corehost/cli/hostmisc/utils.cpp [moved from src/installer/corehost/common/utils.cpp with 100% similarity]
src/installer/corehost/cli/hostmisc/utils.h [moved from src/installer/corehost/common/utils.h with 100% similarity]
src/installer/corehost/cli/hostpolicy/CMakeLists.txt
src/installer/corehost/cli/ijwhost/CMakeLists.txt
src/installer/corehost/cli/lib.cmake
src/installer/corehost/cli/lib_static.cmake
src/installer/corehost/cli/nethost/CMakeLists.txt
src/installer/corehost/cli/test_fx_ver/CMakeLists.txt
src/installer/corehost/cli/winrthost/CMakeLists.txt

index 06140f5..4945f67 100644 (file)
@@ -1,3 +1,5 @@
+add_subdirectory(hostmisc)
+add_subdirectory(hostcommon)
 add_subdirectory(apphost)
 add_subdirectory(dotnet)
 add_subdirectory(fxr)
index eba5c23..580d585 100644 (file)
@@ -18,7 +18,6 @@ endif()
 set(SKIP_VERSIONING 1)
 
 set(SOURCES
-    ../fxr/fx_ver.cpp
     ./bundle/file_entry.cpp
     ./bundle/manifest.cpp
     ./bundle/header.cpp
@@ -30,7 +29,6 @@ set(SOURCES
 )
 
 set(HEADERS
-    ../fxr/fx_ver.h
     ./bundle/file_type.h
     ./bundle/file_entry.h
     ./bundle/manifest.h
index a769f7c..edbf3e7 100644 (file)
@@ -16,14 +16,10 @@ set(SOURCES
     ../fxr_resolver.cpp
     clsidmap.cpp
     ../redirected_error_writer.cpp
-    ../fxr/fx_ver.cpp
-    ../json_parser.cpp
 )
 
 set(HEADERS
     comhost.h
-    ../fxr/fx_ver.h
-    ../json_parser.h
 )
 
 if(CLR_CMAKE_TARGET_WIN32)
@@ -48,3 +44,4 @@ endif()
 
 install(TARGETS comhost DESTINATION corehost)
 install_symbols(comhost corehost)
+target_link_libraries(comhost libhostcommon)
index 865666a..f643777 100644 (file)
@@ -21,29 +21,7 @@ endif()
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
 include_directories(${CMAKE_CURRENT_LIST_DIR}/)
 include_directories(${CMAKE_CURRENT_LIST_DIR}/../)
-include_directories(${CMAKE_CURRENT_LIST_DIR}/../common)
-
-list(APPEND SOURCES
-    ${CMAKE_CURRENT_LIST_DIR}/../common/trace.cpp
-    ${CMAKE_CURRENT_LIST_DIR}/../common/utils.cpp)
-
-list(APPEND HEADERS
-    ${CMAKE_CURRENT_LIST_DIR}/../common/trace.h
-    ${CMAKE_CURRENT_LIST_DIR}/../common/utils.h
-    ${CMAKE_CURRENT_LIST_DIR}/../common/pal.h
-    ${CMAKE_CURRENT_LIST_DIR}/../error_codes.h)
-
-if(CLR_CMAKE_TARGET_WIN32)
-    list(APPEND SOURCES
-        ${CMAKE_CURRENT_LIST_DIR}/../common/pal.windows.cpp
-        ${CMAKE_CURRENT_LIST_DIR}/../common/longfile.windows.cpp)
-    list(APPEND HEADERS
-        ${CMAKE_CURRENT_LIST_DIR}/../common/longfile.h)
-else()
-    list(APPEND SOURCES
-        ${CMAKE_CURRENT_LIST_DIR}/../common/pal.unix.cpp
-        ${VERSION_FILE_PATH})
-endif()
+include_directories(${CMAKE_CURRENT_LIST_DIR}/hostmisc)
 
 set(RESOURCES)
 if(CLR_CMAKE_TARGET_WIN32 AND NOT SKIP_VERSIONING)
@@ -67,12 +45,14 @@ function(set_common_libs TargetType)
         endif()
     endif()
 
-    # Specify the import library to link against for Arm32 build since the default set is minimal
-    if (CLR_CMAKE_TARGET_ARCH_ARM)
-        if (CLR_CMAKE_TARGET_WIN32)
-            target_link_libraries(${DOTNET_PROJECT_NAME} shell32.lib)
-        else()
-            target_link_libraries(${DOTNET_PROJECT_NAME} atomic.a)
+    if (NOT ${TargetType} STREQUAL "lib-static")
+        # Specify the import library to link against for Arm32 build since the default set is minimal
+        if (CLR_CMAKE_TARGET_ARCH_ARM)
+            if (CLR_CMAKE_TARGET_WIN32)
+                target_link_libraries(${DOTNET_PROJECT_NAME} shell32.lib)
+            else()
+                target_link_libraries(${DOTNET_PROJECT_NAME} atomic.a)
+            endif()
         endif()
     endif()
 endfunction()
index e88f40d..4527986 100644 (file)
@@ -5,14 +5,6 @@
 project(dotnet)
 set(DOTNET_PROJECT_NAME "dotnet")
 
-set(SOURCES
-    ../fxr/fx_ver.cpp
-)
-
-set(HEADERS
-    ../fxr/fx_ver.h
-)
-
 if(CLR_CMAKE_TARGET_WIN32)
     list(APPEND SOURCES
         dotnet.manifest)
index f941cd7..3728e05 100644 (file)
@@ -16,10 +16,10 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/fxr)
 list(APPEND SOURCES
     ${CMAKE_CURRENT_LIST_DIR}/fxr_resolver.cpp
     ${CMAKE_CURRENT_LIST_DIR}/../corehost.cpp
-    ${CMAKE_CURRENT_LIST_DIR}/../common/trace.cpp
-    ${CMAKE_CURRENT_LIST_DIR}/../common/utils.cpp)
+)
 
 add_executable(${DOTNET_PROJECT_NAME} ${SOURCES} ${RESOURCES})
+target_link_libraries(${DOTNET_PROJECT_NAME} libhostmisc)
 
 if(NOT CLR_CMAKE_TARGET_WIN32)
     disable_pax_mprotect(${DOTNET_PROJECT_NAME})
index ee83dc4..3e14083 100644 (file)
@@ -11,20 +11,9 @@ include_directories(../json)
 
 # CMake does not recommend using globbing since it messes with the freshness checks
 set(SOURCES
-    ../deps_format.cpp
-    ../deps_entry.cpp
-    ../host_startup_info.cpp
-    ../roll_forward_option.cpp
-    ../runtime_config.cpp
-    ../fx_definition.cpp
-    ../fx_reference.cpp
-    ../version.cpp
-    ../version_compatibility_range.cpp
-    ../json_parser.cpp
     ./command_line.cpp
     ./corehost_init.cpp
     ./hostfxr.cpp
-    ./fx_ver.cpp
     ./fx_muxer.cpp
     ./fx_resolver.cpp
     ./fx_resolver.messages.cpp
@@ -37,21 +26,12 @@ set(SOURCES
 
 set(HEADERS
     ../corehost_context_contract.h
-    ../deps_format.h
-    ../deps_entry.h
-    ../host_startup_info.h
     ../hostpolicy.h
-    ../runtime_config.h
     ../fx_definition.h
     ../fx_reference.h
-    ../roll_forward_option.h
     ../roll_fwd_on_no_candidate_fx_option.h
-    ../version.h
-    ../version_compatibility_range.h
-    ../json_parser.h
     ./command_line.h
     ./corehost_init.h
-    ./fx_ver.h
     ./fx_muxer.h
     ./fx_resolver.h
     ./framework_info.h
@@ -65,3 +45,4 @@ include(../lib.cmake)
 
 install(TARGETS hostfxr DESTINATION corehost)
 install_symbols(hostfxr corehost)
+target_link_libraries(hostfxr libhostcommon)
diff --git a/src/installer/corehost/cli/hostcommon/CMakeLists.txt b/src/installer/corehost/cli/hostcommon/CMakeLists.txt
new file mode 100644 (file)
index 0000000..deac261
--- /dev/null
@@ -0,0 +1,44 @@
+# Licensed to the .NET Foundation under one or more agreements.
+# The .NET Foundation licenses this file to you under the MIT license.
+# See the LICENSE file in the project root for more information.
+
+project(hostcommon)
+
+set(DOTNET_PROJECT_NAME "hostcommon")
+
+# Include directories
+include_directories(../fxr)
+include_directories(../json)
+
+# CMake does not recommend using globbing since it messes with the freshness checks
+set(SOURCES
+    ../json_parser.cpp
+    ../deps_format.cpp
+    ../deps_entry.cpp
+    ../host_startup_info.cpp
+    ../roll_forward_option.cpp
+    ../fx_definition.cpp
+    ../fx_reference.cpp
+    ../fxr/fx_ver.cpp
+    ../version.cpp
+    ../version_compatibility_range.cpp
+    ../runtime_config.cpp
+)
+
+set(HEADERS
+    ../json_parser.h
+    ../deps_format.h
+    ../deps_entry.h
+    ../host_startup_info.h
+    ../roll_forward_option.h
+    ../fx_definition.h
+    ../fx_reference.h
+    ../fxr/fx_ver.h
+    ../version.h
+    ../version_compatibility_range.h
+    ../runtime_config.h
+)
+
+set(SKIP_VERSIONING 1)
+include(../lib_static.cmake)
+
diff --git a/src/installer/corehost/cli/hostmisc/CMakeLists.txt b/src/installer/corehost/cli/hostmisc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8e0c24c
--- /dev/null
@@ -0,0 +1,38 @@
+# Licensed to the .NET Foundation under one or more agreements.
+# The .NET Foundation licenses this file to you under the MIT license.
+# See the LICENSE file in the project root for more information.
+
+project(hostmisc)
+
+set(DOTNET_PROJECT_NAME "hostmisc")
+
+# CMake does not recommend using globbing since it messes with the freshness checks
+set(SOURCES
+    trace.cpp
+    utils.cpp
+    ../fxr/fx_ver.cpp
+)
+
+set(HEADERS
+    trace.h
+    utils.h
+    pal.h
+    ../../error_codes.h
+    ../fxr/fx_ver.h
+)
+
+if(CLR_CMAKE_TARGET_WIN32)
+    list(APPEND SOURCES
+        pal.windows.cpp
+        longfile.windows.cpp)
+    list(APPEND HEADERS
+        longfile.h)
+else()
+    list(APPEND SOURCES
+        pal.unix.cpp
+        ${VERSION_FILE_PATH})
+endif()
+
+set(SKIP_VERSIONING 1)
+include(../lib_static.cmake)
+
index da157c9..b19c743 100644 (file)
@@ -16,44 +16,24 @@ set(SOURCES
     ./breadcrumbs.cpp
     ./coreclr.cpp
     ./deps_resolver.cpp
-    ./hostpolicy.cpp
     ./hostpolicy_context.cpp
+    ./hostpolicy.cpp
     ./hostpolicy_init.cpp
-    ../roll_forward_option.cpp
-    ../runtime_config.cpp
-    ../fxr/fx_ver.cpp
-    ../host_startup_info.cpp
-    ../deps_format.cpp
-    ../deps_entry.cpp
-    ../fx_definition.cpp
-    ../fx_reference.cpp
-    ../version.cpp
-    ../version_compatibility_range.cpp
-    ../json_parser.cpp
 )
 
 set(HEADERS
     ./args.h
     ./breadcrumbs.h
     ./coreclr.h
+    ../corehost_context_contract.h
     ./deps_resolver.h
     ./hostpolicy_context.h
-    ./hostpolicy_init.h
-    ../corehost_context_contract.h
     ../hostpolicy.h
-    ../runtime_config.h
-    ../fxr/fx_ver.h
-    ../host_startup_info.h
-    ../deps_format.h
-    ../deps_entry.h
-    ../fx_definition.h
-    ../fx_reference.h
-    ../version.h
-    ../version_compatibility_range.h
-    ../json_parser.h
+    ./hostpolicy_init.h
 )
 
 include(../lib.cmake)
 
 install(TARGETS hostpolicy DESTINATION corehost)
 install_symbols(hostpolicy corehost)
+target_link_libraries(hostpolicy libhostcommon)
index a56d2e4..c89996f 100644 (file)
@@ -15,9 +15,6 @@ set(SOURCES
     ijwthunk.cpp
     ijwhost.cpp
     ../fxr_resolver.cpp
-    ../../common/trace.cpp
-    ../../common/utils.cpp
-    ../fxr/fx_ver.cpp
     pedecoder.cpp
     bootstrap_thunk_chunk.cpp
     ${ARCH_SPECIFIC_FOLDER_NAME}/bootstrap_thunk.cpp
index 18856b2..d2305fd 100644 (file)
@@ -11,6 +11,7 @@ add_definitions(-D_NO_PPLXIMP)
 add_definitions(-DEXPORT_SHARED_API=1)
 
 add_library(${DOTNET_PROJECT_NAME} SHARED ${SOURCES} ${RESOURCES})
+target_link_libraries(${DOTNET_PROJECT_NAME} libhostmisc)
 
 set_target_properties(${DOTNET_PROJECT_NAME} PROPERTIES MACOSX_RPATH TRUE)
 
index 6c4b503..8135e9c 100644 (file)
@@ -15,4 +15,4 @@ add_library(lib${DOTNET_PROJECT_NAME} STATIC ${SOURCES} ${RESOURCES})
 set_target_properties(lib${DOTNET_PROJECT_NAME} PROPERTIES MACOSX_RPATH TRUE)
 set_target_properties(lib${DOTNET_PROJECT_NAME} PROPERTIES PREFIX "")
 
-set_common_libs("lib")
+set_common_libs("lib-static")
index aad5d0d..af3edaa 100644 (file)
@@ -13,7 +13,6 @@ include_directories(../fxr)
 set(SOURCES
     nethost.cpp
     ../fxr_resolver.cpp
-    ../fxr/fx_ver.cpp
 )
 
 if(CLR_CMAKE_TARGET_WIN32)
index 72a4d57..8777820 100644 (file)
@@ -6,22 +6,11 @@ project(test_fx_ver)
 set(EXE_NAME "test_fx_ver")
 
 include_directories(../fxr)
-include_directories(../../common)
+include_directories(../hostmisc)
 
 set(SOURCES
     test_fx_ver.cpp
-    ../fxr/fx_ver.cpp
-    ../../common/trace.cpp
-    ../../common/utils.cpp)
-
-if(CLR_CMAKE_TARGET_WIN32)
-    list(APPEND SOURCES
-        ../../common/pal.windows.cpp
-        ../../common/longfile.windows.cpp)
-else()
-    list(APPEND SOURCES
-        ../../common/pal.unix.cpp)
-endif()
+)
 
 if(CLR_CMAKE_HOST_WIN32)
     add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
@@ -32,6 +21,7 @@ else()
 endif()
 
 add_executable(${EXE_NAME} ${SOURCES})
+target_link_libraries(${EXE_NAME} libhostmisc libhostcommon)
 
 install(TARGETS ${EXE_NAME} DESTINATION corehost_test)
 
index e364f3a..6b28164 100644 (file)
@@ -14,9 +14,6 @@ set (SOURCES
     winrthost.cpp
     ../redirected_error_writer.cpp
     ../fxr_resolver.cpp
-    ../../common/trace.cpp
-    ../../common/utils.cpp
-    ../fxr/fx_ver.cpp
 )
 
 if(CLR_CMAKE_TARGET_WIN32)
@@ -33,7 +30,7 @@ if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_AR
     target_link_libraries(winrthost Advapi32.lib Ole32.lib OleAut32.lib)
 endif()
 
-target_link_libraries(winrthost RuntimeObject.lib)
+target_link_libraries(winrthost RuntimeObject.lib libhostmisc libhostcommon)
 
 install(TARGETS winrthost DESTINATION corehost)
 install_symbols(winrthost corehost)