Add .NET 7 build support
authorGleb Balykov <g.balykov@samsung.com>
Wed, 12 Oct 2022 14:41:18 +0000 (17:41 +0300)
committerGleb Balykov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Tue, 29 Nov 2022 16:55:08 +0000 (19:55 +0300)
CMakeLists.txt
README.md
fetchdeps.cmake
packaging/netcoredbg.spec
src/CMakeLists.txt
src/debugger/dbgshim.h
src/managed/ManagedPart.csproj

index 6c4b4cda94bbb73958daf519638447e98d9f1707..fb3f54b3f2fe159f5d14468467abb881a7e4d657 100644 (file)
@@ -8,13 +8,11 @@ project(netcoredbg)
 
 set(CORECLR_DIR "" CACHE FILEPATH "Path to CoreCLR source directory")
 set(DOTNET_DIR "" CACHE FILEPATH "Path to .NET SDK directory")
-# Note, since 5.0 src are broken and will not build netcoredbg without patch, stay with 3.1 for now.
-set(CORECLR_BRANCH "release/3.1" CACHE STRING "CoreCLR source branch")
-# Note, we must use latest runtime, since we need copy latest dbgshim in order to work with all runtime versions.
-# https://github.com/dotnet/runtime/pull/44748#issuecomment-729268650
-set(DOTNET_CHANNEL "6.0" CACHE STRING ".NET SDK channel")
+set(CORECLR_BRANCH "release/7.0" CACHE STRING "CoreCLR source branch")
+# After move of dbgshim from runtime to diagnostics, this sdk is used only for build of managed part.
+set(DOTNET_CHANNEL "7.0" CACHE STRING ".NET SDK channel")
 set(BUILD_MANAGED ON CACHE BOOL "Build managed part")
-set(DBGSHIM_RUNTIME_DIR "" CACHE FILEPATH "Path to dbgshim library directory (at runtime)")
+set(DBGSHIM_DIR "" CACHE FILEPATH "Path to dbgshim library directory")
 
 function(clr_unknown_arch)
     message(FATAL_ERROR "Only AMD64, ARM64, ARM, ARMEL, I386 and WASM are supported")
@@ -42,10 +40,37 @@ include(clrdefinitions.cmake)
 include(fetchdeps.cmake)
 
 set(CORECLR_SRC_DIR "${CORECLR_DIR}/src")
+set(VERSION_PROPS_PATH "${CORECLR_DIR}/eng/Versions.props")
 if (NOT EXISTS "${CORECLR_SRC_DIR}/pal")
-  set(CORECLR_SRC_DIR "${CORECLR_DIR}")
+    set(CORECLR_SRC_DIR "${CORECLR_DIR}")
+    set(VERSION_PROPS_PATH "${CORECLR_DIR}/../../eng/Versions.props")
 endif()
 
+if (WIN32)
+    execute_process(
+            COMMAND powershell -Command "Select-Xml -Path ${VERSION_PROPS_PATH} -XPath '/Project/PropertyGroup/ProductVersion' | ForEach-Object { $_.Node.InnerXML }"
+            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+            OUTPUT_VARIABLE CORECLR_VERSION
+            OUTPUT_STRIP_TRAILING_WHITESPACE
+            ERROR_VARIABLE errout
+            RESULT_VARIABLE retcode)
+else()
+    execute_process(
+            COMMAND bash -c "grep ProductVersion ${VERSION_PROPS_PATH} | sed 's,</.*,,;s,.*>,,'"
+            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+            OUTPUT_VARIABLE CORECLR_VERSION
+            OUTPUT_STRIP_TRAILING_WHITESPACE
+            ERROR_VARIABLE errout
+            RESULT_VARIABLE retcode)
+endif()
+
+if (NOT "${retcode}" STREQUAL "0" OR "${CORECLR_VERSION}" STREQUAL "")
+    # For some version of runtime Versions.props file doesn't exist
+    set(CORECLR_VERSION "unknown")
+endif()
+
+message("Building with ${CORECLR_VERSION} CoreCLR")
+
 # Basic checks for valid paths
 if (NOT IS_DIRECTORY "${CORECLR_SRC_DIR}/pal")
     message(FATAL_ERROR "Invalid CoreCLR source directory")
