Skip to content

Commit 2730842

Browse files
committed
Assembly store embedding works
1 parent 7436fbf commit 2730842

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyStores.targets

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<CreateEmbeddedAssemblyStore
1818
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
1919
AppSharedLibrariesDir="$(_AndroidApplicationSharedLibraryPath)"
20+
AssemblySourcesDir="$(IntermediateOutputPath)android"
2021
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)\test\"
2122
Debug="$(AndroidIncludeDebugSymbols)"
2223
EnableCompression="$(AndroidEnableAssemblyCompression)"

src/Xamarin.Android.Build.Tasks/Tasks/CreateEmbeddedAssemblyStore.cs

+37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34

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

22+
[Required]
23+
public string AssemblySourcesDir { get; set; }
24+
2125
[Required]
2226
public string CompressedAssembliesDir { get; set; }
2327

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

74+
var objectFiles = new List<ITaskItem> ();
75+
var sourceFiles = new List<ITaskItem> ();
76+
Dictionary<AndroidTargetArch, string> assemblyStorePaths = storeBuilder.Generate (Path.Combine (AppSharedLibrariesDir, "embedded"));
77+
foreach (var kvp in assemblyStorePaths) {
78+
string abi = MonoAndroidHelper.ArchToAbi (kvp.Key);
79+
string inputFile = kvp.Value;
80+
81+
List<ITaskItem> items = ELFEmbeddingHelper.EmbedBinary (
82+
Log,
83+
abi,
84+
AndroidBinUtilsDirectory,
85+
inputFile,
86+
ELFEmbeddingHelper.KnownEmbedItems.AssemblyStore,
87+
AssemblySourcesDir
88+
);
89+
90+
if (items.Count == 0) {
91+
continue;
92+
}
93+
94+
objectFiles.AddRange (items);
95+
foreach (ITaskItem objectItem in items) {
96+
var sourceItem = new TaskItem (
97+
Path.ChangeExtension (objectItem.ItemSpec, ".s"),
98+
objectItem.CloneCustomMetadata ()
99+
);
100+
sourceFiles.Add (sourceItem);
101+
}
102+
}
103+
104+
NativeAssemblySources = sourceFiles.ToArray ();
105+
EmbeddedObjectFiles = objectFiles.ToArray ();
106+
70107
return !Log.HasLoggedErrors;
71108

72109
void DoAddAssembliesFromArchCollection (TaskLoggingHelper log, AndroidTargetArch arch, ITaskItem assembly)

src/Xamarin.Android.Build.Tasks/Utilities/AssemblyStoreGenerator.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ string Generate (string baseOutputDirectory, AndroidTargetArch arch, List<Assemb
101101

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

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

0 commit comments

Comments
 (0)