Skip to content

[bgen] Remove source compilation support - #26614

Open
rolfbjarne wants to merge 4 commits into
mainfrom
dev/rolf/remove-bgen-compilation
Open

rolfbjarne wants to merge 4 commits into
mainfrom
dev/rolf/remove-bgen-compilation

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member
  • require bgen consumers to pass a compiled API definition assembly
  • remove bgen's API-definition and generated-binding compiler paths and obsolete compiler options
  • keep source generation, generated-file-list output, diagnostics, and validation
  • update the MSBuild task, product build response files, and bgen test harness for external compilation

🤖 Pull request created by Copilot

Require compiled API definition assemblies and leave generated source compilation to consumers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved bgen output validation and CLI contract issues, plus test-harness failures, block approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR updates bgen to consume precompiled API-definition assemblies and generate binding sources only.

Changes:

  • Removes internal compilation paths and obsolete options.
  • Updates MSBuild, Makefile, tests, diagnostics, and documentation.
  • Adds external compilation support to the test harness.
File summaries
File Summary
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/BGenTaskTest.cs Updates task argument tests.
tests/bgen/ErrorTests.cs Tests removed options and source support.
tests/bgen/BGenTool.cs Adds external compilation steps.
src/Resources.resx Removes obsolete diagnostics.
src/Resources.Designer.cs Removes generated obsolete resources.
src/Makefile Updates generator flags.
src/bgen/Models/BindingTouchConfig.cs Removes obsolete compiler configuration.
src/bgen/DocumentationManager.cs Updates compilation documentation.
src/bgen/BindingTouch.cs Removes compilation paths and uses compiled assemblies.
msbuild/Xamarin.Shared/Xamarin.Shared.targets Supplies compiled API assemblies.
msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs Updates task arguments and validation.
docs/website/generator-errors.md Removes obsolete error documentation.
Review details

Files not reviewed (1)

  • src/Resources.Designer.cs: Generated file

Suppressed comments (4)

msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs:210

  • error — Once bgen only generates source, GeneratedSourcesFileList is required too. With it empty this command omits /sourceonly; the local task returns success without exposing generated files (and the remote path later tries to read an empty filename). Validate it here and mark the task parameter required.
			if (CompiledApiDefinitionAssembly is null || string.IsNullOrEmpty (CompiledApiDefinitionAssembly.ItemSpec)) {
				Log.LogError ("A compiled API definition assembly is required.");
				return false;

src/bgen/BindingTouch.cs:138

  • ⚠️ warning — The source-only workflow still treats --sourceonly as optional. If a caller follows the help and supplies only the required compiled assembly, TryGenerate writes files under the temporary directory and deletes it in finally, so bgen exits successfully with no usable output. Require a persistent --outdir/--sourceonly combination or update the CLI contract and help.
				{ "sourceonly=", "Writes the generated source file list", v => config.GeneratedFileList = v },

tests/bgen/BGenTool.cs:197

  • bug — The harness now compiles the API source before running bgen. BI0086 intentionally uses Profile.None with no target framework (ErrorTests.cs:44-47), so this Compile call has no target-framework-derived BCL/base/attribute references but still adds the nfloat global using; the compiler can fail before bgen emits BI0086 and the existing regression test reports the wrong failure. Validate the bgen command before compiling or provide a valid reference set for this case.
				var compileApiDefinitionsResult = Compile (CompiledApiDefinitionAssembly, ApiDefinitions.Concat (Sources), true);

tests/bgen/BGenTool.cs:233

  • Bug — This new post-generation compile path unconditionally calls AssemblyPath, but that property still derives its default from ApiDefinitions[0]. A caller using the intended precompiled-API workflow can provide CompiledApiDefinitionAssembly with no API source files, causing an ArgumentOutOfRangeException after bgen succeeds; derive the final output path from Out or a neutral default and add a source-less external-assembly test.
			var compileResult = Compile (AssemblyPath, File.ReadAllLines (GetGeneratedSourcesFileList ()).Concat (Sources).Concat (ExtraSources), false);
  • Files reviewed: 11/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/bgen/BindingTouch.cs
Require persistent generated source outputs and keep test harness diagnostics and precompiled assembly flows working.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
rolfbjarne added a commit that referenced this pull request Sep 15, 2026
Preserve generation-only output validation while routing its diagnostics through IToolLog.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne requested a lite review from Copilot September 15, 2026 19:51
@rolfbjarne rolfbjarne added the do-not-merge Do not merge this pull request label Sep 15, 2026
@rolfbjarne

Copy link
Copy Markdown
Member Author

This will be .NET 12, so waiting until .NET 11 RC 2 has been branched.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical warning-suppression and output-path validation issues remain.

Get a fresh assessment by requesting another Copilot review.

Review details

Files not reviewed (1)

  • src/Resources.Designer.cs: Generated file

Suppressed comments (3)

msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs:177

  • ⚠️ test_coverage — The new hard requirement for CompiledApiDefinitionAssembly has no direct Execute() regression test: GeneratedSourceOutputsAreRequired sets this property and only covers the second validation branch. Add a test that supplies valid generated-source outputs but leaves the compiled assembly unset, and assert the task fails/logs the required-assembly error, so source-mode execution cannot silently return.
			if (CompiledApiDefinitionAssembly is null || string.IsNullOrEmpty (CompiledApiDefinitionAssembly.ItemSpec)) {
				Log.LogError ("A compiled API definition assembly is required.");
				return false;

src/bgen/BindingTouch.cs:314

  • bug — This guard distinguishes only null from a usable output directory. --outdir= is parsed as an empty string, so it passes here; TryGenerate then uses that empty value as Generator.BaseDir and writes generated files relative to the process working directory instead of rejecting the invalid output path. Treat empty values as absent (or reject them while parsing).
		if (config.BindingFilesOutputDirectory is null && config.DeleteTemporaryFiles) {

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/BGenTaskTest.cs:18

  • 💡 test_coverageExecute() now requires GeneratedSourcesDir alongside the list, but this test leaves the directory unset and therefore never verifies the new /tmpdir: switch. Populate the directory in this setup and assert it is emitted so the task's source-output contract is covered.
			task.GeneratedSourcesFileList = Path.Combine (Cache.CreateTemporaryDirectory (), "generated-sources.txt");
  • Files reviewed: 12/13 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread msbuild/Xamarin.Shared/Xamarin.Shared.targets
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Keep compiled API definitions in a separate directory so that generated binding assemblies do not overwrite the input assembly. Preserve the API assembly basename used for generated helper namespaces, initialize the response-file test profile, and update XML documentation ordering for the sorted generated source list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bd2e6ad9-8e15-400a-ad9b-4c2150fee229
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 5b88546fc54b125756ea98cc4117d1e1d3ce7f22 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #5b88546] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 2 tests failed, 262 tests passed.

Failures

❌ generator tests

1 tests failed, 4 tests passed.

Failed tests

  • BGen tests: Failed (Execution failed with exit code 1)
    • GeneratorTests.BGenTests.PrecompiledApiAssemblyWithoutSources: BGen failed with exit code 1: build
      Microsoft (R) Visual C# Compiler version 5.12.0-1.26461.115 (fb92951eceabe91c5015b35e49acdbc...

Html Report (VSDrops) Download

❌ windows tests

1 tests failed, 2 tests passed.

Failed tests

  • BGen tests/GeneratorTests.BGenTests.PreviewAPIs(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir128'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.ProtocolTests.Members(MacCatalyst): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir12'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.XmlDocs(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir163'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.SimulatorAvailabilityAttributes_NotEmittedForMacPlatforms(MacCatalyst): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir149'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.PreviewAPIs(MacCatalyst): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir129'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.XmlDocs(tvOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir166'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.BackingFieldType(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir20'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.StackOverflow20696157: Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir153'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.SimulatorAvailabilityAttributes(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir145'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.NativeEnum(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir108'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.SimulatorAvailabilityAttributes_NotEmittedForMacPlatforms(macOSMobile): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir148'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.SimulatorAvailabilityAttributes(tvOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir146'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.XmlDocs(macOSMobile): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir165'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.Bug29493: Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir39'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.PreviewAPIs(macOSMobile): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir130'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.XmlDocs(MacCatalyst): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir164'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.ProtocolTests.Members(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir13'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.PrecompiledApiAssemblyWithoutSources: Failed: BGen failed with exit code 1: build

  • BGen tests/GeneratorTests.BGenTests.BackingFieldType(MacCatalyst): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir21'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.FieldEnumTests(iOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir71'. The filename or extension is too long.)

  • BGen tests/GeneratorTests.BGenTests.PreviewAPIs(tvOS): Failed: System.AggregateException : One or more errors occurred. (An error occurred trying to start process 'D:/AzDO/_work/17/s/macios/tests/dotnet/Windows/bin/dotnet/dotnet.exe' with working directory 'D:\AzDO_work\17\s\macios\tests\bgen\bin\Debug\net11.0\tmp-test-dir\Xamarin.Tests.BGenTool.EnsureTempDir131'. The filename or extension is too long.)

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
⚠️ Tests on macOS Golden Gate (27): Tests skipped, incorrect beta version. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 5b88546fc54b125756ea98cc4117d1e1d3ce7f22 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot do-not-merge Do not merge this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants