Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building singlefilehost with clr partition. #48254

Merged
2 commits merged into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ if(FEATURE_STANDALONE_GC)
endif (CLR_CMAKE_BUILD_SUBSET_RUNTIME)
endif(FEATURE_STANDALONE_GC)

if(NOT CLR_CROSS_COMPONENTS_BUILD)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost/apphost/static Corehost.Static)
endif()

if (CLR_CMAKE_HOST_UNIX)
include_directories("pal/inc")
include_directories("pal/inc/rt")
Expand Down
15 changes: 7 additions & 8 deletions src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

# we need to define this library before adding .def fiels to sources.
add_library_clr(coreclr_static
STATIC
${CLR_SOURCES}
)

if (CLR_CMAKE_TARGET_WIN32)
preprocess_file(${DEF_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/coreclr.def)

Expand Down Expand Up @@ -64,11 +71,6 @@ add_library_clr(coreclr
${CLR_SOURCES}
)

add_library_clr(coreclr_static
STATIC
${CLR_SOURCES}
)

add_custom_target(coreclr_exports DEPENDS ${EXPORTS_FILE})
add_custom_target(coreclr_def DEPENDS ${DEF_FILE})

Expand Down Expand Up @@ -222,8 +224,5 @@ endif(CLR_CMAKE_TARGET_WIN32)
# add the install targets
install_clr(TARGETS coreclr ADDITIONAL_DESTINATIONS sharedFramework)

# publish coreclr_static lib
_install(TARGETS coreclr_static DESTINATION lib)

# Enable profile guided optimization
add_pgo(coreclr)
11 changes: 5 additions & 6 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,14 @@ else()
clr_unknown_arch()
endif()

set(SOURCES
set(JIT_CORE_SOURCES
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was needed to not include resources in the statically linked JIT.

${JIT_SOURCES}
${JIT_HEADERS}
${JIT_RESOURCES}
)

convert_to_absolute_path(SOURCES ${SOURCES})
convert_to_absolute_path(JIT_CORE_SOURCES ${JIT_CORE_SOURCES})
convert_to_absolute_path(JIT_ARCH_SOURCES ${JIT_ARCH_SOURCES})
convert_to_absolute_path(JIT_RESOURCES ${JIT_RESOURCES})

# Also convert the per-architecture sources to absolute paths, if the subdirs want to use them.

Expand All @@ -371,7 +371,6 @@ if(CLR_CMAKE_TARGET_WIN32)
set(JIT_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/ClrJit.exports.def)
preprocess_file (${CLRJIT_EXPORTS} ${JIT_EXPORTS_FILE})

set(JIT_CORE_SOURCES ${SOURCES})
set(JIT_DEF_FILE ${JIT_EXPORTS_FILE})
else()
set(CLRJIT_EXPORTS ${CMAKE_CURRENT_LIST_DIR}/ClrJit.PAL.exports)
Expand All @@ -386,7 +385,6 @@ else()

set_exports_linker_option(${JIT_EXPORTS_FILE})
set(JIT_EXPORTS_LINKER_OPTION ${EXPORTS_LINKER_OPTION})
set(JIT_CORE_SOURCES ${SOURCES})
endif()

add_custom_target(jit_exports DEPENDS ${JIT_EXPORTS_FILE})
Expand Down Expand Up @@ -432,6 +430,7 @@ function(add_jit jitName)
add_library_clr(${jitName}
SHARED
${JIT_CORE_SOURCES}
${JIT_RESOURCES}
${JIT_ARCH_SOURCES}
${JIT_DEF_FILE}
${JIT_DLL_MAIN_FILE}
Expand Down Expand Up @@ -506,4 +505,4 @@ if (CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_PGO_INSTRUMENT)
find_path(PGORT_DIR ${PGORT_DLL} REQUIRED)
_install(FILES "${PGORT_DIR}/${PGORT_DLL}" DESTINATION ${CMAKE_INSTALL_PREFIX})
_install(FILES "${PGORT_DIR}/${PGORT_DLL}" DESTINATION ${CMAKE_INSTALL_PREFIX}/sharedFramework)
endif ()
endif ()
14 changes: 12 additions & 2 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ if(CLR_CMAKE_TARGET_ARCH_AMD64)
)
elseif(CLR_CMAKE_TARGET_ARCH_I386)
set(VM_SOURCES_DAC_AND_WKS_ARCH
gcdecode.cpp
exinfo.cpp
${ARCH_SOURCES_DIR}/cgenx86.cpp
${ARCH_SOURCES_DIR}/excepx86.cpp
Expand Down Expand Up @@ -888,12 +887,23 @@ if (CLR_CMAKE_TARGET_WIN32)
list(APPEND VM_SOURCES_DAC ${VM_HEADERS_DAC})
endif(CLR_CMAKE_TARGET_WIN32)

#these two files we need to compile differently for standalone and mergeable flavors of WKS
# these two files we need to compile differently for standalone and mergeable flavors of WKS
set (VM_SOURCES_WKS_SPECIAL
codeman.cpp
ceemain.cpp
)

# gcdecode.cpp is included by both JIT and VM. to avoid duplicate definitions we need to
# treat it in a special way when statically linking with both VM and JIT
if(CLR_CMAKE_TARGET_ARCH_I386)
list(APPEND VM_SOURCES_DAC
gcdecode.cpp
)
list(APPEND VM_SOURCES_WKS_SPECIAL
gcdecode.cpp
)
endif()

convert_to_absolute_path(VM_SOURCES_WKS ${VM_SOURCES_WKS})
convert_to_absolute_path(VM_SOURCES_WKS_ARCH_ASM ${VM_SOURCES_WKS_ARCH_ASM})
convert_to_absolute_path(VM_SOURCES_DAC ${VM_SOURCES_DAC})
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/gcdecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
/* GCDecoder.cpp is a common source file bewtween VM and JIT/IL */
/* GCDecoder.cpp is located in $COM99/inc */

// we need only one copy when embedding
#if !defined(CORECLR_EMBEDDED)
#include "gcdecoder.cpp"
#endif
2 changes: 0 additions & 2 deletions src/installer/corehost.proj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<BuildArgs Condition="'$(Compiler)' != ''">$(BuildArgs) $(Compiler)</BuildArgs>
<BuildArgs Condition="'$(CMakeArgs)' != ''">$(BuildArgs) $(CMakeArgs)</BuildArgs>
<BuildArgs>$(BuildArgs) -coreclrartifacts $(CoreCLRArtifactsPath)</BuildArgs>
<BuildArgs>$(BuildArgs) -nativelibsartifacts $(LibrariesArtifactsPath)/bin/native/$(NetCoreAppCurrent)-$(TargetOS)-$(LibrariesConfiguration)-$(TargetArchitecture)</BuildArgs>
<BuildArgs Condition="'$(Ninja)' == 'true'">$(BuildArgs) -ninja</BuildArgs>
<BuildArgs>$(BuildArgs) -runtimeflavor $(RuntimeFlavor)</BuildArgs>
</PropertyGroup>
Expand Down Expand Up @@ -92,7 +91,6 @@
<BuildArgs Condition="'$(IncrementalNativeBuild)' == 'true'">$(BuildArgs) incremental-native-build</BuildArgs>
<BuildArgs>$(BuildArgs) rootdir $(RepoRoot)</BuildArgs>
<BuildArgs>$(BuildArgs) coreclrartifacts $(CoreCLRArtifactsPath)</BuildArgs>
<BuildArgs>$(BuildArgs) nativelibsartifacts $(LibrariesArtifactsPath)/bin/native/$(NetCoreAppCurrent)-$(TargetOS)-$(LibrariesConfiguration)-$(TargetArchitecture)</BuildArgs>
<BuildArgs Condition="'$(Ninja)' == 'true'">$(BuildArgs) ninja</BuildArgs>
<BuildArgs>$(BuildArgs) runtimeflavor $(RuntimeFlavor)</BuildArgs>
<BuildArgs>$(BuildArgs) runtimeconfiguration $(RuntimeConfiguration)</BuildArgs>
Expand Down
1 change: 0 additions & 1 deletion src/native/corehost/apphost/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.

add_subdirectory(static)
add_subdirectory(standalone)
1 change: 1 addition & 0 deletions src/native/corehost/apphost/apphost.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "pal.h"
#include "trace.h"
#include "utils.h"
#include <shellapi.h>

namespace
{
Expand Down
103 changes: 35 additions & 68 deletions src/native/corehost/apphost/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ include(../../fxr/files.cmake)
include(../../hostpolicy/files.cmake)
include(../../hostcommon/files.cmake)

if(MSVC)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4996>)
Copy link
Member Author

@VSadov VSadov Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these /wd defined for everything in host.native .
Since we build this separately from others now, I had to add the options here.

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4267>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4018>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4200>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4244>)
# Host components don't try to handle asynchronous exceptions
add_compile_options(/EHsc)
elseif (CMAKE_CXX_COMPILER_ID MATCHES GNU)
# Prevents libc from calling pthread_cond_destroy on static objects in
# dlopen()'ed library which we dlclose() in pal::unload_library.
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>)
endif()

if(CLR_CMAKE_TARGET_WIN32)
list(APPEND SOURCES
../apphost.windows.cpp)
Expand Down Expand Up @@ -84,59 +98,18 @@ if(CLR_CMAKE_TARGET_WIN32)
# Disable manifest generation into the file .exe on Windows
add_linker_flag("/MANIFEST:NO")

get_property(ALL_COMPILE_OPTIONS TARGET ${PROJECT_NAME} PROPERTY COMPILE_OPTIONS)
string(TOUPPER ${RUNTIME_CONFIG} UPPERCASE_RUNTIME_CONFIG)

# make sure that certain compiler and linker settings match the runtime config
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very happy that this is gone. It seemed very fragile.

# we need to ensure that to be able to link with coreclr in mixed builds (ex: Debug with Release runtime)
if(UPPERCASE_RUNTIME_CONFIG STREQUAL DEBUG OR UPPERCASE_RUNTIME_CONFIG STREQUAL CHECKED)
# add_compile_options(/MTd)
# per-config options will win, so we have to use this syntax to override
set_property(TARGET ${PROJECT_NAME} PROPERTY
COMPILE_OPTIONS "${ALL_COMPILE_OPTIONS};$<$<CONFIG:DEBUG>:/MTd>"
)

remove_definitions(-DNDEBUG)
add_definitions(-DDEBUG -D_DEBUG -D_DBG)

# ignore runtime libraries that could have been added so far based on the config
add_linker_flag("/NODEFAULTLIB:ucrt.lib")
add_linker_flag("/NODEFAULTLIB:libucrt.lib")
add_linker_flag("/NODEFAULTLIB:libcmt.lib")

# make sure we use statically linked crt
add_linker_flag("/DEFAULTLIB:libucrtd.lib")
else()
# add_compile_options(/MT)
# per-config options will win, so we have to use this syntax to override
set_property(TARGET ${PROJECT_NAME} PROPERTY
COMPILE_OPTIONS "${ALL_COMPILE_OPTIONS};$<$<CONFIG:DEBUG>:/MT>"
)

remove_definitions(-DDEBUG -D_DEBUG -D_DBG)
add_definitions(-DNDEBUG)

# Force uCRT to be dynamically linked for Release build
add_linker_flag("/NODEFAULTLIB:libucrt.lib")
add_linker_flag("/DEFAULTLIB:ucrt.lib")
endif()

# Incremental linking results in the linker inserting extra padding and routing function calls via thunks that can break the
# invariants (e.g. size of region between Jit_PatchedCodeLast-Jit_PatchCodeStart needs to fit in a page).
add_linker_flag("/INCREMENTAL:NO")
endif()

# Path like: artifacts/bin/coreclr/windows.x64.Release/lib or
# /root/runtime/artifacts/transport/coreclr/lib
set(CORECLR_STATIC_LIB_LOCATION "${CORECLR_ARTIFACTS}/lib")

message ("Looking for coreclr_static lib at location: '${CORECLR_STATIC_LIB_LOCATION}'.")

if(CLR_CMAKE_TARGET_WIN32)
set(NATIVE_LIBS
${CORECLR_STATIC_LIB_LOCATION}/coreclr_static.lib
${CORECLR_STATIC_LIB_LOCATION}/System.Globalization.Native-Static.lib
${CORECLR_STATIC_LIB_LOCATION}/System.IO.Compression.Native-Static.lib
coreclr_static

System.Globalization.Native-Static
System.IO.Compression.Native-Static

kernel32.lib
advapi32.lib
ole32.lib
Expand All @@ -145,24 +118,27 @@ if(CLR_CMAKE_TARGET_WIN32)
user32.lib
version.lib
shlwapi.lib
shell32.lib
bcrypt.lib
RuntimeObject.lib
)

set(RUNTIMEINFO_LIB ${CORECLR_STATIC_LIB_LOCATION}/runtimeinfo.lib)
set(RUNTIMEINFO_LIB runtimeinfo)

else()
set(NATIVE_LIBS
${CORECLR_STATIC_LIB_LOCATION}/libcoreclr_static.a
${CORECLR_STATIC_LIB_LOCATION}/libSystem.Globalization.Native.a
${CORECLR_STATIC_LIB_LOCATION}/libSystem.IO.Compression.Native.a
${CORECLR_STATIC_LIB_LOCATION}/libSystem.Net.Security.Native.a
${CORECLR_STATIC_LIB_LOCATION}/libSystem.Native.a
${CORECLR_STATIC_LIB_LOCATION}/libSystem.Security.Cryptography.Native.OpenSsl.a
${CORECLR_STATIC_LIB_LOCATION}/libpalrt.a
${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a
${CORECLR_STATIC_LIB_LOCATION}/libeventprovider.a
${CORECLR_STATIC_LIB_LOCATION}/libnativeresourcestring.a
coreclr_static

System.Globalization.Native-Static
System.IO.Compression.Native-Static
System.Net.Security.Native-Static
System.Native-Static
System.Security.Cryptography.Native.OpenSsl-Static

palrt
coreclrpal
eventprovider
nativeresourcestring
)

# additional requirements for System.IO.Compression.Native
Expand All @@ -181,13 +157,13 @@ else()
include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake)
append_extra_cryptography_libs(NATIVE_LIBS)

set(RUNTIMEINFO_LIB ${CORECLR_STATIC_LIB_LOCATION}/libruntimeinfo.a)
set(RUNTIMEINFO_LIB runtimeinfo)

endif()

if(CLR_CMAKE_TARGET_OSX)
LIST(APPEND NATIVE_LIBS
${CORECLR_STATIC_LIB_LOCATION}/libSystem.Security.Cryptography.Native.Apple.a
System.Security.Cryptography.Native.Apple-Static
)

# Additional requirements for System.Security.Cryptography.Native.Apple
Expand All @@ -198,15 +174,6 @@ endif()
#
# Additional requirements for coreclr
#

# Specify non-default Windows libs to be used for Arm/Arm64 builds
if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64))
LIST(APPEND NATIVE_LIBS
Advapi32.lib
shell32.lib
)
endif()

