Skip to content

Commit

Permalink
Merge branch 'CompilerInputFilesRootFixesDuplicateFiles' into 'main'
Browse files Browse the repository at this point in the history
Add CompilerInputFilesRoot to the fastbuild bff using...

See merge request Sharpmake/sharpmake!593
  • Loading branch information
jspelletier committed Jan 13, 2025
2 parents b90afbf + 2f2570b commit dd19809
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 0 deletions.
14 changes: 14 additions & 0 deletions SamplesDef.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@
"&'./{testFolder}/projects/output/win64/{configuration}/fastbuildsimpleexecutable.exe'"
]
},
{
"Name": "FastBuildDuplicateFile",
"CIs": [ "github", "gitlab" ],
"OSs": [ "windows-2019", "windows-2022" ],
"Frameworks": [ "net6.0" ],
"Configurations": [ "debug", "release" ],
"TestFolder": "samples/FastBuildDuplicateFile",
"Commands":
[
"./RunSharpmake.ps1 -workingDirectory {testFolder} -sharpmakeFile \"FastBuildDuplicateFile.sharpmake.cs\" -framework {framework}",
"./Compile.ps1 -slnOrPrjFile \"fastbuildsample_{VsVersionSuffix}_win64_fastbuild.sln\" -configuration {configuration} -platform \"x64\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
"&'./{testFolder}/projects/output/win64/{configuration}/duplicatefileproject.exe'"
]
},
{
"Name": "HelloAndroid",
"CIs": [],
Expand Down
1 change: 1 addition & 0 deletions Sharpmake.Generators/FastBuild/Bff.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public static class ConfigurationFile
.CompilerInputPattern = [fastBuildCompilerInputPattern]
.CompilerInputExcludedFiles = [fastBuildInputExcludedFiles]
.CompilerInputFiles = [fastBuildSourceFiles]
.CompilerInputFilesRoot = '[fastBuildInputFilesRootPath]'
";

Expand Down
8 changes: 8 additions & 0 deletions Sharpmake.Generators/FastBuild/Bff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,13 @@ List<string> skipFiles
fastBuildProjectDependencies.Add("[fastBuildOutputFileShortName]_objects");
string fastBuildObjectListEmbeddedResources = FormatListPartForTag(embeddedResourceFilesSections, 32, true);

string fastBuildInputFilesRootPath = FileGeneratorUtilities.RemoveLineTag;

if (conf.FastBuildInputFilesRootPath != null)
{
fastBuildInputFilesRootPath = CurrentBffPathKeyCombine(Util.PathGetRelative(context.ProjectDirectory, conf.FastBuildInputFilesRootPath));
}

using (bffGenerator.Declare("conf", conf))
using (bffGenerator.Declare("project", project))
using (bffGenerator.Declare("target", conf.Target))
Expand Down Expand Up @@ -1170,6 +1177,7 @@ List<string> skipFiles
using (bffGenerator.Declare("fastBuildLibrarianAdditionalInputs", librarianAdditionalInputs))
using (bffGenerator.Declare("fastBuildCompileAsC", fastBuildCompileAsC))
using (bffGenerator.Declare("fastBuildUnityName", fastBuildUnityName ?? FileGeneratorUtilities.RemoveLineTag))
using (bffGenerator.Declare("fastBuildInputFilesRootPath", fastBuildInputFilesRootPath))
using (bffGenerator.Declare("fastBuildClangFileLanguage", clangFileLanguage))
using (bffGenerator.Declare("fastBuildDeoptimizationWritableFiles", fastBuildDeoptimizationWritableFiles))
using (bffGenerator.Declare("fastBuildDeoptimizationWritableFilesWithToken", fastBuildDeoptimizationWritableFilesWithToken))
Expand Down
2 changes: 2 additions & 0 deletions Sharpmake/Project.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ public string FastBuildUnityPath
set { _fastBuildUnityPath = value; }
}

public string FastBuildInputFilesRootPath = null;

/// <summary>
/// If specified, overrides <c>Project.DefaultBlobWorkFileHeader</c>.
/// </summary>
Expand Down
124 changes: 124 additions & 0 deletions samples/FastBuildDuplicateFile/FastBuildDuplicateFile.sharpmake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) Ubisoft. All Rights Reserved.
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information.

using System.IO;
using Sharpmake;

