Skip to content

build: add Source Link to embed GitHub source mappings in PDBs#40055

Merged
benhillis merged 2 commits intomasterfrom
user/benhill/source_link
Apr 7, 2026
Merged

build: add Source Link to embed GitHub source mappings in PDBs#40055
benhillis merged 2 commits intomasterfrom
user/benhill/source_link

Conversation

@benhillis
Copy link
Copy Markdown
Member

When a debugger (Visual Studio, WinDbg, VS Code) loads a PDB and needs to show source, it reads this mapping, substitutes the local build path with the URL, and fetches the exact source file from the server.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Source Link support to the Windows CMake build so generated PDBs can map local source paths to GitHub URLs, enabling debuggers to fetch exact source files for a given commit.

Changes:

  • Generate a sourcelink.json file during CMake configure with document mappings to raw.githubusercontent.com for the current COMMIT_HASH.
  • Pass /SOURCELINK:<json> to the MSVC linker for DLL and EXE targets.

@benhillis benhillis force-pushed the user/benhill/source_link branch from 26d09cc to 51a0268 Compare March 31, 2026 22:14
OneBlue
OneBlue previously approved these changes Apr 6, 2026
CMakeLists.txt Outdated

# Generate Source Link JSON so debuggers can fetch source from GitHub
set(SOURCELINK_JSON "${GENERATED_DIR}/sourcelink.json")
file(WRITE "${SOURCELINK_JSON}" "{\"documents\":{\"${CMAKE_SOURCE_DIR}/*\":\"https://raw.githubusercontent.com/microsoft/WSL/${COMMIT_HASH}/*\"}}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I recommend doing this only for pipeline builds. We could use PIPELINE_BUILD_ID to detect that we're inside a pipeline

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>
Copilot AI review requested due to automatic review settings April 6, 2026 23:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@benhillis
Copy link
Copy Markdown
Member Author

Hey @benhillis 👋 — This PR is nearly ready to merge (clean mergeable state, all CI green). There's 1 unresolved review thread from @OneBlue suggesting Source Link should only be enabled for pipeline builds (using \PIPELINE_BUILD_ID\ detection). Could you address that to unblock this?

@benhillis benhillis merged commit effd9ef into master Apr 7, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants