-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[XABT] Create separate assembly preparation tasks. #9637
Conversation
0e05e6a
to
1ce7fb1
Compare
{ | ||
var value = item.GetMetadata (name); | ||
|
||
if (string.IsNullOrWhiteSpace (value)) | ||
return defaultValue; | ||
|
||
return value; | ||
return (T?)Convert.ChangeType (value, typeof (T)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws https://learn.microsoft.com/en-us/dotnet/api/system.convert.changetype?view=net-9.0. We should handle that case? and return the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this only throws if the input cannot be converted to the requested type, like say you passed in "tru"
and T
is bool
.
Passing in an invalid input is a bug that should be fixed, and it feels like we should indeed throw an exception here rather than silently swallow the error and return the default.
Recording what was mentioned on an earlier call: We need to simplify our build system (and related) to reduce maintenance costs, up to and including removing infrequently/rarely used features. While we need to continue to support The appropriate fix for #9455 is not to "make |
One caveat with this today is that assembly stores do not contain android/src/Xamarin.Android.Build.Tasks/Tasks/CollectAssemblyFilesForArchive.cs Lines 118 to 153 in 0475a60
We default assembly stores to android/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Lines 328 to 329 in 0475a60
|
1ce7fb1
to
33cee50
Compare
33cee50
to
ea10b6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.
Files not reviewed (3)
- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets: Language not supported
- src/Xamarin.Android.Build.Tasks/Tasks/CollectAssemblyFilesForArchive.cs: Evaluated as low risk
- src/Xamarin.Android.Build.Tasks/Tasks/CompressAssemblies.cs: Evaluated as low risk
Comments suppressed due to low confidence (1)
src/Xamarin.Android.Build.Tasks/Tasks/CreateAssemblyStore.cs:79
- The metadata value may not be a valid boolean. Consider using bool.TryParse to ensure the metadata value is a valid boolean.
var should_skip = asm.GetMetadataOrDefault ("AndroidSkipAddToPackage", false);
They support PDB files (and also per assembly .config files). If debugging with assembly stores doesn't work, then perhaps the problem is in Mono not getting them (or not asking for them) when debugging. |
var key = CompressedAssemblyInfo.GetKey (ProjectFullPath); | ||
Log.LogDebugMessage ($"Retrieving assembly compression info with key '{key}'"); | ||
|
||
var compressedAssembliesInfo = BuildEngine4.UnregisterTaskObjectAssemblyLocal<IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>> (key, RegisteredTaskObjectLifetime.Build); | ||
|
||
if (compressedAssembliesInfo is null) | ||
throw new InvalidOperationException ($"Assembly compression info not found for key '{key}'. Compression will not be performed."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code was like this, but...
What saves this RegisterTaskObject
value? If we can avoid it, I wouldn't recommend using RegisterTaskObject
here as a project could have:
<TargetFrameworks>net9.0-android;net10.0-android</TargetFrameworks>
The two would overwrite each other with this value for the key
. The CompressedAssemblyInfo
type will be incompatible between the two assemblies under .NET framework because their versions do not match.
Can we calculate the value within this task and not use RegisterTaskObject
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generated here:
android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateCompressedAssembliesNativeSourceFiles.cs
Line 88 in fec3b79
string key = CompressedAssemblyInfo.GetKey (ProjectFullPath); |
The problem is that we have to generate the LLVM IR assembly sources way, way before we package the assemblies and the info gathered while generating the native assembly sources is crucial to the correct construction of the assembly store. We allocate buffers of specific size for each of the assemblies, so that decompressed data for each assembly gets a buffer of the correct size. This saves memory. The way it works is that each assembly has an index, allocated while generating the native assembler sources, and that index is used at run time to find the correct buffer.
Maybe the assemblies could be compressed just before generation step for the native assembler sources, but I don't know if it isn't too early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I could tell, the only thing that gets used from this is the "DescriptorIndex"
:
AssemblyData compressedAssembly = new AssemblyData (assembly.ItemSpec, info.DescriptorIndex); |
It feels like this could be a piece of metadata added to the @(Item)
instead, but I certainly haven't decoded the full picture.
Any change here should likely be done in its own PR.
It looks like here's the context for why assembly stores are disabled by default when debugging: #6660. |
#6660 seems like it was specific to In the original issue, a breakpoint didn't even work. So, we should have a test to catch that if it was broken now. |
Break down the
CollectAssemblyFilesForArchive
task further into individual tasks.These tasks each handle a separate concern about preparing the assemblies for the apk:
CompressAssemblies
- Compresses assemblies using LZ4 compression (independent of ZIP compression).CreateAssemblyStore
- Bundles assemblies into a single.blob
file.WrapAssembliesAsSharedLibraries
- Wraps the assemblies as shared libraries so they can go in thelib
directory of the APK.This should allow them to be moved to separate incremental targets in the future. For example, we do not need to compress all assemblies on every build if they haven't changed since the previous build.