Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity(JUMBO) build support #307

Merged
merged 21 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions SamplesDef.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@
"&'./{testFolder}/projects/output/win64/{configuration}/helloWorld.exe'"
]
},
{
"Name": "JumboBuild",
"CIs": [ "github", "gitlab" ],
"OSs": [ "windows-2019", "windows-2022" ],
"Frameworks": [ "net6.0" ],
"Configurations": [ "debug", "release" ],
"TestFolder": "samples/JumboBuild",
"Commands":
[
"./RunSharpmake.ps1 -workingDirectory {testFolder} -sharpmakeFile \"JumboBuild.sharpmake.cs\" -framework {framework}",
"./Compile.ps1 -slnOrPrjFile \"jumbobuild_vs2019_win32.sln\" -configuration {configuration} -platform \"Win32\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
Say-Y marked this conversation as resolved.
Show resolved Hide resolved
"&'./{testFolder}/projects/output/win32/{configuration}/jumboBuild.exe'",
"./Compile.ps1 -slnOrPrjFile \"jumbobuild_vs2019_win64.sln\" -configuration {configuration} -platform \"x64\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
"&'./{testFolder}/projects/output/win64/{configuration}/jumboBuild.exe'"
]
},
{
"Name": "NetCore-DotNetCoreFrameworkHelloWorld",
"CIs": [ "gitlab" ],
Expand Down
18 changes: 18 additions & 0 deletions Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,24 @@ private void GenerateCompilerOptions(IGenerationContext context, ProjectOptionsG
Options.Option(Options.Vc.Compiler.EnableAsan.Enable, () => { context.Options["EnableASAN"] = "true"; context.CommandLineOptions["EnableASAN"] = "/fsanitize=address"; })
);

context.SelectOption
(
Options.Option(Options.Vc.Compiler.JumboBuild.Disable, () =>
{
context.Options["JumboBuild"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["MaxFilesPerJumboFile"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["MinFilesPerJumboFile"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["MinJumboFiles"] = FileGeneratorUtilities.RemoveLineTag;
}),
Options.Option(Options.Vc.Compiler.JumboBuild.Enable, () =>
{
context.Options["JumboBuild"] = "true";
context.Options["MaxFilesPerJumboFile"] = context.Configuration.MaxFilesPerJumboFile.ToString();
context.Options["MinFilesPerJumboFile"] = context.Configuration.MinFilesPerJumboFile.ToString();
context.Options["MinJumboFiles"] = context.Configuration.MinJumboFiles.ToString();
})
);

if (context.DevelopmentEnvironment.IsVisualStudio() && context.DevelopmentEnvironment >= DevEnv.vs2017)
{
//Options.Vc.Compiler.DefineCPlusPlus. See: https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public abstract partial class BasePlatform
<WindowsTargetPlatformVersion>[options.WindowsTargetPlatformVersion]</WindowsTargetPlatformVersion>
<SpectreMitigation>[options.SpectreMitigation]</SpectreMitigation>
<EnableASAN>[options.EnableASAN]</EnableASAN>
<EnableUnitySupport>[options.JumboBuild]</EnableUnitySupport>
<MaxFilesInUnityFile>[options.MaxFilesPerJumboFile]</MaxFilesInUnityFile>
<MinFilesInUnityFile>[options.MinFilesPerJumboFile]</MinFilesInUnityFile>
<MinUnityFiles>[options.MinJumboFiles]</MinUnityFiles>
</PropertyGroup>
";

Expand Down
14 changes: 14 additions & 0 deletions Sharpmake/Options.Vc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,20 @@ public enum EnableAsan
[DevEnvVersion(minimum = DevEnv.vs2019)]
Enable
}

/// <summary>
/// Enable Jumbo/Unity builds
Say-Y marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// Merges multiple translation units together
/// </remarks>
public enum JumboBuild
{
[Default]
Disable,
[DevEnvVersion(minimum = DevEnv.vs2019)]
Enable
}
}

public static class CodeAnalysis
Expand Down
5 changes: 5 additions & 0 deletions Sharpmake/Project.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,11 @@ public string FastBuildUnityPath
/// </remarks>
public bool DoNotGenerateFastBuild = false;

// Jumbo builds support
Say-Y marked this conversation as resolved.
Show resolved Hide resolved
public int MaxFilesPerJumboFile = 0;
public int MinFilesPerJumboFile = 2;
public int MinJumboFiles = 1;

// container for executable
/// <summary>
/// Represents a build step that invokes an executable on the file system.
Expand Down
1 change: 1 addition & 0 deletions regression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def launch_tests():
Test("CPPCLI", "CLRTest.sharpmake.cs"),
Test("CSharpHelloWorld", "HelloWorld.sharpmake.cs"),
Test("HelloWorld", "HelloWorld.sharpmake.cs"),
Test("JumboBuild", "JumboBuild.sharpmake.cs"),
Test("HelloLinux", "HelloLinux.Main.sharpmake.cs"),
Say-Y marked this conversation as resolved.
Show resolved Hide resolved
Test("HelloAssembly", "HelloAssembly.sharpmake.cs"),
Test("CSharpVsix", "CSharpVsix.sharpmake.cs"),
Expand Down
73 changes: 73 additions & 0 deletions samples/JumboBuild/JumboBuild.sharpmake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Ubisoft. All Rights Reserved.
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information.

using Sharpmake;

namespace JumboBuild
{
[Sharpmake.Generate]
public class JumboBuildProject : Project
{
public JumboBuildProject()
{
Name = "JumboBuild";

AddTargets(new Target(
Platform.win32 | Platform.win64,
Say-Y marked this conversation as resolved.
Show resolved Hide resolved
DevEnv.vs2019,
Optimization.Debug | Optimization.Release
));

SourceRootPath = @"[project.SharpmakeCsPath]\codebase";
}

[Configure]
public void ConfigureAll(Configuration conf, Target target)
{
conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]";
conf.ProjectPath = @"[project.SharpmakeCsPath]\projects";

conf.Defines.Add("_HAS_EXCEPTIONS=0");

conf.CustomProperties.Add("CustomOptimizationProperty", $"Custom-{target.Optimization}");

conf.Options.Add(Options.Vc.Compiler.JumboBuild.Enable);
conf.MaxFilesPerJumboFile = 0;
conf.MinFilesPerJumboFile = 2;
conf.MinJumboFiles = 1;
}
}

[Sharpmake.Generate]
public class JumboBuildSolution : Sharpmake.Solution
{
public JumboBuildSolution()
{
Name = "JumboBuild";

AddTargets(new Target(
Platform.win32 | Platform.win64,
DevEnv.vs2019,
Optimization.Debug | Optimization.Release
));
}

[Configure()]
public void ConfigureAll(Configuration conf, Target target)
{
conf.SolutionFileName = "[solution.Name]_[target.DevEnv]_[target.Platform]";
conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects";
conf.AddProject<JumboBuildProject>(target);
}
}

public static class Main
{
[Sharpmake.Main]
public static void SharpmakeMain(Sharpmake.Arguments arguments)
{
KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2019, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);
arguments.Generate<JumboBuildSolution>();
}
}
}
29 changes: 29 additions & 0 deletions samples/JumboBuild/codebase/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include "test1.h"
#include "test2.h"

int main(int, char**)
{
std::cout << "I was built in "

#if _DEBUG
"Debug"
#endif

#if NDEBUG
"Release"
#endif

#if _WIN64
" x64"
#else
" x86"
#endif

<< std::endl;

std::cout << "test1: " << test1() << std::endl;
std::cout << "test2: " << test2() << std::endl;

return 0;
}
6 changes: 6 additions & 0 deletions samples/JumboBuild/codebase/test1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "test1.h"

int test1()
{
return 1;
}
3 changes: 3 additions & 0 deletions samples/JumboBuild/codebase/test1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int test1();
6 changes: 6 additions & 0 deletions samples/JumboBuild/codebase/test2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "test2.h"

int test2()
{
return 2;
}
3 changes: 3 additions & 0 deletions samples/JumboBuild/codebase/test2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int test2();