Skip to content

Commit d28c577

Browse files
lambdageekam11
andauthored
[cdac] link a stub contract descriptor if cdac-build-tool is not available (#101297)
* [cdac] link a stub contract descriptor if cdac-build-tool is not available Fixes builds that use src/coreclr/build-runtime.sh directly, or bringup scenarios without msbuild * Use DOTNET_HOST_PATH to run cdac-build-tool Related to dotnet/installer#19534 (comment) it's only unset by .NET Framework which is not supported by runtime.proj --------- Co-authored-by: Adeel Mujahid <[email protected]>
1 parent f806da2 commit d28c577

File tree

3 files changed

+85
-33
lines changed

3 files changed

+85
-33
lines changed

src/coreclr/debug/runtimeinfo/CMakeLists.txt

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,57 @@ endif()
3838
# publish runtimeinfo lib
3939
install_clr(TARGETS runtimeinfo DESTINATIONS lib COMPONENT runtime)
4040

41-
add_library(cdac_data_descriptor OBJECT datadescriptor.cpp)
42-
# don't build the data descriptor before the VM (and any of its dependencies' generated headers)
43-
add_dependencies(cdac_data_descriptor cee_wks_core)
44-
if(CLR_CMAKE_TARGET_WIN32)
45-
# turn off whole program optimization:
46-
# 1. it creates object files that cdac-build-tool can't read
47-
# 2. we never link cdac_data_descriptor into the final product - it's only job is to be scraped
48-
target_compile_options(cdac_data_descriptor PRIVATE /GL-)
49-
endif()
50-
target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR})
51-
target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR}/${ARCH_SOURCES_DIR})
52-
target_include_directories(cdac_data_descriptor PRIVATE ${CLR_DIR}/interop/inc)
53-
54-
set(GENERATED_CDAC_DESCRIPTOR_DIR "${CMAKE_CURRENT_BINARY_DIR}/cdac")
55-
set(CONTRACT_DESCRIPTOR_OUTPUT "${GENERATED_CDAC_DESCRIPTOR_DIR}/contract-descriptor.c")
56-
if("${CDAC_BUILD_TOOL_BINARY_PATH}" STREQUAL "" OR NOT EXISTS "${CDAC_BUILD_TOOL_BINARY_PATH}")
57-
message(FATAL_ERROR "No cdac-build-tool set or ${CDAC_BUILD_TOOL_BINARY_PATH} does not exist")
58-
endif()
5941

60-
set(CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc")
42+
# cDAC contract descriptor
43+
44+
if (NOT CDAC_BUILD_TOOL_BINARY_PATH)
45+
# if CDAC_BUILD_TOOL_BINARY_PATH is unspecified (for example for a build without a .NET SDK or msbuild),
46+
# link a stub contract descriptor into the runtime
47+
add_library_clr(cdac_contract_descriptor OBJECT contractdescriptorstub.c)
48+
message(STATUS "Using a stub cDAC contract descriptor")
49+
else()
50+
# generate a contract descriptor using cdac-build-tool from a data descriptor and contract json file
51+
52+
add_library(cdac_data_descriptor OBJECT datadescriptor.cpp)
53+
# don't build the data descriptor before the VM (and any of its dependencies' generated headers)
54+
add_dependencies(cdac_data_descriptor cee_wks_core)
55+
if(CLR_CMAKE_TARGET_WIN32)
56+
# turn off whole program optimization:
57+
# 1. it creates object files that cdac-build-tool can't read
58+
# 2. we never link cdac_data_descriptor into the final product - it's only job is to be scraped
59+
target_compile_options(cdac_data_descriptor PRIVATE /GL-)
60+
endif()
61+
target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR})
62+
target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR}/${ARCH_SOURCES_DIR})
63+
target_include_directories(cdac_data_descriptor PRIVATE ${CLR_DIR}/interop/inc)
64+
65+
set(GENERATED_CDAC_DESCRIPTOR_DIR "${CMAKE_CURRENT_BINARY_DIR}/cdac")
66+
set(CONTRACT_DESCRIPTOR_OUTPUT "${GENERATED_CDAC_DESCRIPTOR_DIR}/contract-descriptor.c")
67+
if(NOT EXISTS "${CDAC_BUILD_TOOL_BINARY_PATH}")
68+
message(FATAL_ERROR "${CDAC_BUILD_TOOL_BINARY_PATH} does not exist")
69+
endif()
6170

