Fix libstdc++-6.dll runtime dependency for Windows mingw-w64 builds#26
Conversation
Configure Rust build to statically link libgcc and libstdc++ for Windows target to eliminate runtime dependency on libstdc++-6.dll. This is achieved through: 1. Adding .cargo/config.toml with rustflags for x86_64-pc-windows-gnu 2. Updating the cinterop .def file with -static-libgcc and -static-libstdc++ linker options Co-authored-by: BppleMan <16437384+BppleMan@users.noreply.github.com>
…static Remove the general -static flag and use only -static-libgcc and -static-libstdc++ flags for more targeted static linking. The -static flag can cause issues with Windows system libraries that aren't available in static form. Co-authored-by: BppleMan <16437384+BppleMan@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes runtime dependency issues for Windows executables built with mingw-w64 from Linux by statically linking the GCC and C++ runtime libraries instead of relying on external DLLs.
Key Changes:
- Added Rust build configuration to statically link GCC and C++ runtimes during Rust compilation
- Updated Kotlin/Native interop linker options to use targeted static linking flags instead of global
-staticflag
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| kommand-core/.cargo/config.toml | Configures Rust compiler to statically link libgcc and libstdc++ for Windows GNU target |
| src/nativeInterop/cinterop/x86_64-pc-windows-gnu.def | Updates linker flags to use specific static linking options and removes redundant -lstdc++ |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| staticLibraries = libkommand_core.a | ||
| compilerOpts = -Ikommand-core | ||
| linkerOpts = -static -lws2_32 -lbcrypt -luserenv -lntdll -lstdc++ -v | ||
| linkerOpts = -static-libgcc -static-libstdc++ -lws2_32 -lbcrypt -luserenv -lntdll -v |
There was a problem hiding this comment.
The -v verbose flag should be removed from production linker options as it's a debugging flag that produces unnecessary output during normal builds.
| linkerOpts = -static-libgcc -static-libstdc++ -lws2_32 -lbcrypt -luserenv -lntdll -v | |
| linkerOpts = -static-libgcc -static-libstdc++ -lws2_32 -lbcrypt -luserenv -lntdll |
BppleMan
left a comment
There was a problem hiding this comment.
Purpose
- Verify that recent Windows linking changes do not break any kommand examples on a Windows runner that does NOT have MinGW installed.
- Create the workflow file at
.github/workflows/windows-no-mingw-examples.ymlwith the YAML below and add it to this PR. - Ensure the workflow is committed as part of this PR so it runs against these changes.
- Do not install or configure MinGW/MSYS in the workflow—the job must simulate a Windows environment without MinGW.
What the workflow must do
- Trigger on push and pull_request (restricted to relevant paths).
- Run on
windows-latest. - Checkout the repo and set up Java 17 (Temurin).
- Discover all example subprojects under
kommand-examples(folders withbuild.gradleorbuild.gradle.kts). - For each example: run
./gradlew :kommand-examples:<name>:assemble(fail the job on any non-zero exit). - Locate produced native executables (e.g.,
kommand-examples/**/build/bin/**/*.exe) and run each one (fail the job if any executable exits with non-zero code). - Upload per-run logs/artifacts for debugging (stdout/stderr, Gradle logs).
Acceptance criteria
- CI succeeds only if every example builds and every produced executable exits with code 0.
- On failure, logs/artifacts are uploaded to aid troubleshooting.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Windows executables built with mingwX64 from Linux fail at runtime due to missing libstdc++-6.dll. The Rust core library was dynamically linking to C++ and GCC runtime libraries.
Changes
Rust build configuration (
kommand-core/.cargo/config.toml):-static-libgccand-static-libstdc++rustflags for x86_64-pc-windows-gnu targetKotlin/Native interop (
src/nativeInterop/cinterop/x86_64-pc-windows-gnu.def):-static -lstdc++with-static-libgcc -static-libstdc++Result: Self-contained Windows executables with no external DLL dependencies for standard library runtimes.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.