Skip to content
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
177facd
Package CLR host static archives
grendello Mar 19, 2025
4fabeb3
Package NDK redistributables into our runtime packs
grendello Mar 19, 2025
dd31583
Build's broken atm, tbc tomorrow
grendello Mar 19, 2025
f8a5bab
Builds now
grendello Mar 20, 2025
c2e821f
More archives to package
grendello Mar 20, 2025
62a4433
Builds now
grendello Mar 20, 2025
6676c58
Nope. Not here.
grendello Mar 20, 2025
bff6399
Symbol preservation tweaks
grendello Mar 20, 2025
9f38fdd
Better. Next step, dotnet/runtime libs (not in runtime pack, alas)
grendello Mar 20, 2025
8030476
Some progress, still ways to go.
grendello Mar 21, 2025
1494a1e
Enable a bunch of p/invokes
grendello Mar 24, 2025
9a9cfcc
Fix archive path
grendello Mar 24, 2025
b3260d1
Make clr hack use configurable build config
grendello Mar 25, 2025
86f7fdb
Package actual NDK libs instead of stubs
grendello Mar 26, 2025
4616cd4
[WIP] reshaping linking
grendello Mar 27, 2025
ffac6be
Remove TODO and add a debug message
grendello Mar 27, 2025
2d0f6fb
Strip debug symbols again
grendello Mar 27, 2025
ee7037e
Some must-have flags
grendello Mar 28, 2025
d9a1505
Fix after rebase
grendello Mar 28, 2025
95c2d0b
Fix indentation
grendello Mar 28, 2025
2a9ef9f
Use NativeLinker for libxamarin-app.so too
grendello Mar 31, 2025
9979247
Use MonoAndroidHelper.RunProcess
grendello Mar 31, 2025
7034f60
Fix typo
grendello Apr 1, 2025
c76faa3
Quote response file path
grendello Apr 1, 2025
a4e89f1
Remove library stubs
grendello Apr 1, 2025
5b92ad7
Fix after rebase
grendello Apr 9, 2025
688c880
Post-rebase fixlet
grendello Apr 9, 2025
74e47f7
Fix a typo
grendello Apr 9, 2025
3f6cdbc
Link `libcoreclrpal.a` whole, just like upstream does
grendello Apr 9, 2025
dd401b6
Update after the recent timing changes
grendello Apr 22, 2025
cc50c2f
Fix after rebase
grendello Apr 24, 2025
274b49f
Post-rebase fixes
grendello Apr 24, 2025
92a77c8
Add support for -Bsymbolic
grendello Apr 24, 2025
fa4f4df
Fix after rebase
grendello Apr 25, 2025
42c48c6
Fixes after 'main' branch changes
grendello Apr 25, 2025
813f82f
Fix after rebase
grendello Apr 30, 2025
54eab3b
Rebase on `main` and fix NRT errors
grendello May 6, 2025
04a29f8
Fix after rebase
grendello May 12, 2025
1d8a40d
Fix after rebase
grendello May 13, 2025
e147bd0
Use the new `libcoreclr_static.a` library
grendello May 13, 2025
13848ce
oops
grendello May 13, 2025
1d35f27
Fix after rebase
grendello May 26, 2025
bbe5aa7
Remove duplicate definition
grendello May 26, 2025
b995d1a
System.IO.Ports is not part of the BCL
grendello Jun 2, 2025
96c7d6e
Address feedback
grendello Jun 3, 2025
7ab3331
Don't need NDK anymore
grendello Jun 3, 2025
592da2e
More `std::string_view` use in p/invoke overrides machinery
grendello Jun 3, 2025
89c4c49
Improve handling of p/invokes using "foreign" libraries
grendello Jun 3, 2025
d705608
Update src/native/clr/runtime-base/android-system.cc
grendello Jun 4, 2025
ac16b3d
Fix after rebase
grendello Jun 6, 2025
87a6743
Comment out MonoVM icalls
grendello Jun 6, 2025
b426edd
CoreCLR preview 7 has all the libs, remove local runtime hack
grendello Jun 30, 2025
3ef5693
Update src/Xamarin.Android.Build.Tasks/Tasks/GenerateNativeMarshalMet…
grendello Jun 30, 2025
eed75f0
Bring those back
grendello Jul 1, 2025
d74ed00
_LinkNativeRuntime is available only in CoreCLR
grendello Jul 1, 2025
c10688c
Doh
grendello Jul 1, 2025
2d9d5b2
Update paths in .gitignore
grendello Jul 1, 2025
782a4e1
Re-enable the code
grendello Jul 2, 2025
9fec06f
Static runtime linking is off by default and always off for Debug builds
grendello Jul 2, 2025
10f9d08
Fix indentation
grendello Jul 2, 2025
b7eebcb
Update src/Xamarin.Android.Build.Tasks/Utilities/NativeRuntimeCompone…
grendello Jul 3, 2025
e8a282a
Update src/native/clr/pinvoke-override/dynamic.cc
grendello Jul 3, 2025
ebbb774
Address feedback
grendello Jul 3, 2025
d539171
Address feedback
grendello Jul 10, 2025
5c21313
Update src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs
grendello Jul 15, 2025
cd2ca9a
Update src/Xamarin.Android.Build.Tasks/Tasks/GetNativeRuntimeComponen…
grendello Jul 15, 2025
00be51b
Update src/Xamarin.Android.Build.Tasks/Tasks/GetNativeRuntimeComponen…
grendello Jul 15, 2025
f0aa0dd
Update src/Xamarin.Android.Build.Tasks/Tasks/LinkNativeRuntime.cs
grendello Jul 15, 2025
2dac62e
Update src/Xamarin.Android.Build.Tasks/Utilities/PreservePinvokesNati…
grendello Jul 15, 2025
6bd0cd7
Update src/Xamarin.Android.Build.Tasks/Utilities/PreservePinvokesNati…
grendello Jul 15, 2025
fbda5ff
Unindent
grendello Jul 15, 2025
36196cb
Address feedback
grendello Jul 15, 2025
4691fea
Merge branch 'main' into dev/grendel/clr-host-static-link
jonathanpeppers Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Novell
*.keystore
/omnisharp.json
src/native/CMakePresets.json
src/native/clr/host/generate-pinvoke-tables
src/native/clr/host/pinvoke-tables.include.generated
src/native/clr/pinvoke-override/generate-pinvoke-tables
src/native/clr/pinvoke-override/pinvoke-tables.include.generated
src/native/mono/pinvoke-override/generate-pinvoke-tables
src/native/mono/pinvoke-override/pinvoke-tables.include.generated
dotnet-install.ps1
4 changes: 4 additions & 0 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@
AndroidRuntime="CoreCLR" />
</ItemGroup>