62-
# generate the contract descriptor by running cdac-build-tool
63-
# n.b. this just uses `dotnet` from the PATH. InitializeDotNetCli adds the apropropriate directory
64-
add_custom_command(
71+
set(CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc")
72+
73+
# generate the contract descriptor by running cdac-build-tool
74+
# n.b. this just uses `dotnet` from the PATH. InitializeDotNetCli adds the apropropriate directory
75+
add_custom_command(
6576
OUTPUT "${CONTRACT_DESCRIPTOR_OUTPUT}"
6677
VERBATIM
67-
COMMAND dotnet ${CDAC_BUILD_TOOL_BINARY_PATH} compose -o "${CONTRACT_DESCRIPTOR_OUTPUT}" -c "${CONTRACT_FILE}" $<TARGET_OBJECTS:cdac_data_descriptor>
78+
COMMAND ${CLR_DOTNET_HOST_PATH} ${CDAC_BUILD_TOOL_BINARY_PATH} compose -o "${CONTRACT_DESCRIPTOR_OUTPUT}" -c "${CONTRACT_FILE}" $<TARGET_OBJECTS:cdac_data_descriptor>
6879
DEPENDS cdac_data_descriptor cee_wks_core $<TARGET_OBJECTS:cdac_data_descriptor> "${CONTRACT_FILE}"
6980
USES_TERMINAL
70-
)
81+
)
7182

72-
# It is important that cdac_contract_descriptor is an object library;
73-
# if it was static, linking it into the final dll would not export
74-
# DotNetRuntimeContractDescriptor since it is not referenced anywhere.
75-
add_library_clr(cdac_contract_descriptor OBJECT
83+
# It is important that cdac_contract_descriptor is an object library;
84+
# if it was static, linking it into the final dll would not export
85+
# DotNetRuntimeContractDescriptor since it is not referenced anywhere.
86+
add_library_clr(cdac_contract_descriptor OBJECT
7687
"${CONTRACT_DESCRIPTOR_OUTPUT}"
7788
contractpointerdata.cpp
78-
)
79-
target_include_directories(cdac_contract_descriptor BEFORE PRIVATE ${VM_DIR})
80-
target_include_directories(cdac_contract_descriptor BEFORE PRIVATE ${VM_DIR}/${ARCH_SOURCES_DIR})
81-
target_include_directories(cdac_contract_descriptor PRIVATE ${CLR_DIR}/interop/inc)
82-
add_dependencies(cdac_contract_descriptor cdac_data_descriptor cee_wks_core)
89+
)
90+
target_include_directories(cdac_contract_descriptor BEFORE PRIVATE ${VM_DIR})
91+
target_include_directories(cdac_contract_descriptor BEFORE PRIVATE ${VM_DIR}/${ARCH_SOURCES_DIR})
92+
target_include_directories(cdac_contract_descriptor PRIVATE ${CLR_DIR}/interop/inc)
93+
add_dependencies(cdac_contract_descriptor cdac_data_descriptor cee_wks_core)
94+
endif()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#include <stdint.h>
5+
6+
#ifdef _MSC_VER
7+
#define DLLEXPORT __declspec(dllexport)
8+
#else
9+
#define DLLEXPORT __attribute__((visibility("default")))
10+
#endif
11+
12+
struct DotNetRuntimeContractDescriptor
13+
{
14+
uint64_t magic;
15+
uint32_t flags;
16+
const uint32_t descriptor_size;
17+
const char *descriptor;
18+
const uint32_t pointer_data_count;
19+
uint32_t pad0;
20+
const uintptr_t *pointer_data;
21+
};
22+
23+
extern const uintptr_t contractDescriptorPointerData[];
24+
25+
// just the placeholder pointer
26+
const uintptr_t contractDescriptorPointerData[] = { (uintptr_t)0 };
27+
28+
DLLEXPORT struct DotNetRuntimeContractDescriptor DotNetRuntimeContractDescriptor;
29+
30+
#define STUB_DESCRIPTOR "{\"version\":0,\"baseline\":\"empty\",\"contracts\":{},\"types\":{},\"globals\":{}}"
31+
32+
DLLEXPORT struct DotNetRuntimeContractDescriptor DotNetRuntimeContractDescriptor = {
33+
.magic = 0x0043414443434e44ull, // "DNCCDAC\0"
34+
.flags = 0x1u & (sizeof(void*) == 4 ? 0x02u : 0x00u),
35+
.descriptor_size = sizeof(STUB_DESCRIPTOR),
36+
.descriptor = STUB_DESCRIPTOR,
37+
.pointer_data_count = 1,
38+
.pointer_data = &contractDescriptorPointerData[0],
39+
};

src/coreclr/runtime.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<_CoreClrBuildArg Condition="'$(HostCrossOS)' != ''" Include="-hostos $(HostCrossOS)" />
5151
<_CoreClrBuildArg Include="-outputrid $(OutputRID)" />
5252
<_CoreClrBuildArg Condition="'$(BuildSubdirectory)' != ''" Include="-subdir $(BuildSubdirectory)" />
53+
<_CoreClrBuildArg Include="-cmakeargs &quot;-DCLR_DOTNET_HOST_PATH=$(DOTNET_HOST_PATH)&quot;" />
5354
<_CoreClrBuildArg Include="-cmakeargs &quot;-DCDAC_BUILD_TOOL_BINARY_PATH=$(RuntimeBinDir)cdac-build-tool\cdac-build-tool.dll&quot;" />
5455
</ItemGroup>
5556

0 commit comments

Comments
 (0)