Skip to content

Link MSVC runtime library statically#276

Merged
samansmink merged 1 commit intoduckdb:mainfrom
staticlibs:msvc_static
Dec 15, 2025
Merged

Link MSVC runtime library statically#276
samansmink merged 1 commit intoduckdb:mainfrom
staticlibs:msvc_static

Conversation

@staticlibs
Copy link
Copy Markdown
Contributor

@staticlibs staticlibs commented Oct 15, 2025

This change replaces the use of
x64-windows-static-md-release-vs2019comp vcpkg toolchain to x64-windows-static-release for Windows MSVC builds.

With this change the MSVC runtime library (both C and C++ stdlibs) is linked statically to every extension. Thus extensions no longer rely on the MSVC runtime shared libs used by the host process and the VS2019-specific changes added in #229 are no longer necessary.

To make the build working a change is also required to the duckdb/duckdb repo - will file a PR there shortly.

Testing: checked locally on duckdb-aws that resulting extension binaries are no longer depend on MSVC runtime shared libs.

Ref: duckdblabs/duckdb-internal#2036

Upd: the same change is applied to windows_arm64.

staticlibs added a commit to staticlibs/duckdb that referenced this pull request Oct 15, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in
duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Testing: checked locally that `duckdb-httpfs` can successfully fetch
HTTP(S) resources with this and `extension-ci-tools` changes applied.

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in
duckdb/duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-python that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 described in
duckdb/duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in
duckdb/duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Oct 17, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
This change replaces the use of
`x64-windows-static-md-release-vs2019comp` vcpkg toolchain to
`x64-windows-static-release` for Windows MSVC builds.

With this change the MSVC runtime library (both C and C++ stdlibs) is
linked statically to every extension. Thus extensions no longer rely on
the MSVC runtime shared libs used by the host process and the
VS2019-specific changes added in duckdb#229 are no longer necessary.

To make the build working a change is also required to the
`duckdb/duckdb` repo - will file a PR there shortly.

Testing: checked locally on `duckdb-aws` that resulting extension
binaries no longer depend on MSVC runtime shared libs.

Ref: duckdblabs/duckdb-internal#2036

Upd: the same change is applied to `windows_arm64`.
@staticlibs
Copy link
Copy Markdown
Contributor Author

Rebased the PR on the latest main applying the same changes to windows_arm64, I think this is ready for review now, CC: @lnkuiper

@staticlibs
Copy link
Copy Markdown
Contributor Author

windows_amd64_mingw CI run has failed with:

Downloading vcpkg.exe failed. Please check your internet connection

This looks like duckdblabs/duckdb-internal#6877

@lnkuiper
Copy link
Copy Markdown
Member

I don't have merge access here, can you have a look @carlopi ? Feel free to rerun CI if you think it's necessary

@carlopi
Copy link
Copy Markdown
Member

carlopi commented Dec 12, 2025

One thing I am wary connected to merging this is what are the wider implications of having some CI/extensions being built with this change, while other are built the other way.

Also I am not sure how statically linking MSVC work for example with cross extension throws, those Exception will be the same type (and so caught) or not? Or similar issues at the border.

I would need to think a bit more what is the proper path here, and would prefer to double check with @samansmink before proceding.

@carlopi carlopi requested a review from samansmink December 12, 2025 08:59
@staticlibs
Copy link
Copy Markdown
Contributor Author

On the CI failures: Rust extension loading is supposed to be fixed by duckdb/extension-template-rs#37, WASM failure is a generic download failure (networking error).

@samansmink samansmink merged commit 0728ffb into duckdb:main Dec 15, 2025
47 of 54 checks passed
lnkuiper added a commit to duckdb/duckdb that referenced this pull request Dec 16, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in
#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Testing: checked locally that `duckdb-httpfs` can successfully fetch
HTTP(S) resources with this and `extension-ci-tools` changes applied.

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/extension-ci-tools that referenced this pull request Dec 17, 2025
This PR adds an option `vcpkg_triplets_override` to the
`_extension_distribution.yml` that can be used to override vcpkg
triplets specified in the `distribution_matrix.json`.

Example:

```yaml
uses: ./.github/workflows/_extension_distribution.yml
    with:
      ...
      vcpkg_triplets_override: 'windows_amd64:x64-windows-static-md-release-vs2019comp;windows_arm64:arm64-windows-static-md-release-vs2019comp;'
```

It also restores the custom triplets removed in duckdb#276 so they can be
requested by caller workflows.

Testing: added example usage of the new option to `TestCITools.yml`
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Dec 19, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Dec 19, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Dec 22, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Dec 22, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in
duckdb/duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-odbc that referenced this pull request Dec 22, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in duckdb#169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to duckdb/duckdb-odbc that referenced this pull request Dec 22, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in #169 is no
longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to duckdb/duckdb-java that referenced this pull request Dec 22, 2025
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 added in
duckdb/duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
evertlammerts added a commit to duckdb/duckdb-python that referenced this pull request Jan 6, 2026
This change makes all CMake targets to use `-MT`/`-MTd` compilation
flags for Windows MSVC builds. This way the MSVC runtime library is
linked statically and the workaround for VS2019 described in
duckdb/duckdb#17991 is no longer necessary.

`extension-ci-tools` PR: duckdb/extension-ci-tools#276

Ref: duckdblabs/duckdb-internal#2036
staticlibs added a commit to staticlibs/duckdb-spatial that referenced this pull request Jan 10, 2026
Due to the integration of duckdb/duckdb#19415 and
duckdb/extension-ci-tools#276 the `1.4-andium` branch of Spatial
extension can no longer be built with `main` branch of
`extension-ci-tools`.

This PR pins the version of `extension-ci-tools` used for CI builds.
It should fix the following build problem on Windows:

```
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'
```

Ref: duckdblabs/duckdb-internal#2036
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.

4 participants