Skip to content

Commit 5958ff6

Browse files
authored
Unity(JUMBO) build support (#307)
Add Jumbo Build support(MSBuild only) Jumbo builds is similar to Sharpmake blobbing system and fastbuild unity build support but specific to msbuild.
1 parent 91480bf commit 5958ff6

19 files changed

Lines changed: 748 additions & 0 deletions

SamplesDef.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@
209209
"&'./{testFolder}/projects/output/win64/{configuration}/helloWorld.exe'"
210210
]
211211
},
212+
{
213+
"Name": "JumboBuild",
214+
"CIs": [ "github", "gitlab" ],
215+
"OSs": [ "windows-2019", "windows-2022" ],
216+
"Frameworks": [ "net6.0" ],
217+
"Configurations": [ "debug", "release" ],
218+
"TestFolder": "samples/JumboBuild",
219+
"Commands":
220+
[
221+
"./RunSharpmake.ps1 -workingDirectory {testFolder} -sharpmakeFile \"JumboBuild.sharpmake.cs\" -framework {framework}",
222+
"./Compile.ps1 -slnOrPrjFile \"jumbobuild_vs2019_win64.sln\" -configuration {configuration} -platform \"x64\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
223+
"&'./{testFolder}/projects/output/win64/{configuration}/jumboBuild.exe'"
224+
]
225+
},
212226
{
213227
"Name": "NetCore-DotNetCoreFrameworkHelloWorld",
214228
"CIs": [ "gitlab" ],

Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,24 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG
10571057
Options.Option(Options.Vc.Compiler.EnableAsan.Enable, () => { context.Options["EnableASAN"] = "true"; context.CommandLineOptions["EnableASAN"] = "/fsanitize=address"; })
10581058
);
10591059

1060+
context.SelectOption
1061+
(
1062+
Options.Option(Options.Vc.Compiler.JumboBuild.Disable, () =>
1063+
{
1064+
context.Options["JumboBuild"] = FileGeneratorUtilities.RemoveLineTag;
1065+
context.Options["MaxFilesPerJumboFile"] = FileGeneratorUtilities.RemoveLineTag;
1066+
context.Options["MinFilesPerJumboFile"] = FileGeneratorUtilities.RemoveLineTag;
1067+
context.Options["MinJumboFiles"] = FileGeneratorUtilities.RemoveLineTag;
1068+
}),
1069+
Options.Option(Options.Vc.Compiler.JumboBuild.Enable, () =>
1070+
{
1071+
context.Options["JumboBuild"] = "true";
1072+
context.Options["MaxFilesPerJumboFile"] = context.Configuration.MaxFilesPerJumboFile.ToString();
1073+
context.Options["MinFilesPerJumboFile"] = context.Configuration.MinFilesPerJumboFile.ToString();
1074+
context.Options["MinJumboFiles"] = context.Configuration.MinJumboFiles.ToString();
1075+
})
1076+
);
1077+
10601078
if (context.DevelopmentEnvironment.IsVisualStudio() && context.DevelopmentEnvironment >= DevEnv.vs2017)
10611079
{
10621080
//Options.Vc.Compiler.DefineCPlusPlus. See: https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/

Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ public abstract partial class BasePlatform
180180
<WindowsTargetPlatformVersion>[options.WindowsTargetPlatformVersion]</WindowsTargetPlatformVersion>
181181
<SpectreMitigation>[options.SpectreMitigation]</SpectreMitigation>
182182
<EnableASAN>[options.EnableASAN]</EnableASAN>
183+
<EnableUnitySupport>[options.JumboBuild]</EnableUnitySupport>
184+
<MaxFilesInUnityFile>[options.MaxFilesPerJumboFile]</MaxFilesInUnityFile>
185+
<MinFilesInUnityFile>[options.MinFilesPerJumboFile]</MinFilesInUnityFile>
186+
<MinUnityFiles>[options.MinJumboFiles]</MinUnityFiles>
183187
</PropertyGroup>
184188
";
185189

Sharpmake/Options.Vc.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,20 @@ public enum EnableAsan
13481348
[DevEnvVersion(minimum = DevEnv.vs2019)]
13491349
Enable
13501350
}
1351+
1352+
/// <summary>
1353+
/// Enable Jumbo/Unity builds for msbuild. Only usable with msbuild.
1354+
/// </summary>
1355+
/// <remarks>
1356+
/// Merges multiple translation units together
1357+
/// </remarks>
1358+
public enum JumboBuild
1359+
{
1360+
[Default]
1361+
Disable,
1362+
[DevEnvVersion(minimum = DevEnv.vs2019)]
1363+
Enable
1364+
}
13511365
}
13521366

13531367
public static class CodeAnalysis

Sharpmake/Project.Configuration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,11 @@ public string FastBuildUnityPath
16051605
/// </remarks>
16061606
public bool DoNotGenerateFastBuild = false;
16071607

