[msbuild/bgen] Run bgen in the MSBuild task process. Fixes #26584 - #26590
rolfbjarne wants to merge 7 commits into
Conversation
Compile the binding generator into Xamarin.MacDev.Tasks and invoke its entry point directly, avoiding dependency on the bgen runtimeconfig framework version. Add temporary netstandard2.0 compatibility paths and verify the task no longer uses the configured bgen executable for local execution. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Allow the internal _BGenUseExternalProcess MSBuild property to select the previous out-of-process bgen execution path while keeping in-process execution as the default. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Propagate the BGen task cancellation token into the binding generator and observe it between initialization and generated types. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Pass DOTNET_CUSTOM_HOME to compiler child processes without mutating the MSBuild process environment during in-process generation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Return a structured bgen error instead of terminating the hosting MSBuild process when an Export selector is invalid. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Forward in-process task cancellation to bgen compiler invocations and surface cancellation after terminating the child process. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Include bgen's command-line parser dependency in the netstandard2.0 task assembly so packaged tasks can execute bgen in-process. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The in-process console redirection in BGen can interfere with other concurrently running tasks that also redirect Console.Out/Error, risking misrouted or lost build output.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR integrates bgen into Xamarin.MacDev.Tasks so local builds can run bgen in-process (avoiding a separate dotnet bgen.dll process by default), while keeping an opt-in external-process mode via _BGenUseExternalProcess and preserving remote execution behavior.
Changes:
- Compile bgen sources into
Xamarin.MacDev.Tasksand add an in-process execution path (with cancellation/custom HOME handling). - Keep an external-process fallback (
UseExternalProcess) and add tests covering both modes. - Improve netstandard2.0 compatibility and convert a hard-exit invalid selector failure into a
BindingException(BI1129) with docs/resources updates.
File summaries
| File | Description |
|---|---|
| tools/common/Driver.execution.cs | Adds cancellation-aware RunCommand overloads for process execution. |
| tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/BGenTaskTest.cs | Adds unit tests for in-process vs external-process execution modes. |
| src/Resources.resx | Adds BI1129 resource string. |
| src/Resources.Designer.cs | Adds BI1129 strongly-typed accessor. |
| src/ObjCRuntime/Stret.cs | Adds netstandard-compatible null checking helper. |
| src/build/dotnet/generator-frameworks.g.cs | Renames generated framework container type to BGenFrameworks. |
| src/bgen/TypeManager.cs | Updates framework type reference to BGenFrameworks. |
| src/bgen/NullabilityInfoContext.cs | Guards NullabilityInfo helpers behind #if NET for netstandard builds. |
| src/bgen/NetStandardCompatibility.cs | Adds polyfills for newer attributes/types when not building with NET. |
| src/bgen/Models/MarshalTypeList.cs | Updates framework type reference to BGenFrameworks. |
| src/bgen/Generator.cs | Throws BI1129 instead of printing+exiting; adds cancellation checks in loops. |
| src/bgen/Frameworks.cs | Renames Frameworks to BGenFrameworks. |
| src/bgen/Extensions/StringExtensions.cs | Adds warning suppression for netstandard compilation. |
| src/bgen/Enums.cs | Uses reflection overloads compatible with non-NET builds. |
| src/bgen/DocumentationManager.cs | Adds netstandard-compatible string slicing and SZ-array detection. |
| src/bgen/Caches/TypeCache.cs | Updates framework type reference to BGenFrameworks. |
| src/bgen/Caches/NamespaceCache.cs | Updates framework type reference to BGenFrameworks. |
| src/bgen/BindingTouch.cs | Adds Run(...) entrypoint, cancellation propagation, custom HOME support for compiler runs. |
| src/bgen/AttributeManager.cs | Adds netstandard-compatible substring parsing. |
| scripts/generate-frameworks/README.md | Updates example output to BGenFrameworks. |
| scripts/generate-frameworks/generate-frameworks.cs | Emits partial class BGenFrameworks in generated output. |
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Wires _BGenUseExternalProcess into the BGen task. |
| msbuild/Xamarin.MacDev.Tasks/Xamarin.MacDev.Tasks.csproj | Compiles bgen sources into tasks assembly; adds Mono.Options and BI resources generation. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs | Fully qualifies ErrorHelper.WarningLevel to avoid ambiguity. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs | Implements in-process bgen execution path and external-process switch. |
| msbuild/ILMerge.targets | Adds Mono.Options to merged assemblies list. |
| docs/website/generator-errors.md | Documents BI1129. |
Review details
Files not reviewed (1)
- src/Resources.Designer.cs: Generated file
- Files reviewed: 26/27 changed files
- Comments generated: 2
- Review effort level: Lite
| counter--; | ||
| if (counter == 0) { | ||
| if (originalStdout is null || originalStderr is null) | ||
| throw new InvalidOperationException ("The original console writers were not captured."); | ||
| Console.SetOut (originalStdout); | ||
| Console.SetError (originalStderr); | ||
| originalStdout = null; | ||
| originalStderr = null; | ||
| } |
| if (export.Selector.IndexOfAny (invalid_selector_chars) != -1) | ||
| throw new BindingException (1129, true, export.Selector); |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #888a016] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 4 tests failed, 260 tests passed. Failures❌ monotouch tests (MacCatalyst)1 tests failed, 24 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)2 tests failed, 18 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests1 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Compile bgen into Xamarin.MacDev.Tasks and invoke it directly for local builds, avoiding a separate bgen process by default.
Keep the external-process implementation available through the opt-in
_BGenUseExternalProcessproperty, while preserving remote execution.Add netstandard2.0 compatibility, cancellation support, isolated compiler environment handling, and task coverage for both execution modes.
Fixes #26584
🤖 Pull request created by Copilot