diff --git a/SamplesDef.json b/SamplesDef.json index cf56cd255..b1fee3298 100644 --- a/SamplesDef.json +++ b/SamplesDef.json @@ -209,6 +209,20 @@ "&'./{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_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" ], diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index b8038237e..1cb7a6199 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -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/ diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs index dcb734b2e..e39d00dd7 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.Vcxproj.Template.cs @@ -180,6 +180,10 @@ public abstract partial class BasePlatform [options.WindowsTargetPlatformVersion] [options.SpectreMitigation] [options.EnableASAN] + [options.JumboBuild] + [options.MaxFilesPerJumboFile] + [options.MinFilesPerJumboFile] + [options.MinJumboFiles] "; diff --git a/Sharpmake/Options.Vc.cs b/Sharpmake/Options.Vc.cs index f2f776fb8..2b22eec74 100644 --- a/Sharpmake/Options.Vc.cs +++ b/Sharpmake/Options.Vc.cs @@ -1348,6 +1348,20 @@ public enum EnableAsan [DevEnvVersion(minimum = DevEnv.vs2019)] Enable } + + /// + /// Enable Jumbo/Unity builds for msbuild. Only usable with msbuild. + /// + /// + /// Merges multiple translation units together + /// + public enum JumboBuild + { + [Default] + Disable, + [DevEnvVersion(minimum = DevEnv.vs2019)] + Enable + } } public static class CodeAnalysis diff --git a/Sharpmake/Project.Configuration.cs b/Sharpmake/Project.Configuration.cs index 49481db24..d808a21f5 100644 --- a/Sharpmake/Project.Configuration.cs +++ b/Sharpmake/Project.Configuration.cs @@ -1605,6 +1605,11 @@ public string FastBuildUnityPath /// public bool DoNotGenerateFastBuild = false; + // Jumbo builds support for msbuild + public int MaxFilesPerJumboFile = 0; + public int MinFilesPerJumboFile = 2; + public int MinJumboFiles = 1; + // container for executable /// /// Represents a build step that invokes an executable on the file system. diff --git a/UpdateSamplesOutput.bat b/UpdateSamplesOutput.bat index e5d26c4c9..c3dbe64b0 100644 --- a/UpdateSamplesOutput.bat +++ b/UpdateSamplesOutput.bat @@ -22,6 +22,8 @@ call :UpdateRef samples CPPCLI CLRTest.sharpmake.cs if not "%ERRORLEVEL_BACKUP%" == "0" goto error call :UpdateRef samples CSharpHelloWorld HelloWorld.sharpmake.cs reference CSharpHelloWorld if not "%ERRORLEVEL_BACKUP%" == "0" goto error +call :UpdateRef samples JumboBuild JumboBuild.sharpmake.cs reference JumboBuild +if not "%ERRORLEVEL_BACKUP%" == "0" goto error call :UpdateRef samples HelloWorld HelloWorld.sharpmake.cs reference HelloWorld if not "%ERRORLEVEL_BACKUP%" == "0" goto error call :UpdateRef samples HelloLinux HelloLinux.Main.sharpmake.cs reference HelloLinux diff --git a/regression_test.py b/regression_test.py index 5e51bf9ad..f0f65a4cb 100644 --- a/regression_test.py +++ b/regression_test.py @@ -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"), Test("HelloAssembly", "HelloAssembly.sharpmake.cs"), Test("CSharpVsix", "CSharpVsix.sharpmake.cs"), diff --git a/samples/JumboBuild/JumboBuild.sharpmake.cs b/samples/JumboBuild/JumboBuild.sharpmake.cs new file mode 100644 index 000000000..c3f76a4ae --- /dev/null +++ b/samples/JumboBuild/JumboBuild.sharpmake.cs @@ -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, + 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(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(); + } + } +} diff --git a/samples/JumboBuild/codebase/main.cpp b/samples/JumboBuild/codebase/main.cpp new file mode 100644 index 000000000..e046aa031 --- /dev/null +++ b/samples/JumboBuild/codebase/main.cpp @@ -0,0 +1,29 @@ +#include +#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; +} diff --git a/samples/JumboBuild/codebase/test1.cpp b/samples/JumboBuild/codebase/test1.cpp new file mode 100644 index 000000000..5e26e9964 --- /dev/null +++ b/samples/JumboBuild/codebase/test1.cpp @@ -0,0 +1,6 @@ +#include "test1.h" + +int test1() +{ + return 1; +} diff --git a/samples/JumboBuild/codebase/test1.h b/samples/JumboBuild/codebase/test1.h new file mode 100644 index 000000000..39a74fa7f --- /dev/null +++ b/samples/JumboBuild/codebase/test1.h @@ -0,0 +1,3 @@ +#pragma once + +int test1(); diff --git a/samples/JumboBuild/codebase/test2.cpp b/samples/JumboBuild/codebase/test2.cpp new file mode 100644 index 000000000..5ab97c07e --- /dev/null +++ b/samples/JumboBuild/codebase/test2.cpp @@ -0,0 +1,6 @@ +#include "test2.h" + +int test2() +{ + return 2; +} diff --git a/samples/JumboBuild/codebase/test2.h b/samples/JumboBuild/codebase/test2.h new file mode 100644 index 000000000..512b315e3 --- /dev/null +++ b/samples/JumboBuild/codebase/test2.h @@ -0,0 +1,3 @@ +#pragma once + +int test2(); diff --git a/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.sln b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.sln new file mode 100644 index 000000000..ef2a4d77a --- /dev/null +++ b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29424.173 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JumboBuild", "jumbobuild_vs2019_win32.vcxproj", "{7E5D7FA3-1BD1-D52B-649E-C932F0163E62}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7E5D7FA3-1BD1-D52B-649E-C932F0163E62}.Debug|Win32.ActiveCfg = Debug|Win32 + {7E5D7FA3-1BD1-D52B-649E-C932F0163E62}.Debug|Win32.Build.0 = Debug|Win32 + {7E5D7FA3-1BD1-D52B-649E-C932F0163E62}.Release|Win32.ActiveCfg = Release|Win32 + {7E5D7FA3-1BD1-D52B-649E-C932F0163E62}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.vcxproj b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.vcxproj new file mode 100644 index 000000000..4bf2597b1 --- /dev/null +++ b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.vcxproj @@ -0,0 +1,252 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {7E5D7FA3-1BD1-D52B-649E-C932F0163E62} + en-US + JumboBuild + JumboBuild + + + 10.0.19041.0 + + + + Application + true + MultiByte + false + v142 + true + 0 + 2 + 1 + + + Application + false + MultiByte + false + v142 + true + 0 + 2 + 1 + + + + + + + + + + jumbobuild + output\win32\debug\ + obj\win32\debug\ + .exe + true + false + output\win32\debug\jumbobuild.exe + false + + + Custom-Debug + + + jumbobuild + output\win32\release\ + obj\win32\release\ + .exe + true + false + output\win32\release\jumbobuild.exe + false + + + Custom-Release + + + + NotUsing + Level4 + Disabled + WIN32;_CONSOLE;_DEBUG;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions);$(PreprocessorDefinitions) + ProgramDatabase + true + false + true + false + OnlyExplicitInline + true + Neither + false + false + false + false + false + false + false + false + true + false + false + Default + MultiThreadedDebug + Default + true + false + NotSet + Fast + false + false + true + true + false + false + false + NoListing + false + false + Cdecl + Default + /Zc:__cplusplus + obj\win32\debug\jumbobuild_compiler.pdb + MultiThreadedDebug + + + Console + true + output\win32\debug\jumbobuild.exe + NotSet + output\win32\debug\jumbobuild.pdb + true + false + false + false + NotSet + false + false + + + Default + false + 1 + false + false + false + MachineX86 + false + Default + PromptImmediately + ;%(AdditionalDependencies) + true + false + + true + output\win32\debug\jumbobuild.map + + + + + NotUsing + Level4 + Full + NDEBUG;WIN32;_CONSOLE;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions);$(PreprocessorDefinitions) + ProgramDatabase + true + false + true + false + AnySuitable + true + Speed + false + false + false + false + false + false + false + false + true + false + false + Default + MultiThreaded + Default + false + true + NotSet + Fast + false + false + true + true + false + false + false + NoListing + false + false + Cdecl + Default + /Zc:__cplusplus + obj\win32\release\jumbobuild_compiler.pdb + MultiThreaded + + + Console + true + output\win32\release\jumbobuild.exe + NotSet + output\win32\release\jumbobuild.pdb + true + false + false + false + NotSet + true + true + + + Default + false + 1 + false + false + false + MachineX86 + false + Default + PromptImmediately + ;%(AdditionalDependencies) + true + false + + true + output\win32\release\jumbobuild.map + + + + + + + + + + + + + + + diff --git a/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.vcxproj.filters b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.vcxproj.filters new file mode 100644 index 000000000..b9bc2ee9d --- /dev/null +++ b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win32.vcxproj.filters @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.sln b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.sln new file mode 100644 index 000000000..d5d47d6ac --- /dev/null +++ b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29424.173 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JumboBuild", "jumbobuild_vs2019_win64.vcxproj", "{8A1D15AD-7B70-583E-0E94-FB3022C29864}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8A1D15AD-7B70-583E-0E94-FB3022C29864}.Debug|x64.ActiveCfg = Debug|x64 + {8A1D15AD-7B70-583E-0E94-FB3022C29864}.Debug|x64.Build.0 = Debug|x64 + {8A1D15AD-7B70-583E-0E94-FB3022C29864}.Release|x64.ActiveCfg = Release|x64 + {8A1D15AD-7B70-583E-0E94-FB3022C29864}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.vcxproj b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.vcxproj new file mode 100644 index 000000000..17e6e2774 --- /dev/null +++ b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.vcxproj @@ -0,0 +1,252 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {8A1D15AD-7B70-583E-0E94-FB3022C29864} + en-US + JumboBuild + JumboBuild + + + 10.0.19041.0 + + + + Application + true + MultiByte + false + v142 + true + 0 + 2 + 1 + + + Application + false + MultiByte + false + v142 + true + 0 + 2 + 1 + + + + + + + + + + jumbobuild + output\win64\debug\ + obj\win64\debug\ + .exe + true + false + output\win64\debug\jumbobuild.exe + false + + + Custom-Debug + + + jumbobuild + output\win64\release\ + obj\win64\release\ + .exe + true + false + output\win64\release\jumbobuild.exe + false + + + Custom-Release + + + + NotUsing + Level4 + Disabled + WIN64;_CONSOLE;_DEBUG;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions);$(PreprocessorDefinitions) + ProgramDatabase + true + false + true + false + OnlyExplicitInline + true + Neither + false + false + false + false + false + false + false + false + true + false + false + Default + MultiThreadedDebug + Default + true + false + NotSet + Fast + false + false + true + true + false + false + false + NoListing + false + false + Cdecl + Default + /Zc:__cplusplus + obj\win64\debug\jumbobuild_compiler.pdb + MultiThreadedDebug + + + Console + true + output\win64\debug\jumbobuild.exe + NotSet + output\win64\debug\jumbobuild.pdb + true + false + false + false + NotSet + false + false + + + Default + false + 1 + false + false + false + MachineX64 + false + Default + PromptImmediately + ;%(AdditionalDependencies) + true + false + + true + output\win64\debug\jumbobuild.map + + + + + NotUsing + Level4 + Full + NDEBUG;WIN64;_CONSOLE;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions);$(PreprocessorDefinitions) + ProgramDatabase + true + false + true + false + AnySuitable + true + Speed + false + false + false + false + false + false + false + false + true + false + false + Default + MultiThreaded + Default + false + true + NotSet + Fast + false + false + true + true + false + false + false + NoListing + false + false + Cdecl + Default + /Zc:__cplusplus + obj\win64\release\jumbobuild_compiler.pdb + MultiThreaded + + + Console + true + output\win64\release\jumbobuild.exe + NotSet + output\win64\release\jumbobuild.pdb + true + false + false + false + NotSet + true + true + + + Default + false + 1 + false + false + false + MachineX64 + false + Default + PromptImmediately + ;%(AdditionalDependencies) + true + false + + true + output\win64\release\jumbobuild.map + + + + + + + + + + + + + + + diff --git a/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.vcxproj.filters b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.vcxproj.filters new file mode 100644 index 000000000..b9bc2ee9d --- /dev/null +++ b/samples/JumboBuild/reference/projects/jumbobuild_vs2019_win64.vcxproj.filters @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file