Skip to content

Commit

Permalink
- Add the possibility for a platform to register extra stamp events
Browse files Browse the repository at this point in the history
- Add an option FastBuildSupportLinkerStampList  to FastBuildSettings, to indicate if the fastbuild exe that's used support multi stamping (that's a feature that's only in the internal fastbuild fork atm)
- Use the extra stamp events on linux to strip debug symbol info, that will fix un-necessary rebuilds when cross compiling with FastBuild for linux
  • Loading branch information
belkiss committed Apr 27, 2022
1 parent 41c6be9 commit f424cac
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
37 changes: 24 additions & 13 deletions Sharpmake.Generators/FastBuild/Bff.cs
Expand Up @@ -585,7 +585,11 @@ List<string> skipFiles
postBuildEvents.Add(eventPair.Key, eventPair.Value);
}

var extraPlatformEvents = platformBff.GetExtraPostBuildEvents(conf, fastBuildOutputFile).Select(step => { step.Resolve(resolver); return step; });
var extraPlatformEvents = new List<Project.Configuration.BuildStepBase>();
if (!FastBuildSettings.FastBuildSupportLinkerStampList)
extraPlatformEvents.AddRange(platformBff.GetExtraStampEvents(conf, fastBuildOutputFile).Select(step => { step.Resolve(resolver); return step; }));

extraPlatformEvents.AddRange(platformBff.GetExtraPostBuildEvents(conf, fastBuildOutputFile).Select(step => { step.Resolve(resolver); return step; }));
foreach (var buildEvent in extraPlatformEvents.Concat(conf.ResolvedEventPostBuildExe))
{
string eventKey = ProjectOptionsGenerator.MakeBuildStepName(conf, buildEvent, Vcxproj.BuildStep.PostBuild, project.RootPath, projectPath);
Expand Down Expand Up @@ -830,22 +834,29 @@ List<string> skipFiles
fastBuildCompilerForceUsing = builderForceUsingFiles.ToString();
}

if (isOutputTypeExeOrDll && (conf.PostBuildStampExe != null || conf.PostBuildStampExes.Any()))
if (isOutputTypeExeOrDll)
{
List<string> fastbuildStampExecutableList = new List<string>();
List<string> fastBuildStampArgumentsList = new List<string>();
var extraPlatformEvents = new List<Project.Configuration.BuildStepExecutable>();
if (FastBuildSettings.FastBuildSupportLinkerStampList)
extraPlatformEvents.AddRange(platformBff.GetExtraStampEvents(conf, fastBuildOutputFile).Select(step => { step.Resolve(resolver); return step; }));

foreach (var stampExe in conf.PostBuildStampExes.Prepend(conf.PostBuildStampExe).Where(x => x != null))
if (conf.PostBuildStampExe != null || conf.PostBuildStampExes.Any() || extraPlatformEvents.Any())
{
fastbuildStampExecutableList.Add(CurrentBffPathKeyCombine(Util.PathGetRelative(projectPath, stampExe.ExecutableFile, true)));
fastBuildStampArgumentsList.Add(string.Format("{0} {1} {2}",
stampExe.ExecutableInputFileArgumentOption,
stampExe.ExecutableOutputFileArgumentOption,
stampExe.ExecutableOtherArguments));
}
var fastbuildStampExecutableList = new List<string>();
var fastBuildStampArgumentsList = new List<string>();

fastBuildStampExecutable = UtilityMethods.FBuildFormatList(fastbuildStampExecutableList, 30);
fastBuildStampArguments = UtilityMethods.FBuildFormatList(fastBuildStampArgumentsList, 30);
foreach (var stampExe in extraPlatformEvents.Concat(conf.PostBuildStampExes.Prepend(conf.PostBuildStampExe)).Where(x => x != null))
{
fastbuildStampExecutableList.Add(CurrentBffPathKeyCombine(Util.PathGetRelative(projectPath, stampExe.ExecutableFile, true)));
fastBuildStampArgumentsList.Add(string.Format("{0} {1} {2}",
stampExe.ExecutableInputFileArgumentOption,
stampExe.ExecutableOutputFileArgumentOption,
stampExe.ExecutableOtherArguments));
}

fastBuildStampExecutable = UtilityMethods.FBuildFormatList(fastbuildStampExecutableList, 30);
fastBuildStampArguments = UtilityMethods.FBuildFormatList(fastBuildStampArgumentsList, 30);
}
}

bool linkObjects = false;
Expand Down
8 changes: 8 additions & 0 deletions Sharpmake.Generators/FastBuild/IPlatformBff.cs
Expand Up @@ -70,6 +70,14 @@ public interface IPlatformBff
/// <returns>The list of post build step to execute.</returns>
IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBuildEvents(Project.Configuration configuration, string fastBuildOutputFile);

/// <summary>
/// Get the extra list of stamp steps to execute for this platform.
/// </summary>
/// <param name="configuration">The project configuration</param>
/// <param name="fastBuildOutputFile">The file name of the build output.</param>
/// <returns>The list of stamp step to execute.</returns>
IEnumerable<Project.Configuration.BuildStepExecutable> GetExtraStampEvents(Project.Configuration configuration, string fastBuildOutputFile);

/// <summary>
/// Get the linker output name for this platform.
/// </summary>
Expand Down
Expand Up @@ -157,6 +157,11 @@ public IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBuildEvents(
return Enumerable.Empty<Project.Configuration.BuildStepBase>();
}