index dc8ca5cc6daa86f4890890dd14209712f301b395..a871b96d7c62476067e09d22a98064cd566e51ee 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,12 +34,12 @@ Building of Netcoredbg requires Microsoft's .NET, so currently you can build Net
 
 5. It is expected, that Netcoredbg sources placed to some directory;
 
-6. Optional step: Netcoredbg requires **Core CLR runtime source code**, which is typically downloaded automatically, but you can download it from here: https://github.com/dotnet/coreclr
+6. Optional step: Netcoredbg requires **CoreCLR runtime source code**, which is typically downloaded automatically, but you can download it from here: https://github.com/dotnet/runtime
 
-   You should check out tag v3.x.
+   You should check out tag v7.x.
 
 7. Optional step: Netcoredbg requires **.NET SDK**, which can be downloaded automatically, but you can download it manually from here: https://dotnet.microsoft.com/download
-   You need .NET SDK 3.1.
+   You need .NET SDK 7.0.
 
 #### Compiling
 
@@ -53,9 +53,9 @@ user@build$ CC=clang CXX=clang++ cmake ..
 
 For running tests after build has succeed you need to add option `-DCMAKE_INSTALL_PREFIX=$PWD/../bin`.
 
-If you have previously downloaded .NET SDK or Core CLR sources, then you should modify command line and add following options: `-DDOTNET_DIR=/path/to/sdk/dir -DCORECLR_DIR=/path/to/coreclr/sources`
+If you have previously downloaded .NET SDK or CoreCLR sources, then you should modify command line and add following options: `-DDOTNET_DIR=/path/to/sdk/dir -DCORECLR_DIR=/path/to/coreclr/sources`
 
-If cmake tries to download .NET SDK or Core CLR sources and fails -- see bullets 6 and 7 above. You can download required files manually.
+If cmake tries to download .NET SDK or CoreCLR sources and fails -- see bullets 6 and 7 above. You can download required files manually.
 
 After configuration has finished, you can build Netcoredbg:
 
@@ -103,12 +103,12 @@ After this, build instructions are same as for Unix (including prerequisites).
 
 
 5. This step might be omitted, in this case cmake automatically downloads necessary files.
-   But if it fails, you should then checkout **Core CLR sources** to another directory from here: https://github.com/dotnet/coreclr
+   But if it fails, you should then checkout **CoreCLR sources** to another directory from here: https://github.com/dotnet/runtime
 
-   You need latest tag **v3.x**.
+   You need latest tag **v7.x**.
 
 6. This step might be omitted too, and cmake will automatically downloads that it needs.
-   But in case of failure you need download and install **.NET Core 3.1 SDK** from here: https://dotnet.microsoft.com/download
+   But in case of failure you need download and install **.NET Core 7.0 SDK** from here: https://dotnet.microsoft.com/download
 
 #### Compiling
 
index 6a2f0a02365f0189340bedb0235bfa5386b452f0..16ae4828c8f5309ade92b7cb1ec32b9a6d22a76a 100644 (file)
@@ -26,17 +26,19 @@ if ("${CORECLR_DIR}" STREQUAL "")
             file(REMOVE_RECURSE "${CORECLR_DIR}")
         endif()
         execute_process(
-            COMMAND ${GIT_EXECUTABLE} clone --progress --depth 1 https://github.com/dotnet/coreclr "${CORECLR_DIR}" -b "${CORECLR_BRANCH}"
+            COMMAND ${GIT_EXECUTABLE} clone --progress --depth 1 https://github.com/dotnet/runtime "${CORECLR_DIR}" -b "${CORECLR_BRANCH}"
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
             RESULT_VARIABLE retcode)
         if (NOT "${retcode}" STREQUAL "0")
             message(FATAL_ERROR "Fatal error when cloning coreclr sources")
         endif()
     endif()