<!-- These properties serve the purpose of not duplicating the strings between xaprepare and
package creation tools -->
<PropertyGroup>
<_MonoRuntimeFlavorDirName>mono</_MonoRuntimeFlavorDirName>
<_CLRRuntimeFlavorDirName>clr</_CLRRuntimeFlavorDirName>
<_RuntimeRedistDirName>redist</_RuntimeRedistDirName>
</PropertyGroup>

Expand Down
36 changes: 33 additions & 3 deletions build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,51 @@ projects that use the Microsoft.Android.Runtimes framework in .NET 6+.
DependsOnTargets="_GetLicense;_GetDefaultPackageVersion"
BeforeTargets="GetFilesToPackage" >
<PropertyGroup>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">clr</_RuntimeFlavorDirName>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">mono</_RuntimeFlavorDirName>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">$(_CLRRuntimeFlavorDirName)</_RuntimeFlavorDirName>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">$(_MonoRuntimeFlavorDirName)</_RuntimeFlavorDirName>
<_ClangArch Condition=" '$(AndroidRID)' == 'android-arm64' ">aarch64</_ClangArch>
<_ClangArch Condition=" '$(AndroidRID)' == 'android-arm' ">arm</_ClangArch>
<_ClangArch Condition=" '$(AndroidRID)' == 'android-x64' ">x86_64</_ClangArch>
<_ClangArch Condition=" '$(AndroidRID)' == 'android-x86' ">i686</_ClangArch>
</PropertyGroup>

<ItemGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.debug-static-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.debug-static-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.debug.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.debug.so" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.release-static-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.release-static-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.release.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.release.so" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libpinvoke-override-dynamic-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libpinvoke-override-dynamic-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libpinvoke-override-dynamic-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libpinvoke-override-dynamic-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-common-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-common-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-common-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libruntime-base-common-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-java-interop-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-java-interop-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-java-interop-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-java-interop-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-lz4-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-lz4-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-lz4-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-lz4-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-shared-bits-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-shared-bits-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-shared-bits-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxa-shared-bits-release.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-startup-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-startup-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-startup-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-startup-release.a" />