public IEnumerable<Project.Configuration.BuildStepExecutable> GetExtraStampEvents(Project.Configuration configuration, string fastBuildOutputFile)
{
return Enumerable.Empty<Project.Configuration.BuildStepExecutable>();
}

public string GetOutputFilename(Project.Configuration.OutputType outputType, string fastBuildOutputFile) => fastBuildOutputFile;

public void AddCompilerSettings(IDictionary<string, CompilerSettings> masterCompilerSettings, Project.Configuration conf)
Expand Down
5 changes: 5 additions & 0 deletions Sharpmake.Platforms/Sharpmake.CommonPlatforms/BasePlatform.cs
Expand Up @@ -123,6 +123,11 @@ public virtual IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBuil
return Enumerable.Empty<Project.Configuration.BuildStepBase>();
}

public virtual IEnumerable<Project.Configuration.BuildStepExecutable> GetExtraStampEvents(Project.Configuration configuration, string fastBuildOutputFile)
{
return Enumerable.Empty<Project.Configuration.BuildStepExecutable>();
}

public virtual string GetOutputFilename(Project.Configuration.OutputType outputType, string fastBuildOutputFile) => fastBuildOutputFile;

public virtual void AddCompilerSettings(IDictionary<string, CompilerSettings> masterCompilerSettings, Project.Configuration conf)
Expand Down
Expand Up @@ -459,7 +459,31 @@ public override void SetupExtraLinkerSettings(IFileGenerator fileGenerator, Proj
}
}

public override IEnumerable<Project.Configuration.BuildStepExecutable> GetExtraStampEvents(Project.Configuration configuration, string fastBuildOutputFile)
{
if (FastBuildSettings.FastBuildSupportLinkerStampList)
{
foreach (var step in GetStripDebugSymbolsSteps(configuration, asStampSteps: true))
yield return step;
}
}

public override IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBuildEvents(Project.Configuration configuration, string fastBuildOutputFile)
{
if (!FastBuildSettings.FastBuildSupportLinkerStampList)
{
foreach (var step in GetStripDebugSymbolsSteps(configuration, asStampSteps: false))
yield return step;
}
}

/// <summary>
/// Get the list of steps (if any), to strip the exe/dll from debug symbols for FastBuild
/// </summary>
/// <param name="configuration">The configuration</param>
/// <param name="asStampSteps">Indicates if those steps are post build or stamp, the latter being more efficient</param>
/// <returns>The list of steps</returns>
private IEnumerable<Project.Configuration.BuildStepExecutable> GetStripDebugSymbolsSteps(Project.Configuration configuration, bool asStampSteps)
{
if (configuration.Output == Project.Configuration.OutputType.Exe || configuration.Output == Project.Configuration.OutputType.Dll)
{
Expand All @@ -482,8 +506,8 @@ public override IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBui
string objCopySentinelFile = @"[conf.IntermediatePath]\" + fileFullname + ".extracted";
yield return new Project.Configuration.BuildStepExecutable(
Path.Combine(binPath, GlobalSettings.UseLlvmObjCopy ? "llvm-objcopy.exe" : "objcopy.exe"),
targetFileFullPath,
objCopySentinelFile,
asStampSteps ? string.Empty : targetFileFullPath,
asStampSteps ? string.Empty : objCopySentinelFile,
string.Join(" ",
"--only-keep-debug",
targetFileFullPath,
Expand All @@ -495,8 +519,8 @@ public override IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBui
string strippedSentinelFile = @"[conf.IntermediatePath]\" + fileFullname + ".stripped";
yield return new Project.Configuration.BuildStepExecutable(
Path.Combine(binPath, GlobalSettings.UseLlvmObjCopy ? "llvm-objcopy.exe" : "strip.exe"),
objCopySentinelFile,
strippedSentinelFile,
asStampSteps ? string.Empty : objCopySentinelFile,
asStampSteps ? string.Empty : strippedSentinelFile,
string.Join(" ",
"--strip-debug",
"--strip-unneeded",
Expand All @@ -508,8 +532,8 @@ public override IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBui
string linkedSentinelFile = @"[conf.IntermediatePath]\" + fileFullname + ".linked";
yield return new Project.Configuration.BuildStepExecutable(
Path.Combine(binPath, GlobalSettings.UseLlvmObjCopy ? "llvm-objcopy.exe" : "objcopy.exe"),
strippedSentinelFile,
linkedSentinelFile,
asStampSteps ? string.Empty : strippedSentinelFile,
asStampSteps ? string.Empty : linkedSentinelFile,
string.Join(" ",
$@"--add-gnu-debuglink=""{targetDebugFileFullPath}""",
targetFileFullPath
Expand Down
5 changes: 5 additions & 0 deletions Sharpmake/FastBuildSettings.cs
Expand Up @@ -101,6 +101,11 @@ public enum CacheTypes
public static bool FastBuildNoUnity = false;
public static bool FastBuildValidateCopyFiles = true;

/// <summary>
/// Controls whether FastBuild supports a list of LinkerStamp steps
/// </summary>
public static bool FastBuildSupportLinkerStampList = false;

/// <summary>
/// Allows retention of build state across BFF changes. Requires v0.97
/// </summary>
Expand Down

0 comments on commit f424cac

Please sign in to comment.