if(CLR_CMAKE_TARGET_OSX)
find_library(COREFOUNDATION CoreFoundation)
find_library(CORESERVICES CoreServices)
Expand Down
14 changes: 12 additions & 2 deletions src/native/corehost/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ if /i [%1] == [commit] (set __CommitSha=%2&&shift&&shift&goto Arg_Loop)
if /i [%1] == [incremental-native-build] ( set __IncrementalNativeBuild=1&&shift&goto Arg_Loop)
if /i [%1] == [rootDir] ( set __rootDir=%2&&shift&&shift&goto Arg_Loop)
if /i [%1] == [coreclrartifacts] (set __CoreClrArtifacts=%2&&shift&&shift&goto Arg_Loop)
if /i [%1] == [nativelibsartifacts] (set __NativeLibsArtifacts=%2&&shift&&shift&goto Arg_Loop)
if /i [%1] == [ninja] (set __Ninja=1)
if /i [%1] == [runtimeflavor] (set __RuntimeFlavor=%2&&shift&&shift&goto Arg_Loop)
if /i [%1] == [runtimeconfiguration] (set __RuntimeConfiguration=%2&&shift&&shift&goto Arg_Loop)
Expand Down Expand Up @@ -154,7 +153,6 @@ echo "Computed RID for native build is %cm_BaseRid%"