<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeRedistDirName)\$(AndroidRID)\crtbegin_so.o" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeRedistDirName)\$(AndroidRID)\crtend_so.o" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeRedistDirName)\$(AndroidRID)\libc++_static.a" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeRedistDirName)\$(AndroidRID)\libc++abi.a" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeRedistDirName)\$(AndroidRID)\libclang_rt.builtins-$(_ClangArch)-android.a" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeRedistDirName)\$(AndroidRID)\libunwind.a" />
</ItemGroup>

<ItemGroup Condition=" '$(AndroidRuntime)' == 'Mono' ">
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libmono-android.debug.so" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libmono-android.release.so" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-debug-app-helper.so" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-native-tracing.so" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin.a" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin-debug.a" />
<NativeRuntimeAsset Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin-release.a" />
</ItemGroup>

<ItemGroup Condition=" '$(AndroidRuntime)' != 'NativeAOT' ">
Expand Down
2 changes: 1 addition & 1 deletion build-tools/scripts/generate-pinvoke-tables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ HOST="$(uname | tr A-Z a-z)"
NATIVE_DIR="${MY_DIR}/../../src/native"
MONODROID_SOURCE_DIR="${NATIVE_DIR}/mono/pinvoke-override"
MONODROID_INCLUDE_DIR="${NATIVE_DIR}/mono/shared"
CLR_SOURCE_DIR="${NATIVE_DIR}/clr/host"
CLR_SOURCE_DIR="${NATIVE_DIR}/clr/pinvoke-override"
CLR_INCLUDE_DIR="${NATIVE_DIR}/clr/include/shared"
GENERATOR_SOURCE="generate-pinvoke-tables.cc"
GENERATOR_BINARY="generate-pinvoke-tables"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static class KnownProperties
public const string AndroidToolchainDirectory = "AndroidToolchainDirectory";
public const string AutoProvision = "AutoProvision";
public const string AutoProvisionUsesSudo = "AutoProvisionUsesSudo";
public const string CLRRuntimeFlavorDirName = "_CLRRuntimeFlavorDirName";
public const string CMakePath = "CmakePath";
public const string Configuration = "Configuration";
public const string CommandLineToolsVersion = nameof (CommandLineToolsVersion);
Expand Down Expand Up @@ -46,6 +47,7 @@ static class KnownProperties
public const string MonoDarwinPackageUrl = "MonoDarwinPackageUrl";
public const string MonoRequiredMinimumVersion = "MonoRequiredMinimumVersion";
public const string MonoRequiredMaximumVersion = "MonoRequiredMaximumVersion";
public const string MonoRuntimeFlavorDirName = "_MonoRuntimeFlavorDirName";
public const string MonoSourceFullPath = "MonoSourceFullPath";
public const string NativeRuntimeOutputRootDir = "NativeRuntimeOutputRootDir";
public const string NinjaPath = "NinjaPath";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Xamarin.Android.Prepare
properties.Add (KnownProperties.AndroidToolchainDirectory, StripQuotes (@"@AndroidToolchainDirectory@"));
properties.Add (KnownProperties.AutoProvision, StripQuotes ("@AutoProvision@"));
properties.Add (KnownProperties.AutoProvisionUsesSudo, StripQuotes ("@AutoProvisionUsesSudo@"));
properties.Add (KnownProperties.CLRRuntimeFlavorDirName, StripQuotes ("@_CLRRuntimeFlavorDirName@"));
properties.Add (KnownProperties.CMakePath, StripQuotes (@"@CmakePath@"));
properties.Add (KnownProperties.Configuration, StripQuotes ("@Configuration@"));
properties.Add (KnownProperties.CommandLineToolsFolder, StripQuotes ("@CommandLineToolsFolder@"));
Expand All @@ -48,6 +49,7 @@ namespace Xamarin.Android.Prepare
properties.Add (KnownProperties.MicrosoftAndroidSdkOutDir, StripQuotes (@"@MicrosoftAndroidSdkOutDir@"));
properties.Add (KnownProperties.MonoCecilVersion, StripQuotes ("@MonoCecilVersion@"));
properties.Add (KnownProperties.MonoDarwinPackageUrl, StripQuotes ("@MonoDarwinPackageUrl@"));
properties.Add (KnownProperties.MonoRuntimeFlavorDirName, StripQuotes ("@_MonoRuntimeFlavorDirName@"));
properties.Add (KnownProperties.MonoRequiredMinimumVersion, StripQuotes ("@MonoRequiredMinimumVersion@"));
properties.Add (KnownProperties.MonoRequiredMaximumVersion, StripQuotes ("@MonoRequiredMaximumVersion@"));
properties.Add (KnownProperties.MonoSourceFullPath, StripQuotes (@"@MonoSourceFullPath@"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public static partial class Defaults
{ "x86_64", "android-x64" },
};

public static readonly Dictionary<string, string> AbiToClangArch = new (StringComparer.Ordinal) {
{ "armeabi-v7a", "arm" },
{ "arm64-v8a", "aarch64" },
{ "x86", "i686" },
{ "x86_64", "x86_64" },
};

public static readonly List <NDKTool> NDKTools = new List<NDKTool> {
// Tools prefixed with architecture triple
new NDKTool (name: "as", prefixed: true),
Expand Down Expand Up @@ -233,6 +240,7 @@ public static partial class Paths
// Other
public static string AndroidNdkDirectory => ctx.Properties.GetRequiredValue (KnownProperties.AndroidNdkDirectory);
public static string AndroidToolchainRootDirectory => GetCachedPath (ref androidToolchainRootDirectory, () => Path.Combine (AndroidNdkDirectory, "toolchains", "llvm", "prebuilt", NdkToolchainOSTag));
public static string AndroidClangRootDirectory => GetCachedPath (ref androidClangRootDirectory, () => Path.Combine (AndroidToolchainRootDirectory, "lib", "clang"));
public static string AndroidToolchainBinDirectory => GetCachedPath (ref androidToolchainBinDirectory, () => Path.Combine (AndroidToolchainRootDirectory, "bin"));
public static string AndroidToolchainSysrootLibDirectory => GetCachedPath (ref androidToolchainSysrootLibDirectory, () => Path.Combine (AndroidToolchainRootDirectory, "sysroot", "usr", "lib"));
public static string WindowsBinutilsInstallDir => GetCachedPath (ref windowsBinutilsInstallDir, () => Path.Combine (InstallMSBuildDir, "binutils"));
Expand Down Expand Up @@ -288,6 +296,7 @@ static string GetCachedPath (ref string? variable, Func<string> creator)
static string? buildBinDir;
static string? binDir;
static string? androidToolchainRootDirectory;
static string? androidClangRootDirectory;
static string? androidToolchainBinDirectory;
static string? androidToolchainSysrootLibDirectory;
static string? installMSBuildDir;
Expand Down
35 changes: 35 additions & 0 deletions build-tools/xaprepare/xaprepare/Steps/Step_Android_SDK_NDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ sealed class AndroidPackage
#nullable enable

static readonly string[] CRTFiles = {
"crtbegin_so.o",
"crtend_so.o",
"libc.so",
"libdl.so",
"liblog.so",
"libm.so",
"libz.so",
};

static readonly string[] CPPAbiFiles = {
"libc++_static.a",
"libc++abi.a",
};

static readonly string[] ClangArchFiles = {
"libunwind.a",
};

bool RefreshSdk = false;
bool RefreshNdk = false;
AndroidToolchainComponentType DependencyTypeToInstall = AndroidToolchainComponentType.All;
Expand Down Expand Up @@ -189,14 +200,38 @@ bool CopyRedistributableFiles (Context context)
throw new InvalidOperationException ($"Unknown LLVM version format for '{lines[0]}'");
}

string clangLibPath = Path.Combine (
Configurables.Paths.AndroidClangRootDirectory,
llvmVersion[0],
"lib",
"linux"
);

foreach (var kvp in Configurables.Defaults.AndroidToolchainPrefixes) {
string abi = kvp.Key;
string abiDir = Path.Combine (Configurables.Paths.AndroidToolchainSysrootLibDirectory, kvp.Value);
string crtFilesPath = Path.Combine (abiDir, BuildAndroidPlatforms.NdkMinimumAPI.ToString (CultureInfo.InvariantCulture));
string clangArch = Configurables.Defaults.AbiToClangArch[abi];

foreach (string file in CRTFiles) {
CopyFile (abi, crtFilesPath, file);
}

foreach (string file in CPPAbiFiles) {
CopyFile (abi, abiDir, file);
}

CopyFile (abi, clangLibPath, $"libclang_rt.builtins-{clangArch}-android.a");

// Yay, consistency
if (String.Compare (clangArch, "i686", StringComparison.Ordinal) == 0) {
clangArch = "i386";
}
string clangArchLibPath = Path.Combine (clangLibPath, clangArch);

foreach (string file in ClangArchFiles) {
CopyFile (abi, clangArchLibPath, file);
}
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions build-tools/xaprepare/xaprepare/xaprepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
Replacements="@XA_SOURCE_ROOT@=$([System.IO.Path]::GetFullPath ('$(MSBuildThisFileDirectory)..\..\..'));@XA_PREPARE_SOURCE@=$([System.IO.Path]::GetFullPath ('$(MSBuildThisFileDirectory)\.'));@XA_PRODUCT_VERSION@=$(ProductVersion)" />

<ItemGroup>
<Replacement Include="@_CLRRuntimeFlavorDirName@=$(_CLRRuntimeFlavorDirName)" />
<Replacement Include="@_MonoRuntimeFlavorDirName@=$(_MonoRuntimeFlavorDirName)" />
<Replacement Include="@AndroidLatestStableFrameworkVersion@=$(AndroidLatestStableFrameworkVersion)" />
<Replacement Include="@AndroidCmakeUrlPrefix@=$(AndroidCmakeUrlPrefix)" />
<Replacement Include="@AndroidCmakeVersion@=$(AndroidCmakeVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ This file is imported *after* the Microsoft.NET.Sdk/Sdk.targets.
<Import Project="Microsoft.Android.Sdk.Aot.targets" Condition=" '$(AndroidApplication)' == 'true' " />
<Import Project="Microsoft.Android.Sdk.Application.targets" Condition=" '$(AndroidApplication)' == 'true' " />
<Import Project="Microsoft.Android.Sdk.AssemblyResolution.targets" />

<!-- This one must be imported after `Microsoft.Android.Sdk.AssemblyResolution.targets` -->
<Import Project="Microsoft.Android.Sdk.NativeRuntime.targets" Condition=" '$(AndroidApplication)' == 'true' And '$(_AndroidRuntime)' == 'CoreCLR' " />

<Import Project="Microsoft.Android.Sdk.ILLink.targets" />
<Import Project="Microsoft.Android.Sdk.ProjectCapabilities.targets" />
<Import Project="Microsoft.Android.Sdk.Publish.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,25 @@ _ResolveAssemblies MSBuild target.
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" />
</ItemGroup>

<!-- Let's keep the item group close to the task that uses them, the list is irrelevant for
anything else. The group MUST contain only shared libraries from the runtime pack.
DO NOT modify the group unless you're absolutely sure what you're doing -->
<ItemGroup Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " >
<_KnownRuntimeNativeLibrary Include="libSystem.Globalization.Native.so" />
<_KnownRuntimeNativeLibrary Include="libSystem.IO.Compression.Native.so" />
<_KnownRuntimeNativeLibrary Include="libSystem.Native.so" />
<_KnownRuntimeNativeLibrary Include="libSystem.Security.Cryptography.Native.Android.so" />
<_KnownRuntimeNativeLibrary Include="libclrjit.so" />
<_KnownRuntimeNativeLibrary Include="libcorclr.so" />
</ItemGroup>

<ProcessNativeLibraries
NativeRuntimeLinking="$(_AndroidEnableNativeRuntimeLinking)"
InputLibraries="@(_ResolvedNativeLibraries)"
ExcludedLibraries="@(_ExcludedNativeLibraries)"
Components="@(_MonoComponent->Distinct())"
IncludeDebugSymbols="$(AndroidIncludeDebugSymbols)">
IncludeDebugSymbols="$(AndroidIncludeDebugSymbols)"
KnownRuntimeNativeLibraries="@(_KnownRuntimeNativeLibrary)">
<Output TaskParameter="OutputLibraries" ItemName="FrameworkNativeLibrary" />
</ProcessNativeLibraries>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ properties that determine build ordering.
</_AndroidBuildDependsOn>
</PropertyGroup>

<PropertyGroup Condition=" '$(AndroidApplication)' == 'true' And '$(_AndroidRuntime)' == 'CoreCLR' ">
<_NativeRuntimeLinking>_LinkNativeRuntime</_NativeRuntimeLinking>
</PropertyGroup>

<PropertyGroup Condition=" '$(AndroidApplication)' == 'True' ">
<BuildDependsOn>
$(_AndroidBuildDependsOn);
Expand Down Expand Up @@ -76,6 +80,7 @@ properties that determine build ordering.
_ReadAndroidManifest;
_CompileJava;
_CreateApplicationSharedLibraries;
$(_NativeRuntimeLinking);
_CompileDex;
$(_AfterCompileDex);
_CreateBaseApk;
Expand Down
Loading
Loading