Skip to content

Commit db300ef

Browse files
philz-unityclaude
andauthored
[PLAT-22844] Add /MD Windows builds of libprotobuf (#7)
* [PLAT-22844] Add /MD Windows builds of libprotobuf 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> * [PLAT-22844] Upgrade Bee and set the CRT on the toolchain Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * [PLAT-22844] Use Yamato images that can run current Bee Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * [PLAT-22844] Fix the Linux and Mac builds with current Bee Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * [PLAT-22844] Build Windows with VS2026 and SDK 20348 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> * [PLAT-22844] Rename the Windows job for VS2026 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7004ddc commit db300ef

7 files changed

Lines changed: 440 additions & 287 deletions

File tree

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,8 @@ BenchmarkDotNet.Artifacts/
215215
# Clangd uses these common ephemeral files
216216
.cache
217217
compile_commands.json
218+
219+
# Bee build outputs
220+
/artifacts/
221+
/builds/
222+
/build.gen.sln

‎.yamato/build-linux-x64.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build protobuf - CentOS 7 x64 with Clang9
22

33
agent:
44
type: Unity::VM
5-
image: platform-foundation/linux-bokken:latest
5+
image: build-system/unity-ubuntu-22.04:v2.9071485
66
flavor: b1.small
77

88
artifacts:
@@ -13,4 +13,4 @@ artifacts:
1313
# After building, recursively copy .h and .inc files from the source to the destination, then rename the folder.
1414
# This is a superset of what make does, but only a couple of extra test files are included.
1515
commands:
16-
- bash ./bee/bee linux_x64_clang
16+
- bash ./bee/bee linux_x64

‎.yamato/build-windows-all.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
windows-c-libraries:
2-
name: Build protobuf - Windows 10 x64 with VS 2017
2+
name: Build protobuf - Windows x64 and arm64 with VS 2026
33

44
agent:
55
type: Unity::VM
@@ -12,8 +12,8 @@ windows-c-libraries:
1212
- builds/**
1313

1414
commands:
15-
- .\bee\bee win_x64_vs2017_win7
16-
- .\bee\bee win_arm64_vs2019_win7
15+
- .\bee\bee win_x64
16+
- .\bee\bee win_arm64
1717

1818
csharp-bindings:
1919
name: Build C# Bindings

‎Build.bee.cs‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static NativeProgram SetupLibProtobuf(IEnumerable<ToolChain> toolchains)
121121
var nativeProgramConfiguration = new NativeProgramConfiguration(codegen, toolchain, lump: true);
122122
var format = toolchain.StaticLibraryFormat;
123123
var deployedProgram = np.SetupSpecificConfiguration(nativeProgramConfiguration, format).DeployTo(GetBuildTargetDir(toolchain));
124-
Backend.Current.AddAliasDependency(toolchain.ActionName, deployedProgram.Path);
124+
Backend.Current.AddAliasDependency(AliasFor(toolchain), deployedProgram.Path);
125125

126126
if (toolchain.Platform is LinuxPlatform)
127127
{
@@ -232,44 +232,64 @@ static NativeProgram SetupProtoc(IEnumerable<ToolChain> toolchains, NativeProgra
232232
np.CompilerSettingsForGccLike().Add(s => s.WithGlibcxxUseCxx11Abi(true));
233233
np.Libraries.Add(libProtobuf);
234234

235-
foreach (var toolchain in toolchains)
235+
// On Windows protoc is built with the dynamic CRT (/MD) only
236+
foreach (var toolchain in toolchains.Where(t => !IsStaticCrtWindows(t)))
236237
{
237238
var nativeProgramConfiguration = new NativeProgramConfiguration(CodeGen.Release, toolchain, lump: true);
238239

239240
var format = toolchain.ExecutableFormat;
240241

241242
var deployedProgram = np.SetupSpecificConfiguration(nativeProgramConfiguration, format).DeployTo(GetBuildTargetDir(toolchain, true));
242-
Backend.Current.AddAliasDependency(toolchain.ActionName, deployedProgram.Path);
243+
Backend.Current.AddAliasDependency(AliasFor(toolchain), deployedProgram.Path);
243244
}
244245

245246
return np;
246247
}
247248

249+
static bool IsStaticCrtWindows(ToolChain toolchain) =>
250+
toolchain is VisualStudioToolchain vs && vs.CompilerRuntimeLibrary == CompilerRuntimeLibrary.Static;
251+
252+
static string AliasFor(ToolChain toolchain)
253+
{
254+
var platform = toolchain.Platform switch
255+
{
256+
WindowsPlatform => "win",
257+
LinuxPlatform => "linux",
258+
MacOSXPlatform => "mac",
259+
_ => throw new ArgumentException($"Don't know alias for toolchain {toolchain.ActionName}")
260+
};
261+
return $"{platform}_{toolchain.Architecture.DisplayName}";
262+
}
263+
248264
static NPath GetBuildTargetDir(ToolChain toolchain, bool isExecutable = false)
249265
{
250266
var mapping = new Dictionary<string, string>
251267
{
252268
{"mac_x64", "macos/x64"},
253269
{"mac_arm64", "macos/arm64"},
254-
{"linux_x64_clang", "linux"},
255-
{"win_x64_vs2017_win7", "win/x64"},
256-
{"win_arm64_vs2019_win7", "win/arm64"},
270+
{"linux_x64", "linux"},
271+
{"win_x64", "win/x64"},
272+
{"win_arm64", "win/arm64"},
257273
};
258274

259-
var name = toolchain.ActionName.ToLowerInvariant();
275+
var name = AliasFor(toolchain);
260276
if (!mapping.ContainsKey(name))
261277
throw new ArgumentException($"Don't know output path for toolchain {name}");
262278

279+
// Windows libraries built with the dynamic CRT (/MD, /MDd in Debug) go in an MD subfolder, for linking into a /MD Unity Editor
263280
var typePath = isExecutable ? "bin" : "lib";
264-
return $"builds/{typePath}/{mapping[name]}";
281+
var crtPath = !isExecutable && toolchain is VisualStudioToolchain { CompilerRuntimeLibrary: CompilerRuntimeLibrary.Dynamic } ? "/MD" : "";
282+
return $"builds/{typePath}/{mapping[name]}{crtPath}";
265283
}
266284

267285
static IEnumerable<ToolChain> GetToolchains()
268286
{
269287
var toolchains = new ToolChain[] {
270-
ToolChain.Store.Windows().VS2017().Sdk_17134().x64(),
271-
ToolChain.Store.Windows().VS2019().Sdk_20348().Arm64(),
272-
ToolChain.Store.Linux().Centos_7_7_1908().Clang_9_0_1().x64(),
288+
ToolChain.Store.Windows().VS2026().Sdk_20348().x64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Static),
289+
ToolChain.Store.Windows().VS2026().Sdk_20348().x64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Dynamic),
290+
ToolChain.Store.Windows().VS2026().Sdk_20348().Arm64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Static),
291+
ToolChain.Store.Windows().VS2026().Sdk_20348().Arm64(TargetWindowsVersion.Windows7, CompilerRuntimeLibrary.Dynamic),
292+
ToolChain.Store.Linux().GLibC_2_35().LLVM_15_0().x64(),
273293
ToolChain.Store.Mac().Sdk_11_0().x64(),
274294
ToolChain.Store.Mac().Sdk_11_0().ARM64(),
275295
}.Where(t => t != null).ToArray();

0 commit comments

Comments
 (0)