Skip to content

Commit effd9ef

Browse files
benhillisBen HillisCopilot
authored
build: add Source Link to embed GitHub source mappings in PDBs (#40055)
* build: add Source Link to embed GitHub source mappings in PDBs * Gate Source Link on pipeline builds only Only generate sourcelink.json and pass /SOURCELINK to the linker when PIPELINE_BUILD_ID is defined (i.e. during CI pipeline builds). This avoids unnecessary Source Link artifacts in local developer builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 20ca899 commit effd9ef

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ file(MAKE_DIRECTORY ${BIN})
156156
set (GENERATED_DIR ${CMAKE_BINARY_DIR}/generated)
157157
file(MAKE_DIRECTORY ${GENERATED_DIR})
158158

159+
# Generate Source Link JSON so debuggers can fetch source from GitHub (pipeline builds only)
160+
if (DEFINED PIPELINE_BUILD_ID)
161+
set(SOURCELINK_JSON "${GENERATED_DIR}/sourcelink.json")
162+
file(WRITE "${SOURCELINK_JSON}" "{\"documents\":{\"${CMAKE_SOURCE_DIR}/*\":\"https://raw.githubusercontent.com/microsoft/WSL/${COMMIT_HASH}/*\"}}")
163+
endif()
164+
159165
set(PACKAGE_CERTIFICATE ${GENERATED_DIR}/dev-cert.pfx)
160166
file(CREATE_LINK ${WSLG_SOURCE_DIR}/${TARGET_PLATFORM}/${WSLG_TS_PLUGIN_DLL} ${BIN}/${WSLG_TS_PLUGIN_DLL})
161167
file(CREATE_LINK ${WSLDEPS_SOURCE_DIR}/bin/wsldeps.dll ${BIN}/wsldeps.dll)
@@ -234,6 +240,10 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /guard:cf /Qspectre"
234240
# Linker flags
235241
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /debug:full /debugtype:cv,fixup /guard:cf /DYNAMICBASE")
236242
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /debug:full /debugtype:cv,fixup /guard:cf /DYNAMICBASE")
243+
if (DEFINED SOURCELINK_JSON)
244+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SOURCELINK:\"${SOURCELINK_JSON}\"")
245+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SOURCELINK:\"${SOURCELINK_JSON}\"")
246+
endif()
237247
if (${TARGET_PLATFORM} STREQUAL "x64")
238248
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /CETCOMPAT")
239249
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /CETCOMPAT")

0 commit comments

Comments
 (0)