Skip to content

cc/msvc: real DLL output for dynamic_link (auto-export, implib, staging) - #70

Merged
chen3feng merged 1 commit into
mainfrom
feat/msvc-dll
Jul 5, 2026
Merged

cc/msvc: real DLL output for dynamic_link (auto-export, implib, staging)#70
chen3feng merged 1 commit into
mainfrom
feat/msvc-dll

Conversation

@chen3feng

Copy link
Copy Markdown
Contributor

blade-go linked dynamic_link targets statically. Now, on MSVC, a cc_library reachable from a dynamic_link cc_binary/cc_test is built as a real DLL, the consumer links the import lib, and the DLL is staged for load — matching Blade. gcc/clang and non-dynamic builds unchanged.

Mechanism

  • needs-dynamic set — the cc_library closure of every dynamic_link target, honoring generate_dynamic=False (gtest_main/test_main stay static — their main() belongs in the exe, not a DLL).
  • auto-export .def — a windef edge runs the new __gen-windef subcommand: read the objects' COFF symbols via dumpbin /SYMBOLS, write a .def exporting every defined external (DATA-tagged when not a function). The blade-go analog of Blade's cc_windef — no per-source __declspec(dllexport) needed.
  • solink — links the DLL + import lib (/DLL /DEF /IMPLIB); the DLL base name encodes its package (suites.cc_basic.hello.dll) so DLLs flatten into one dir without collision.
  • dynamic linking + staging — a dynamic_link binary/test links the deps' import libs (not the static archives) and gets each transitive DLL staged next to the exe via a deduped copy edge (__cp), so it loads at runtime.
  • ninja.Build gains ImplicitOutputs (DLL|implib); ninja.Rule gains Restat (write-if-changed .def prunes needless relinks).

Verified (Windows 11 ARM64, VS2026)

blade-test cc_basic's dynamic tests (hello_dynamic_test, cross_package_dynamic_test) build as real DLLs and pass; hello.dll/farewell.dll are auto-exported + staged next to the exe. All cc suites (cc_basic/cc_incs/cc_export_map/cc_dll_export) stay green. go test ./... green on macOS/arm64; new tests cover dllBasename, the dynamic-link generation, and the export filter.

blade-go linked dynamic_link targets statically. Now, on MSVC, a
cc_library reachable from a dynamic_link cc_binary/cc_test is built as a
real DLL, and the consumer links the import lib with the DLL staged for
load -- matching Blade. gcc/clang and non-dynamic builds are unchanged.

Mechanism (internal/cc, internal/windef, cmd/blade):
  * needs-dynamic set: the cc_library closure of every dynamic_link
    binary/test, honoring generate_dynamic=False (gtest_main/test_main
    stay static -- their main() belongs in the exe, not a DLL).
  * a `windef` edge runs the new `__gen-windef` subcommand: read the
    objects' COFF symbols via `dumpbin /SYMBOLS`, write a .def exporting
    every defined external (DATA-tagged when not a function), so a library
    exports without per-source __declspec(dllexport). The blade-go analog
    of Blade's cc_windef.
  * `solink` links the DLL + import lib (/DLL /DEF /IMPLIB); the DLL base
    name encodes its package (suites.cc_basic.hello.dll) so DLLs flatten
    into one dir without collision.
  * a dynamic_link binary/test links the deps' import libs (not the static
    archives) and gets each transitive DLL staged next to the exe via a
    deduped `copy` edge (`__cp` subcommand), so it loads at runtime.
  * ninja.Build gains ImplicitOutputs (DLL|implib); ninja.Rule gains
    Restat (write-if-changed .def prunes needless DLL relinks).

Verified on Windows 11 ARM64 (VS2026): blade-test cc_basic's dynamic tests
(hello_dynamic_test, cross_package_dynamic_test) build as real DLLs and
pass; hello.dll / farewell.dll are auto-exported and staged next to the
exe. All cc suites (cc_basic/cc_incs/cc_export_map/cc_dll_export) stay
green. go test ./... green on macOS/arm64; new tests cover dllBasename,
the dynamic-link generation, and the export filter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chen3feng
chen3feng merged commit f7e9c3c into main Jul 5, 2026
1 check passed
@chen3feng
chen3feng deleted the feat/msvc-dll branch July 5, 2026 13:08
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.

1 participant