+
+    set(CORECLR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.coreclr/src/coreclr)
 endif()
 
 # Fetch .NET SDK binaries if necessary
-if ("${DOTNET_DIR}" STREQUAL "" AND (("${DBGSHIM_RUNTIME_DIR}" STREQUAL "") OR ${BUILD_MANAGED}))
+if ("${DOTNET_DIR}" STREQUAL "" AND ${BUILD_MANAGED})
     set(DOTNET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.dotnet)
 
     if (WIN32)
@@ -59,7 +61,7 @@ if ("${DOTNET_DIR}" STREQUAL "" AND (("${DBGSHIM_RUNTIME_DIR}" STREQUAL "") OR $
         if (NOT "${retcode}" STREQUAL "0")
             message(FATAL_ERROR "Fatal error when installing dotnet")
         endif()
-        else()
+    else()
         execute_process(
             COMMAND bash -c "curl -sSL \"https://dot.net/v1/dotnet-install.sh\" | bash /dev/stdin --channel \"${DOTNET_CHANNEL}\" --install-dir \"${DOTNET_DIR}\" --verbose"
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
index b36455059506fbdbc5bb9bee30ae58d616014769..62362b77c131da17e279d071cbf458260b7a4290 100644 (file)
@@ -107,7 +107,7 @@ cmake .. \
     -DCMAKE_INSTALL_PREFIX=%{install_prefix} \
     -DCMAKE_BUILD_TYPE=%{build_type} \
     -DCLR_CMAKE_LINUX_ID=tizen \
-    -DDBGSHIM_RUNTIME_DIR=$NETCOREAPPDIR \
+    -DDBGSHIM_DIR=$NETCOREAPPDIR \
     -DBUILD_MANAGED=OFF \
     -DNCDB_DOTNET_STARTUP_HOOK=$STARTUP_HOOK \
     -DBUILD_TESTING=%{build_testing}
index a7ac794838aca59b0b4fdbe1755b4c79e3e71dab..b0b61713c7773806e5f03c9ea0ba6cbb35b0b193 100644 (file)
@@ -3,10 +3,8 @@
 # application name for tizens logger
 add_definitions(-DLOG_TAG="NETCOREDBG")
 
-if (NOT DBGSHIM_RUNTIME_DIR STREQUAL "")
-    add_definitions(-DDBGSHIM_RUNTIME_DIR="${DBGSHIM_RUNTIME_DIR}")
-else()
-    find_file(DBGSHIM_LOCATION NAMES dbgshim.dll libdbgshim.so libdbgshim.dylib PATHS "${DOTNET_DIR}/shared/Microsoft.NETCore.App/*" NO_DEFAULT_PATH)
+if (NOT DBGSHIM_DIR STREQUAL "")
+    add_definitions(-DDBGSHIM_DIR="${DBGSHIM_DIR}")
 endif()
 
 # Build corguids static library from coreclr source files
@@ -200,9 +198,6 @@ add_custom_command(
 )
 
 install(TARGETS netcoredbg DESTINATION ${CMAKE_INSTALL_PREFIX})
-if (DBGSHIM_LOCATION)
-    install(FILES ${DBGSHIM_LOCATION} DESTINATION ${CMAKE_INSTALL_PREFIX})
-endif()
 
 # Build managed part of the debugger (ManagedPart.dll)
 
@@ -219,8 +214,25 @@ if (BUILD_MANAGED)
         set(MANAGEDPART_BUILD_TYPE "Release")
     endif()
 
+    set(USE_DBGSHIM_DEPENDENCY "")
+    if (DBGSHIM_DIR STREQUAL "")
+        set(USE_DBGSHIM_DEPENDENCY "/p:UseDbgShimDependency=true")
+    endif()
+
+    if (CLR_CMAKE_PLATFORM_UNIX)
+        if (CLR_CMAKE_PLATFORM_DARWIN)
+            set(RID_NAME "osx")
+        else()
+            set(RID_NAME "linux")
+        endif()
+    elseif (WIN32)
+        set(RID_NAME "win")
+    else()
+        message(FATAL_ERROR "Unsupported platform")
+    endif()
+
     add_custom_command(OUTPUT ${DOTNET_BUILD_RESULT}
-      COMMAND ${DOTNETCLI} publish ${MANAGEDPART_PROJECT} -c ${MANAGEDPART_BUILD_TYPE} -o ${CMAKE_CURRENT_BINARY_DIR} /p:BaseIntermediateOutputPath=${CMAKE_CURRENT_BINARY_DIR}/obj/ /p:BaseOutputPath=${CMAKE_CURRENT_BINARY_DIR}/bin/
+      COMMAND ${DOTNETCLI} publish ${MANAGEDPART_PROJECT} -r ${RID_NAME}-${CLR_CMAKE_TARGET_ARCH} --self-contained -c ${MANAGEDPART_BUILD_TYPE} -o ${CMAKE_CURRENT_BINARY_DIR} /p:BaseIntermediateOutputPath=${CMAKE_CURRENT_BINARY_DIR}/obj/ /p:BaseOutputPath=${CMAKE_CURRENT_BINARY_DIR}/bin/ ${USE_DBGSHIM_DEPENDENCY}
       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
       DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/managed/*.cs" "${MANAGEDPART_PROJECT}"
       COMMENT "Compiling ${MANAGEDPART_DLL_NAME}"
@@ -242,6 +254,22 @@ if (BUILD_MANAGED)
     endforeach()
 
     install(FILES ${DLLS_TO_DEPLOY} DESTINATION ${CMAKE_INSTALL_PREFIX})
+
+    if (DBGSHIM_DIR STREQUAL "")
+        if (CLR_CMAKE_PLATFORM_UNIX)
+            if (CLR_CMAKE_PLATFORM_DARWIN)
+                set(DBGSHIM_LIB_NAME "libdbgshim.dylib")
+            else()
+                set(DBGSHIM_LIB_NAME "libdbgshim.so")
+            endif()
+        elseif (WIN32)
+            set(DBGSHIM_LIB_NAME "dbgshim.dll")
+        else()
+            message(FATAL_ERROR "Unsupported platform")
+        endif()
+
+        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DBGSHIM_LIB_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX})
+    endif()
 endif()
 
 # Build Hot Reload managed dll (ncdbhook.dll)
index 76eb098e6df24b58433f6af139440e7fa7f2fa36..0a950bd7d7b2e66749cc2cf13ae67d5091535609 100644 (file)
@@ -47,8 +47,8 @@ struct dbgshim_t
         CreateDebuggingInterfaceFromVersionEx(nullptr),
         m_module(nullptr)
     {
-#ifdef DBGSHIM_RUNTIME_DIR
-        std::string libName(DBGSHIM_RUNTIME_DIR);
+#ifdef DBGSHIM_DIR
+        std::string libName(DBGSHIM_DIR);
         libName += DIRECTORY_SEPARATOR_STR_A;
 #else
         std::string exe = GetExeAbsPath();
index d7ada56794dd9f64bde0297b9088c7c595466c97..b9f2ebcfc54b209e3d6b96edf5dc1699097a55b5 100644 (file)
@@ -38,6 +38,7 @@
     </PackageReference>
     <PackageReference Include="Microsoft.CSharp" Version="[4.4,)" />
     <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="[2.3,)" />
+    <PackageReference Include="Microsoft.Diagnostics.DbgShim" Condition="'$(UseDbgShimDependency)' == 'true'" Version="*" />
   </ItemGroup>
 
 </Project>