1608+
// Jumbo builds support for msbuild
1609+
public int MaxFilesPerJumboFile = 0;
1610+
public int MinFilesPerJumboFile = 2;
1611+
public int MinJumboFiles = 1;
1612+
16081613
// container for executable
16091614
/// <summary>
16101615
/// Represents a build step that invokes an executable on the file system.

UpdateSamplesOutput.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ call :UpdateRef samples CPPCLI CLRTest.sharpmake.cs
2222
if not "%ERRORLEVEL_BACKUP%" == "0" goto error
2323
call :UpdateRef samples CSharpHelloWorld HelloWorld.sharpmake.cs reference CSharpHelloWorld
2424
if not "%ERRORLEVEL_BACKUP%" == "0" goto error
25+
call :UpdateRef samples JumboBuild JumboBuild.sharpmake.cs reference JumboBuild
26+
if not "%ERRORLEVEL_BACKUP%" == "0" goto error
2527
call :UpdateRef samples HelloWorld HelloWorld.sharpmake.cs reference HelloWorld
2628
if not "%ERRORLEVEL_BACKUP%" == "0" goto error
2729
call :UpdateRef samples HelloLinux HelloLinux.Main.sharpmake.cs reference HelloLinux

regression_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def launch_tests():
147147
Test("CPPCLI", "CLRTest.sharpmake.cs"),
148148
Test("CSharpHelloWorld", "HelloWorld.sharpmake.cs"),
149149
Test("HelloWorld", "HelloWorld.sharpmake.cs"),
150+
Test("JumboBuild", "JumboBuild.sharpmake.cs"),
150151
Test("HelloLinux", "HelloLinux.Main.sharpmake.cs"),
151152
Test("HelloAssembly", "HelloAssembly.sharpmake.cs"),
152153
Test("CSharpVsix", "CSharpVsix.sharpmake.cs"),
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) Ubisoft. All Rights Reserved.
2+
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information.
3+
4+
using Sharpmake;
5+
6+
namespace JumboBuild
7+
{
8+
[Sharpmake.Generate]
9+
public class JumboBuildProject : Project
10+
{
11+
public JumboBuildProject()
12+
{
13+
Name = "JumboBuild";
14+
15+
AddTargets(new Target(
16+
Platform.win32 | Platform.win64,
17+
DevEnv.vs2019,
18+
Optimization.Debug | Optimization.Release
19+
));
20+
21+
SourceRootPath = @"[project.SharpmakeCsPath]\codebase";
22+
}
23+
24+
[Configure]
25+
public void ConfigureAll(Configuration conf, Target target)
26+
{
27+
conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]";
28+
conf.ProjectPath = @"[project.SharpmakeCsPath]\projects";
29+
30+
conf.Defines.Add("_HAS_EXCEPTIONS=0");
31+
32+
conf.CustomProperties.Add("CustomOptimizationProperty", $"Custom-{target.Optimization}");
33+
34+
conf.Options.Add(Options.Vc.Compiler.JumboBuild.Enable);
35+
conf.MaxFilesPerJumboFile = 0;
36+
conf.MinFilesPerJumboFile = 2;
37+
conf.MinJumboFiles = 1;
38+
}
39+
}
40+
41+
[Sharpmake.Generate]
42+
public class JumboBuildSolution : Sharpmake.Solution
43+
{
44+
public JumboBuildSolution()
45+
{
46+
Name = "JumboBuild";
47+
48+
AddTargets(new Target(
49+
Platform.win32 | Platform.win64,
50+
DevEnv.vs2019,
51+
Optimization.Debug | Optimization.Release
52+
));
53+
}
54+
55+
[Configure()]
56+
public void ConfigureAll(Configuration conf, Target target)
57+
{
58+
conf.SolutionFileName = "[solution.Name]_[target.DevEnv]_[target.Platform]";
59+
conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects";
60+
conf.AddProject<JumboBuildProject>(target);
61+
}
62+
}
63+
64+
public static class Main
65+
{
66+
[Sharpmake.Main]
67+
public static void SharpmakeMain(Sharpmake.Arguments arguments)
68+
{
69+
KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2019, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);
70+
arguments.Generate<JumboBuildSolution>();
71+
}
72+
}
73+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
#include "test1.h"
3+
#include "test2.h"
4+
5+
int main(int, char**)
6+
{
7+
std::cout << "I was built in "
8+
9+
#if _DEBUG
10+
"Debug"
11+
#endif
12+
13+
#if NDEBUG
14+
"Release"
15+
#endif
16+
17+
#if _WIN64
18+
" x64"
19+
#else
20+
" x86"
21+
#endif
22+
23+
<< std::endl;
24+
25+
std::cout << "test1: " << test1() << std::endl;
26+
std::cout << "test2: " << test2() << std::endl;
27+
28+
return 0;
29+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "test1.h"
2+
3+
int test1()
4+
{
5+
return 1;
6+
}

0 commit comments

Comments
 (0)