From 433fa325e7fec984378c6cc0c89d47811849c91c Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 16 Nov 2021 13:17:49 -0800 Subject: [PATCH 1/5] Remove race condition from DllImportGenerator build We had a race condition in the DllImportGenerator build due to the workaround implemented for Roslyn 4.0 RC1's new assembly loading scheme. RC2 has a fix that should work to enable us to remove the workaround. --- eng/generators.targets | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/eng/generators.targets b/eng/generators.targets index aec6e667a6efd..8116f8eca819e 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -41,6 +41,7 @@ and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator')) and '$(IncludeDllImportGeneratorSources)' == 'true'"> + @@ -67,17 +68,6 @@ true $(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE - - - - - - - - - $(DefineConstants);DLLIMPORTGENERATOR_ENABLED From c3356bcd396a1ee360509d6c20df72c0fc143cb4 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 16 Nov 2021 15:25:50 -0800 Subject: [PATCH 2/5] Provide alternative solution that should still fix the race condition (GetTargetPath doesn't touch any files, so it shouldn't race). We'll fix this with the real solution once we update to the RTM sdk --- eng/generators.targets | 30 ++++++++++++++----- .../DllImportGenerator.csproj | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/eng/generators.targets b/eng/generators.targets index 8116f8eca819e..76645f5f54b6a 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -22,9 +22,7 @@ and ( ('@(Reference)' != '' and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices')) - and (@(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.CompilerServices.Unsafe')) - or ('@(ProjectReference)' != '' - and @(ProjectReference->AnyHaveMetadataValue('Identity', $([MSBuild]::NormalizePath('$(LibrariesProjectRoot)', 'System.Runtime.CompilerServices.Unsafe', 'src', 'System.Runtime.CompilerServices.Unsafe.ilproj')))))) + and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.CompilerServices.Unsafe')) and @(Reference->AnyHaveMetadataValue('Identity', 'System.Memory'))) or ('@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))))" /> @@ -40,8 +38,7 @@ - - + @@ -56,8 +53,7 @@ + BeforeTargets="BeforeBuild"> true @@ -68,6 +64,26 @@ true $(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE + + + + + + + + $([System.IO.Path]::GetDirectoryName('$(DllImportGeneratorTargetPath)')) + + + + + $(DefineConstants);DLLIMPORTGENERATOR_ENABLED diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj index 0648253ef2c94..843c88967ad58 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj @@ -41,7 +41,7 @@ - + From 8f7918f1277fd438e956ffab8580c7726217f6e2 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 17 Nov 2021 09:12:05 -0800 Subject: [PATCH 3/5] Use regular project references and lay out the generator assemblies in a new per-project folder side-by-side to avoid race conditions. --- eng/generators.targets | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/eng/generators.targets b/eng/generators.targets index 94ea6771de5b9..cfc4fe8143ba8 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -33,7 +33,14 @@ - + + @@ -60,7 +67,8 @@ + DependsOnTargets="ResolveProjectReferences" + BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun"> true @@ -72,25 +80,12 @@ $(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE - - - - - - - $([System.IO.Path]::GetDirectoryName('$(DllImportGeneratorTargetPath)')) - - - - - + + + + $(DefineConstants);DLLIMPORTGENERATOR_ENABLED From b901a2b8e42a294b22ab944c550477ce9f0b5446 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 17 Nov 2021 11:11:44 -0800 Subject: [PATCH 4/5] Just use the repos handling for enabling DllImportGenerator to hook it up. --- .../DllImportGenerator.Tests/DllImportGenerator.Tests.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj index 351241b66278d..94877b6888cce 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj @@ -18,8 +18,6 @@ - - From 8bae81e24641a98fccc07455c2988605b1f5c7ae Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 17 Nov 2021 14:33:59 -0800 Subject: [PATCH 5/5] IncludeDllImportGeneratorSources should not control referencing the generator itself. --- eng/generators.targets | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eng/generators.targets b/eng/generators.targets index cfc4fe8143ba8..5283236729566 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -31,8 +31,7 @@ + and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))"> + +