Skip to content

Allow building dxc as a static lib - #9161

Draft
Inner Daemons (inner-daemons) wants to merge 2 commits into
microsoft:mainfrom
inner-daemons:claude/friendly-curie-2a99su
Draft

Inner Daemons (inner-daemons) wants to merge 2 commits into
microsoft:mainfrom
inner-daemons:claude/friendly-curie-2a99su

Conversation

@inner-daemons

Copy link
Copy Markdown

Closes #4766

We've wanted this for a while in https://github.com/gfx-rs/wgpu/ for example. So much so in fact that we've relied on using a DXC fork to get static library builds. But if dxc could compile into a static library itself that would be vastly preferred.

The PR's code is LLM generated. Before I take it out of draft I will review it + write my own full description.

If this isn't desired for dxc it can quickly be closed, I won't be too bothered.

Let me know of any other concerns. Thanks

LLM-written description below

Adds an opt-in dxcompiler_static target built from the same sources as dxcompiler (minus the DLL .rc/.def). In the static build, DXC_STATIC_LIB replaces DllMain / the ELF constructor with one-time initialization on the first DxcCreateInstance(2) call, does not export symbols, and does not replace the global operator new on Windows.

Adds DxcStaticTests, a gtest binary that links dxcompiler_static directly (no dlopen/LoadLibrary) and covers DXIL and SPIR-V compilation, disassembly, validation, error reporting, a custom IMalloc, and concurrent first-time initialization.

Refs microsoft/DirectXShaderCompiler

Adds an opt-in dxcompiler_static target built from the same sources as
dxcompiler (minus the DLL .rc/.def). In the static build, DXC_STATIC_LIB
replaces DllMain / the ELF constructor with one-time initialization on the
first DxcCreateInstance(2) call, does not export symbols, and does not
replace the global operator new on Windows.

Adds DxcStaticTests, a gtest binary that links dxcompiler_static directly
(no dlopen/LoadLibrary) and covers DXIL and SPIR-V compilation,
disassembly, validation, error reporting, a custom IMalloc, and concurrent
first-time initialization.

Refs microsoft#4766

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0139G8ioEBLWcwJijh7gvZhz
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

DxcOptimizer.cpp calls pass initializers from IPO and ScalarOpts and the
pass printer factories from PassPrinters, but LLVMHLSL did not declare
those libraries. The shared dxcompiler happened to link because of the
order of its own link line; linking dxcompiler_static into an executable
failed with undefined references. Also apply clang-format.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0139G8ioEBLWcwJijh7gvZhz
@inner-daemons

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

How can I build dxil and dxcompiler as a static library?

2 participants