namespace FastBuildDuplicateFile
{
public static class Globals
{
// branch root path relative to current sharpmake file location
public const string RelativeRootPath = @".\codebase";
public static string RootDirectory;
}

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

StripFastBuildSourceFiles = false;

AddTargets(new Target(
Platform.win64,
DevEnv.vs2019 | DevEnv.vs2022,
Optimization.Debug | Optimization.Release,
OutputType.Lib,
Blob.NoBlob,
BuildSystem.FastBuild | BuildSystem.MSBuild
));

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

[Configure()]
public void ConfigureAll(Configuration conf, Target target)
{
conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]_[target.BuildSystem]";
conf.ProjectPath = @"[project.SharpmakeCsPath]\projects";
conf.Options.Add(Options.Vc.Compiler.Exceptions.Enable);
}

[Configure(BuildSystem.FastBuild)]
public void ConfigureFastBuild(Configuration conf, Target target)
{
conf.IsFastBuild = true;
conf.FastBuildBlobbed = target.Blob == Blob.FastBuildUnitys;
conf.FastBuildInputFilesRootPath = SourceRootPath;

// Force writing to pdb from different cl.exe process to go through the pdb server
conf.AdditionalCompilerOptions.Add("/FS");
}

[Configure(Optimization.Release)]
public virtual void ConfigureRelease(Configuration conf, Target target)
{
// Testing generation of what is needed for working fastbuild deoptimization when using non-exposed compiler optimization options.
conf.AdditionalCompilerOptimizeOptions.Add("/O2"); // This switch is known but for the purpose of this test we will put in in this field.
conf.AdditionalCompilerOptimizeOptions.Add("/Os"); // This switch is known but for the purpose of this test we will put in in this field.
conf.AdditionalCompilerOptions.Add("/bigobj");
conf.FastBuildDeoptimization = Configuration.DeoptimizationWritableFiles.DeoptimizeWritableFiles;
}
}

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

AddTargets(new Target(
Platform.win64,
DevEnv.vs2019 | DevEnv.vs2022,
Optimization.Debug | Optimization.Release,
OutputType.Lib,
Blob.NoBlob,
BuildSystem.FastBuild | BuildSystem.MSBuild
));
}

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

conf.AddProject<DuplicateFileProject>(target);
}
}

public static class Main
{
private static void ConfigureRootDirectory()
{
FileInfo fileInfo = Util.GetCurrentSharpmakeFileInfo();
string rootDirectory = Path.Combine(fileInfo.DirectoryName, Globals.RelativeRootPath);
Globals.RootDirectory = Util.SimplifyPath(rootDirectory);
}

[Sharpmake.Main]
public static void SharpmakeMain(Sharpmake.Arguments arguments)
{
ConfigureRootDirectory();

// for the purpose of this sample, we'll reuse the FastBuild executable that live in the sharpmake source repo
string sharpmakeFastBuildDir = Util.PathGetAbsolute(Globals.RootDirectory, @"..\..\..\tools\FastBuild");
FastBuildSettings.FastBuildMakeCommand = Path.Combine(sharpmakeFastBuildDir, "Windows-x64", "FBuild.exe");

// This is necessary since there is no rc.exe in the same directory than link.exe
FastBuildSettings.SetPathToResourceCompilerInEnvironment = true;

// Add an additional environment variable for fastbuild for testing
FastBuildSettings.AdditionalGlobalEnvironmentVariables.Add("KEY", "VALUE");

KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2019, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);
KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2022, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);

arguments.Generate<DuplicateFileSolution>();
}
}
}
10 changes: 10 additions & 0 deletions samples/FastBuildDuplicateFile/codebase/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>

#include "test1/test.h"
#include "test2/test.h"

int main(int, char**)
{
std::cout << "I have two files named test.h. test1 makes " << test1() << ". test2 makes " << test2() << "." << std::endl;
return 0;
}
3 changes: 3 additions & 0 deletions samples/FastBuildDuplicateFile/codebase/test1/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "test.h"

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

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

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

int test2();
6 changes: 6 additions & 0 deletions samples/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"commandLineArgs": "/sources(@'FastBuildSimpleExecutable.sharpmake.cs')",
"workingDirectory": "$(ProjectDir)\\FastBuildSimpleExecutable"
},
"Sample (FastBuildDuplicateFile)": {
"commandName": "Executable",
"executablePath": "$(ProjectDir)\\..\\Sharpmake.Application\\bin\\$(Configuration)\\$(TargetFramework)\\Sharpmake.Application.exe",
"commandLineArgs": "/sources(@'FastBuildDuplicateFile.sharpmake.cs')",
"workingDirectory": "$(ProjectDir)\\FastBuildDuplicateFile"
},
"Sample (HelloAndroid)": {
"commandName": "Executable",
"executablePath": "$(ProjectDir)\\..\\Sharpmake.Application\\bin\\$(Configuration)\\$(TargetFramework)\\Sharpmake.Application.exe",
Expand Down

0 comments on commit dd19809

Please sign in to comment.