Skip to content

Commit b90afbf

Browse files
committed
Merge branch 'saudi/support-stripping-macos' into 'main'
Add support for stripping debug info when dSYM is generated See merge request Sharpmake/sharpmake!591
2 parents db2d8a0 + 0a2ccda commit b90afbf

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs

+41-7
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,25 @@ public void SetupExtraLinkerSettings(IFileGenerator fileGenerator, Project.Confi
191191
fileGenerator.Write(_linkerOptionsTemplate);
192192
}
193193

194+
public IEnumerable<Project.Configuration.BuildStepExecutable> GetExtraStampEvents(Project.Configuration configuration, string fastBuildOutputFile)
195+
{
196+
if (FastBuildSettings.FastBuildSupportLinkerStampList)
197+
{
198+
foreach (var step in GetStripDebugSymbolsSteps(configuration, fastBuildOutputFile, asStampSteps: true))
199+
yield return step;
200+
}
201+
}
202+
194203
public IEnumerable<Project.Configuration.BuildStepBase> GetExtraPostBuildEvents(Project.Configuration configuration, string fastBuildOutputFile)
204+
{
205+
if (!FastBuildSettings.FastBuildSupportLinkerStampList)
206+
{
207+
foreach (var step in GetStripDebugSymbolsSteps(configuration, fastBuildOutputFile, asStampSteps: false))
208+
yield return step;
209+
}
210+
}
211+
212+
private IEnumerable<Project.Configuration.BuildStepExecutable> GetStripDebugSymbolsSteps(Project.Configuration configuration, string fastBuildOutputFile, bool asStampSteps)
195213
{
196214
if (Util.GetExecutingPlatform() == Platform.mac)
197215
{
@@ -207,22 +225,38 @@ public void SetupExtraLinkerSettings(IFileGenerator fileGenerator, Project.Confi
207225
if (debugFormat == Options.XCode.Compiler.DebugInformationFormat.DwarfWithDSym)
208226
{
209227
string outputPath = Path.Combine(configuration.TargetPath, configuration.TargetFileFullNameWithExtension + ".dSYM");
228+
string dsymutilSentinelFile = Path.Combine(configuration.IntermediatePath, configuration.TargetFileName + ".dsymdone");
210229
yield return new Project.Configuration.BuildStepExecutable(
211230
"/usr/bin/dsymutil",
212-
fastBuildOutputFile,
213-
Path.Combine(configuration.IntermediatePath, configuration.TargetFileName + ".dsymdone"),
231+
asStampSteps ? string.Empty : fastBuildOutputFile,
232+
asStampSteps ? string.Empty : dsymutilSentinelFile,
214233
$"{fastBuildOutputFile} -o {outputPath}",
215234
useStdOutAsOutput: true);
235+
236+
var stripDebugSymbols = Options.GetObject<Options.XCode.Linker.StripLinkedProduct>(configuration);
237+
if (stripDebugSymbols == Options.XCode.Linker.StripLinkedProduct.Enable)
238+
{
239+
string strippedSentinelFile = Path.Combine(configuration.IntermediatePath, configuration.TargetFileName + ".stripped");
240+
yield return new Project.Configuration.BuildStepExecutable(
241+
"/usr/bin/strip",
242+
asStampSteps ? string.Empty : dsymutilSentinelFile,
243+
asStampSteps ? string.Empty : strippedSentinelFile,
244+
// From MacOS strip manual page:
245+
// -r : Save all symbols referenced dynamically.
246+
// -S : Remove the debuging symbol table entries (those created by the -g optin to cc and other compilers).
247+
// -T : The intent of this flag is to remove Swift symbols from the Mach-O symbol table,
248+
// It removes the symbols whose names begin with '_$S' or '_$s' only when it finds an __objc_imageinfo section with and it has non-zero swift version.
249+
// In the future the implementation of this flag may change to match the intent.
250+
// -x : Remove all local symbols (saving only global symbols)
251+
$"-rSTx {fastBuildOutputFile}",
252+
useStdOutAsOutput: true
253+
);
254+
}
216255
}
217256
}
218257
}
219258
}
220259

221-
public IEnumerable<Project.Configuration.BuildStepExecutable> GetExtraStampEvents(Project.Configuration configuration, string fastBuildOutputFile)
222-
{
223-
return Enumerable.Empty<Project.Configuration.BuildStepExecutable>();
224-
}
225-
226260
public string GetOutputFilename(Project.Configuration.OutputType outputType, string fastBuildOutputFile) => fastBuildOutputFile;
227261

228262
public enum CompilerFlavor

0 commit comments

Comments
 (0)