set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%"
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__CommitSha%"
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCORECLR_ARTIFACTS=%__CoreClrArtifacts% " "-DRUNTIME_CONFIG=%__RuntimeConfiguration%" "-DNATIVE_LIBS_ARTIFACTS=%__NativeLibsArtifacts%"
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DRUNTIME_FLAVOR=%__RuntimeFlavor% "
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%"

Expand All @@ -181,6 +179,18 @@ IF ERRORLEVEL 1 (
goto :Failure
)

if "%__RuntimeFlavor%" NEQ "Mono" (
echo Copying "%__CoreClrArtifacts%\corehost\singlefilehost.exe" "%__CMakeBinDir%/corehost/"
copy /B /Y "%__CoreClrArtifacts%\corehost\singlefilehost.exe" "%__CMakeBinDir%/corehost/"

echo Copying "%__CoreClrArtifacts%\corehost\PDB\singlefilehost.pdb" "%__CMakeBinDir%/corehost/PDB/"
copy /B /Y "%__CoreClrArtifacts%\corehost\PDB\singlefilehost.pdb" "%__CMakeBinDir%/corehost/PDB/"

IF ERRORLEVEL 1 (
goto :Failure
)
)

echo Done building Native components
exit /B 0

Expand Down
17 changes: 6 additions & 11 deletions src/native/corehost/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ handle_arguments() {
__ShiftArgs=1
;;

nativelibsartifacts|-nativelibsartifacts)
__NativeLibsArtifacts="$2"
__ShiftArgs=1
;;

