Skip to content

[Microsoft.Android.Build.Tasks] Make AssemblyStore zstd compression level configurable#11968

Open
simonrozsival wants to merge 3 commits into
mainfrom
dev/simonrozsival/configurable-assembly-store-compression-level
Open

[Microsoft.Android.Build.Tasks] Make AssemblyStore zstd compression level configurable#11968
simonrozsival wants to merge 3 commits into
mainfrom
dev/simonrozsival/configurable-assembly-store-compression-level

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

What

Adds a new internal MSBuild property, $(_AndroidAssemblyStoreCompressionLevel), that controls the Zstandard compression level used when building the AssemblyStore.

  • Default is 3 — zstd's current default — so this change is purely additive and does not alter existing build output.
  • Valid range is 122; an out-of-range value fails the build with XA5304.
  • Higher levels produce a smaller store at the cost of build time. zstd decompression speed is independent of the compression level, so raising it has no runtime cost — only a bigger build-time bill.

How

  • AssemblyCompressor.TryCompress / Compress take a compressionLevel argument and pass it to ZstandardEncoder.TryCompress.
  • CompressAssemblies gains a [Required] CompressionLevel property and validates the 122 range up front (XA5304).
  • Xamarin.Android.Common.targets:
    • defines the property default,
    • passes it to the CompressAssemblies task,
    • and includes it in the build-properties cache so changing the level re-triggers the incremental _CompressAssemblies target.

Notes

Builds on the Microsoft.Android.Build.Tasks / CompressAssemblies infrastructure introduced in #11730. This carves the configurable-level knob out of a larger experimental branch so it can land independently.

…el configurable

Add a new `$(_AndroidAssemblyStoreCompressionLevel)` MSBuild property
(default 3, matching zstd's current default so behavior is unchanged)
that controls the Zstandard compression level used when building the
AssemblyStore. Higher levels produce a smaller store at the cost of
build time; zstd decompression speed is independent of the level, so
raising it has no runtime cost.

- `AssemblyCompressor.TryCompress`/`Compress` take a `compressionLevel`
  argument and pass it to `ZstandardEncoder.TryCompress`.
- `CompressAssemblies` gains a `[Required] CompressionLevel` property and
  validates the range (1-22) up front, reporting `XA5304` when invalid.
- `Xamarin.Android.Common.targets` defines the property default, passes
  it to the task, and includes it in the build-properties cache so
  changing the level re-triggers the incremental `_CompressAssemblies`
  target.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 08:03
@simonrozsival simonrozsival changed the title [Xamarin.Android.Build.Tasks] Make AssemblyStore zstd compression level configurable [Microsoft.Android.Build.Tasks] Make AssemblyStore zstd compression level configurable Jul 3, 2026

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.

Pull request overview

This PR adds a new internal MSBuild property ($(_AndroidAssemblyStoreCompressionLevel)) to control the Zstandard compression level used when generating the AssemblyStore, plumbing it through the CompressAssemblies task and ensuring incremental builds re-run when the level changes.

Changes:

  • Introduces $(_AndroidAssemblyStoreCompressionLevel) with a default of 3, and wires it into the _CompressAssemblies target.
  • Adds CompressionLevel to the CompressAssemblies MSBuild task and validates the supported level range (1–22), emitting XA5304 on out-of-range values.
  • Updates assembly compression helpers to pass the chosen level into ZstandardEncoder.TryCompress.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Defines the new internal property default, includes it in the build-properties cache, and passes it to CompressAssemblies for incremental correctness.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds XA5304 error message text for invalid compression-level values.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Regenerates strongly-typed resource accessor for XA5304.
src/Microsoft.Android.Build.Tasks/Utilities/AssemblyCompressor.cs Threads compression level into the underlying zstd encoder call.
src/Microsoft.Android.Build.Tasks/Tasks/CompressAssemblies.cs Adds the new task parameter, validates range, and forwards the level to the compressor.

Copilot's findings

Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
  • Files reviewed: 4/5 changed files
  • Comments generated: 2

Comment thread src/Microsoft.Android.Build.Tasks/Tasks/CompressAssemblies.cs Outdated
Comment on lines +43 to +45
if (CompressionLevel < MinCompressionLevel || CompressionLevel > MaxCompressionLevel) {
Log.LogCodedError ("XA5304", Properties.Resources.XA5304, CompressionLevel, MinCompressionLevel, MaxCompressionLevel);
return false;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot add the documentation for this new error code

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.

Done. Added Documentation/docs-mobile/messages/xa5304.md with the error description and solution, and added an entry for XA5304 to Documentation/docs-mobile/messages/index.md (commit $(latest)).

@simonrozsival simonrozsival added the copilot `copilot-cli` or other AIs were used to author this label Jul 3, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants