Skip to content

Commit 2df7434

Browse files
[APM] Exclude windows only definitions from non windows dlls (#6270)
## Summary of changes Remove windows only definitions from non windows dlls ## Reason for change Defs take up space. Removing non needed ones will help keep package size as low as possible ## Implementation details Surround windows only defs in #if _WIN32 clauses ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. -->
1 parent 7f5fb56 commit 2df7434

File tree

6 files changed

+1263
-1189
lines changed

6 files changed

+1263
-1189
lines changed

tracer/build/_build/CodeGenerators/CallSitesGenerator.cs

+21-2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ static string GetArgument(Mono.Cecil.CustomAttributeArgument customAttributeArgu
251251
internal static void GenerateFile(Dictionary<string, AspectClass> aspectClasses, AbsolutePath outputPath)
252252
{
253253
var sb = new StringBuilder();
254+
bool inWin32Section = false;
254255
sb.AppendLine("""
255256
// <copyright company="Datadog">
256257
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
@@ -273,7 +274,25 @@ namespace trace
273274

274275
foreach (var method in aspectClass.Value.Aspects.OrderBy(static k => k.Key.ToString(), StringComparer.OrdinalIgnoreCase))
275276
{
276-
sb.AppendLine(Format(" " + method.Key + method.Value.Subfix()));
277+
bool win32Only = method.Value.Tfms.IsNetFxOnly();
278+
if (win32Only && !inWin32Section)
279+
{
280+
inWin32Section = true;
281+
sb.AppendLine("#if _WIN32");
282+
}
283+
else if (!win32Only && inWin32Section)
284+
{
285+
inWin32Section = false;
286+
sb.AppendLine("#endif");
287+
}
288+
289+
sb.AppendLine(Format(" " + method.Key + method.Value.Suffix()));
290+
}
291+
292+
if (inWin32Section)
293+
{
294+
inWin32Section = false;
295+
sb.AppendLine("#endif");
277296
}
278297
}
279298

@@ -319,7 +338,7 @@ public Aspect() { }
319338

320339
public TargetFrameworks Tfms = TargetFrameworks.None;
321340

322-
public string Subfix()
341+
public string Suffix()
323342
{
324343
return $" {((long)Tfms).ToString()}";
325344
}

tracer/build/_build/CodeGenerators/CallTargetsGenerator.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ namespace trace
546546

547547

548548
//Write all CallTargets
549+
bool inWin32Section = false;
549550
sb.AppendLine();
550551
sb.AppendLine("std::vector<CallTargetDefinition3> g_callTargets=");
551552
sb.AppendLine("{");
@@ -556,9 +557,27 @@ namespace trace
556557
.ThenBy(static x => x.Key.TargetTypeName)
557558
.ThenBy(static x => x.Key.TargetMethodName))
558559
{
560+
bool win32Only = definition.Value.IsNetFxOnly();
561+
if (win32Only && !inWin32Section)
562+
{
563+
inWin32Section = true;
564+
sb.AppendLine("#if _WIN32");
565+
}
566+
else if (!win32Only && inWin32Section)
567+
{
568+
inWin32Section = false;
569+
sb.AppendLine("#endif");
570+
}
571+
559572
sb.AppendLine(GetCallTarget(definition.Key, signatures[GetSignature(definition.Key)], definition.Value, x++));
560573
}
561574

575+
if (inWin32Section)
576+
{
577+
inWin32Section = false;
578+
sb.AppendLine("#endif");
579+
}
580+
562581
sb.AppendLine("""
563582
};
564583
}
@@ -639,7 +658,6 @@ internal static void GenerateJsonFile(Dictionary<CallTargetDefinitionSource, Tar
639658
Logger.Information("CallTarget definitions File saved: {File}", fileName);
640659
}
641660

642-
643661
internal static TargetFrameworks GetCategory(TargetFramework tfm)
644662
{
645663
return (TargetFrameworks)Enum.Parse<TargetFrameworks>(tfm.ToString().ToUpper().Replace('.', '_'));

tracer/build/_build/CodeGenerators/TargetFrameworks.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ internal enum TargetFrameworks : uint
1616
// NOTE : When modifying this file make sure to update the TargetFrameworks enum in the ClrProfiler folder inside the Datadog.Trace project
1717

1818
NET461 = 1,
19-
NET462 = 2,
20-
NETSTANDARD2_0 = 4,
21-
NETCOREAPP2_1 = 8,
22-
NETCOREAPP3_0 = 16,
23-
NETCOREAPP3_1 = 32,
24-
NET5_0 = 64,
25-
NET6_0 = 128,
26-
NET7_0 = 256,
27-
NET8_0 = 512,
28-
NET0_0 = 1024,
19+
NETSTANDARD2_0 = 2,
20+
NETCOREAPP3_1 = 4,
21+
NET6_0 = 8,
22+
}
23+
24+
25+
internal static class TargetFrameworksExtensions
26+
{
27+
public static bool IsNetFxOnly(this TargetFrameworks tfm)
28+
{
29+
return tfm == TargetFrameworks.NET461;
30+
}
2931
}

tracer/src/Datadog.Trace/ClrProfiler/TargetFrameworks.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ internal enum TargetFrameworks : uint
1414
// NOTE : When modifying this file make sure to update the TargetFrameworks enum in the CodeGenerator folder inside the _build project
1515

1616
NET461 = 1,
17-
NET462 = 2,
18-
NETSTANDARD2_0 = 4,
19-
NETCOREAPP2_1 = 8,
20-
NETCOREAPP3_0 = 16,
21-
NETCOREAPP3_1 = 32,
22-
NET5_0 = 64,
23-
NET6_0 = 128,
24-
NET7_0 = 256,
25-
NET8_0 = 512,
26-
NET9_0 = 1024,
17+
NETSTANDARD2_0 = 2,
18+
NETCOREAPP3_1 = 4,
19+
NET6_0 = 8,
2720
}

0 commit comments

Comments
 (0)