runtimeflavor|-runtimeflavor)
__RuntimeFlavor="$2"
__ShiftArgs=1
Expand All @@ -92,18 +87,13 @@ __DistroRidLower="$(echo $__DistroRid | tr '[:upper:]' '[:lower:]')"
__BinDir="$__RootBinDir/bin/$__DistroRidLower.$__BuildType"
__IntermediatesDir="$__RootBinDir/obj/$__DistroRidLower.$__BuildType"

export __BinDir __IntermediatesDir __CoreClrArtifacts __NativeLibsArtifacts __RuntimeFlavor
export __BinDir __IntermediatesDir __CoreClrArtifacts __RuntimeFlavor

__CMakeArgs="-DCLI_CMAKE_HOST_VER=\"$__host_ver\" -DCLI_CMAKE_COMMON_HOST_VER=\"$__apphost_ver\" -DCLI_CMAKE_HOST_FXR_VER=\"$__fxr_ver\" $__CMakeArgs"
__CMakeArgs="-DCLI_CMAKE_HOST_POLICY_VER=\"$__policy_ver\" -DCLI_CMAKE_PKG_RID=\"$__DistroRid\" -DCLI_CMAKE_COMMIT_HASH=\"$__commit_hash\" $__CMakeArgs"
__CMakeArgs="-DCORECLR_ARTIFACTS=\"$__CoreClrArtifacts\" -DNATIVE_LIBS_ARTIFACTS=\"$__NativeLibsArtifacts\" $__CMakeArgs"
__CMakeArgs="-DRUNTIME_FLAVOR=\"$__RuntimeFlavor\" $__CMakeArgs"
__CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs"

if [[ "$__PortableBuild" == 1 ]]; then
__CMakeArgs="-DCLI_CMAKE_PORTABLE_BUILD=1 $__CMakeArgs"
fi

# Specify path to be set for CMAKE_INSTALL_PREFIX.
# This is where all built CoreClr libraries will copied to.
__CMakeBinDir="$__BinDir"
Expand All @@ -117,3 +107,8 @@ check_prereqs

# Build the installer native components.
build_native "$__TargetOS" "$__BuildArch" "$__scriptpath" "$__IntermediatesDir" "$__CMakeArgs" "installer component"

if [[ "$__RuntimeFlavor" != "Mono" ]]; then
echo Copying "$__CoreClrArtifacts/corehost/." to "$__CMakeBinDir/corehost"
cp -a "$__CoreClrArtifacts/corehost/." "$__CMakeBinDir/corehost"
fi
Loading