Skip to content

Commit

Permalink
Assembly store embedding works
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Oct 10, 2024
1 parent 7436fbf commit 2730842
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<CreateEmbeddedAssemblyStore
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
AppSharedLibrariesDir="$(_AndroidApplicationSharedLibraryPath)"
AssemblySourcesDir="$(IntermediateOutputPath)android"
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)\test\"
Debug="$(AndroidIncludeDebugSymbols)"
EnableCompression="$(AndroidEnableAssemblyCompression)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;

using Microsoft.Android.Build.Tasks;
using Microsoft.Build.Framework;
Expand All @@ -18,6 +19,9 @@ public class CreateEmbeddedAssemblyStore : AndroidTask
[Required]
public string AppSharedLibrariesDir { get; set; }

[Required]
public string AssemblySourcesDir { get; set; }

[Required]
public string CompressedAssembliesDir { get; set; }

Expand Down Expand Up @@ -67,6 +71,39 @@ public override bool RunTask ()
// Add framework assemblies
AssemblyPackagingHelper.AddAssembliesFromCollection (Log, SupportedAbis, ResolvedFrameworkAssemblies, DoAddAssembliesFromArchCollection);

var objectFiles = new List<ITaskItem> ();
var sourceFiles = new List<ITaskItem> ();
Dictionary<AndroidTargetArch, string> assemblyStorePaths = storeBuilder.Generate (Path.Combine (AppSharedLibrariesDir, "embedded"));
foreach (var kvp in assemblyStorePaths) {
string abi = MonoAndroidHelper.ArchToAbi (kvp.Key);
string inputFile = kvp.Value;

List<ITaskItem> items = ELFEmbeddingHelper.EmbedBinary (
Log,
abi,
AndroidBinUtilsDirectory,
inputFile,
ELFEmbeddingHelper.KnownEmbedItems.AssemblyStore,
AssemblySourcesDir
);

if (items.Count == 0) {
continue;
}

objectFiles.AddRange (items);
foreach (ITaskItem objectItem in items) {
var sourceItem = new TaskItem (
Path.ChangeExtension (objectItem.ItemSpec, ".s"),
objectItem.CloneCustomMetadata ()
);
sourceFiles.Add (sourceItem);
}
}

NativeAssemblySources = sourceFiles.ToArray ();
EmbeddedObjectFiles = objectFiles.ToArray ();

return !Log.HasLoggedErrors;

void DoAddAssembliesFromArchCollection (TaskLoggingHelper log, AndroidTargetArch arch, ITaskItem assembly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ string Generate (string baseOutputDirectory, AndroidTargetArch arch, List<Assemb

string androidAbi = MonoAndroidHelper.ArchToAbi (arch);
uint infoCount = (uint)infos.Count;
string storePath = Path.Combine (baseOutputDirectory, androidAbi, $"assemblies.{androidAbi}.blob.so");
string storeDirectory = Path.Combine (baseOutputDirectory, androidAbi);
string storePath = Path.Combine (storeDirectory, $"assemblies.{androidAbi}.blob.so");
var index = new List<AssemblyStoreIndexEntry> ();
var descriptors = new List<AssemblyStoreEntryDescriptor> ();
ulong namesSize = 0;
Expand All @@ -115,6 +116,7 @@ string Generate (string baseOutputDirectory, AndroidTargetArch arch, List<Assemb
// We'll start writing to the stream after we seek to the position just after the header, index, descriptors and name data.
ulong curPos = assemblyDataStart;

Directory.CreateDirectory (storeDirectory);
using var fs = File.Open (storePath, FileMode.Create, FileAccess.Write, FileShare.Read);
fs.Seek ((long)curPos, SeekOrigin.Begin);

Expand Down

0 comments on commit 2730842

Please sign in to comment.