Skip to content

[PLAT-22844] Add /MD Windows builds of libprotobuf - #7

Merged
philz-unity merged 6 commits into
v21.2-unityfrom
platform/editor/windows-dynamic-crt
Oct 19, 2026
Merged

philz-unity merged 6 commits into
v21.2-unityfrom
platform/editor/windows-dynamic-crt

Conversation

@philz-unity

@philz-unity philz-unity commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Unity is moving the Windows Editor from the static CRT (/MT) to the dynamic CRT (/MD) (PLAT-22757). A /MD Editor can't link the current /MT libprotobuf (LNK2038), so this adds /MD builds alongside the existing ones.

Changes

  • Upgrades Bee from a February 2023 build to the current production build (b649be378334), replacing the bootstrap scripts in bee/. The old Bee predates the Bee CRT rework (June 2024), and setting the CRT through compiler settings is broken in it.
  • The CRT is set on the toolchain: each Windows toolchain is listed twice, once with the static CRT (/MT) and once with the dynamic CRT (/MD), and the same libprotobuf program builds with both.
  • On Windows, the /MD builds go into lib/win/{x64,arm64}/MD/: libprotobuf.lib (/MD) and libprotobufd.lib (/MDd). The /MT libraries keep their current names and paths.
  • protoc now uses /MD on Windows and links the /MD library. It needs the VC++ runtime (normally already present on dev and build machines).
  • New Bee has no VS2017, so Windows x64 now builds with VS2019 (like arm64 already did). The Bee upgrade also rebuilds macOS and Linux with newer toolchains (for example, Clang_9_0_1() now uses clang 15.0.6).
  • The Bee target names in .yamato changed to win_x64, win_arm64 and linux_x64, because new Bee's toolchain action names include the compiler and CRT.
  • The Yamato Linux job moves to build-system/unity-ubuntu-22.04 (the image unity/unity uses for Bee), because the current Bee and its .NET 10 runtime need a newer glibc than the old image has.
  • .gitignore now covers the Bee outputs (artifacts/, builds/, build.gen.sln).

Testing

  • Built locally on x64 and arm64. The regular libs depend on LIBCMT/LIBCMTD and the MD/ libs on MSVCRT/MSVCRTD; protoc.exe imports the dynamic CRT. No LNK4098 or LNK2038 warnings.
  • protoc.exe --version runs on x64.
  • In a local Unity Editor build with the dynamic CRT turned on, libprotobuf links without CRT-mismatch errors (before the Bee upgrade; to be rechecked with the new artifact).
  • Yamato build of all platforms: https://unity-ci.cds.internal.unity3d.com/job/77719568

This description was updated by Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

Windows also builds libprotobuf with the dynamic CRT (/MD, /MDd in
Debug) into lib/win/{arch}/MD, for linking into a /MD Unity Editor.
The /MT libraries are unchanged. protoc now uses /MD on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread Build.bee.cs Outdated
// Windows also gets a dynamic CRT (/MD, /MDd in Debug) build in an MD subfolder, for linking into a /MD Unity Editor
var dynamicCrtNp = CreateLibProtobuf("libprotobuf_md");
dynamicCrtNp.OutputName.Add(c => c.CodeGen == CodeGen.Debug ? "libprotobufd" : "libprotobuf");
dynamicCrtNp.CompilerSettingsForMsvc().Add(s => s.WithCompilerRuntimeLibrary(CompilerRuntimeLibrary.Dynamic));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This seems to be using an old version of bee. With this version of bee, you'd set compiler runtime library using CompilerSettings. Unfortunately this was broken, I had to rewrite it in order to switch the player to dynamic CRT. You might have to upgrade bee for this to work correctly.

@philz-unity philz-unity Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Upgraded Bee to the current production build (b649be378334) and now set the CRT on the toolchain: each Windows toolchain is listed once with CompilerRuntimeLibrary.Static and once with CompilerRuntimeLibrary.Dynamic, and the same libprotobuf builds with both. The duplicated _md program and the WithCompilerRuntimeLibrary calls are gone (22899cc). S3TCompress and Umbra had the same problem and get the same fix in https://github.cds.internal.unity3d.com/unity/graphics.ati-texture.compressor/pull/6 and https://github.cds.internal.unity3d.com/unity/Umbra/pull/16.

(Reply written by Claude Code, Claude Opus 5.5, on behalf of Phil.)

philz-unity and others added 3 commits October 16, 2026 16:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread bee/bee.ps1

$ErrorActionPreference = "Stop"

try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is from the upgrade's artifacts, no code modified.

Comment thread bee/bee.bat
SETLOCAL
SET distributionDir=%~dp0
SET beePowerShellScript=%distributionDir%bee.ps1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is from the upgrade's artifacts, no code modified.

Comment thread Build.bee.cs Outdated
ToolChain.Store.Windows().VS2019().Sdk_17134().x64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Static),
ToolChain.Store.Windows().VS2019().Sdk_17134().x64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Dynamic),
ToolChain.Store.Windows().VS2019().Sdk_20348().Arm64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Static),
ToolChain.Store.Windows().VS2019().Sdk_20348().Arm64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Dynamic),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Might as well use VS2026 if you're upgrading the compiler, to match what the editor uses.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

And also it'd be good to use the same Windows SDK too :).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good idea.

philz-unity and others added 2 commits October 19, 2026 13:13
Match the Unity Editor's toolchain: MSVC 14.51.36231 and
Windows SDK 10.0.20348.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@philz-unity
philz-unity merged commit db300ef into v21.2-unity Oct 19, 2026
4 of 10 checks passed
@philz-unity
philz-unity deleted the platform/editor/windows-dynamic-crt branch October 19, 2026 22:30
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.

2 participants