Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4243eb0
Update ApkBuilder to support static linking
kotlarmilos Apr 8, 2025
43310f2
Add static libs to the framework directory
kotlarmilos Apr 9, 2025
4463fae
Add static libs to the runtime pack
kotlarmilos Apr 14, 2025
f08e9fe
Fix formatting
kotlarmilos Apr 14, 2025
ffa5351
Add object libraries for Android static linking
kotlarmilos Apr 24, 2025
8507f65
Install libcoreclrpal.a as it is linked using -Wl,--whole-archive
kotlarmilos Apr 24, 2025
76b4d6a
Fix x64 static linking
kotlarmilos Apr 24, 2025
2ef4399
Add gc_vxsort objects
kotlarmilos Apr 25, 2025
1ff51f6
Add static test project
kotlarmilos Apr 25, 2025
0584ea8
Fix MainLibraryFileName in Android.Device_Emulator.JIT.Static.Test pr…
kotlarmilos Apr 25, 2025
d6a2893
Update src/coreclr/gc/vxsort/CMakeLists.txt
kotlarmilos Apr 26, 2025
2b3a5ee
Update src/coreclr/gc/unix/CMakeLists.txt
kotlarmilos Apr 26, 2025
db2e108
Update CMakeLists.txt to conditionally link gc_pal_objects for Android
kotlarmilos Apr 26, 2025
39dea31
Test static linking on linux
kotlarmilos Apr 26, 2025
de2506e
Fix typo
kotlarmilos Apr 26, 2025
1a12a79
Revert gc_pal changes to test the build
kotlarmilos Apr 27, 2025
7f282b6
Revert changes
kotlarmilos Apr 28, 2025
2df2281
Merge branch 'dotnet:main' into feature/coreclr-android-static-libs
kotlarmilos Apr 28, 2025
21b454f
Add gcinfo library
kotlarmilos Apr 28, 2025
d17fe7a
Conditionally add gcinfo
kotlarmilos Apr 28, 2025
d53aefc
FIx formatting
kotlarmilos Apr 29, 2025
cd867ae
Switch from static to object
kotlarmilos Apr 30, 2025
a9ac92c
Merge branch 'main' into feature/coreclr-android-static-libs
kotlarmilos Apr 30, 2025
e9d5b20
Fix coreclr build
kotlarmilos Apr 30, 2025
7b4efbf
Remove unnecessary static library installation for Android
kotlarmilos Apr 30, 2025
ea53d06
Update static libraries to be based on the object libraries
kotlarmilos May 1, 2025
4dc57cf
Merge branch 'main' into feature/coreclr-android-static-libs
kotlarmilos May 2, 2025
5e6cc7c
Add coreclrpal_objects
kotlarmilos May 2, 2025
ed47a53
Merge branch 'main' into feature/coreclr-android-static-libs
kotlarmilos May 6, 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
2 changes: 1 addition & 1 deletion src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ endif(CLR_CMAKE_TARGET_WIN32)

# add the install targets
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS)
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_ANDROID)
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
endif()

Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/gc/unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ set(GC_PAL_SOURCES
cgroup.cpp)

add_library(gc_pal STATIC ${GC_PAL_SOURCES} ${VERSION_FILE_PATH})

if(CLR_CMAKE_HOST_ANDROID)
install_clr(TARGETS gc_pal DESTINATIONS . sharedFramework)
endif()
4 changes: 4 additions & 0 deletions src/coreclr/minipal/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ add_library(coreclrminipal
)

target_link_libraries(coreclrminipal PRIVATE minipal)

if(CLR_CMAKE_HOST_ANDROID)
install_clr(TARGETS coreclrminipal DESTINATIONS . sharedFramework)
endif()
4 changes: 4 additions & 0 deletions src/coreclr/nativeresources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ add_library_clr(nativeresourcestring
)

install_clr (TARGETS nativeresourcestring DESTINATIONS lib)

if(CLR_CMAKE_HOST_ANDROID)
install_clr(TARGETS nativeresourcestring DESTINATIONS . sharedFramework)
endif()
3 changes: 3 additions & 0 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,6 @@ endif(FEATURE_EVENT_TRACE)

# Install the static PAL library for VS
install_clr (TARGETS coreclrpal DESTINATIONS lib)
if(CLR_CMAKE_HOST_ANDROID)
install_clr(TARGETS coreclrpal DESTINATIONS . sharedFramework)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ set_target_properties(eventprovider PROPERTIES LINKER_LANGUAGE CXX)

# Install the static eventprovider library
install(TARGETS eventprovider DESTINATION lib)

if(CLR_CMAKE_HOST_ANDROID)
install_clr(TARGETS eventprovider DESTINATIONS . sharedFramework)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
<PlatformManifestFileEntry Include="libcoreclr.so" IsNative="true" />
<PlatformManifestFileEntry Include="libcoreclr.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libcoreclr_static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libcoreclrminipal.a" IsNative="true" />
<PlatformManifestFileEntry Include="libcoreclrpal.a" IsNative="true" />
<PlatformManifestFileEntry Include="libeventprovider.a" IsNative="true" />
<PlatformManifestFileEntry Include="libgc_pal.a" IsNative="true" />
<PlatformManifestFileEntry Include="libnativeresourcestring.a" IsNative="true" />
<PlatformManifestFileEntry Include="libminipal.a" IsNative="true" />
<PlatformManifestFileEntry Include="clrgc.dll" IsNative="true" />
<PlatformManifestFileEntry Include="libclrgc.so" IsNative="true" />
<PlatformManifestFileEntry Include="libclrgc.dylib" IsNative="true" />
Expand Down
5 changes: 3 additions & 2 deletions src/mono/msbuild/android/build/AndroidBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<_HostOS Condition="$([MSBuild]::IsOSPlatform('Windows'))">windows</_HostOS>
<_HostOS Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</_HostOS>
<_HostOS Condition="'$(_HostOS)' == ''">linux</_HostOS>

<_IsLibraryMode Condition="'$(UseMonoRuntime)' == 'true' and '$(UseNativeAOTRuntime)' != 'true' and '$(NativeLib)' != ''">true</_IsLibraryMode>
<_ReadRuntimeComponentsManifestTargetName Condition="'$(UseMonoRuntime)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">_MonoReadAvailableComponentsManifest</_ReadRuntimeComponentsManifestTargetName>

<StaticLinkedRuntime Condition="'$(RuntimeFlavor)' == 'coreclr' and '$(StaticLinkedRuntime)' == ''">false</StaticLinkedRuntime>

<AndroidBuildAfterThisTarget Condition="'$(AndroidBuildAfterThisTarget)' == ''">Publish</AndroidBuildAfterThisTarget>
<AndroidBuildDependsOn Condition="'$(UseMonoRuntime)' == 'true'">
$(_ReadRuntimeComponentsManifestTargetName);
Expand Down Expand Up @@ -41,4 +42,4 @@
<Import Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(UseMonoRuntime)' == 'true'" Project="$(_CommonTargetsDir)CommonMobileBuild.props" />
<Import Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(UseMonoRuntime)' == 'true'" Project="$(_CommonTargetsDir)RuntimeComponentManifest.targets" />
<Import Condition="'$(UseNativeAOTRuntime)' != 'true' and ('$(UseMonoRuntime)' == 'true' and '$(RunAOTCompilation)' == 'true')" Project="$(_CommonTargetsDir)MonoAOTCompiler.props" />
</Project>
</Project>
3 changes: 2 additions & 1 deletion src/mono/msbuild/android/build/AndroidBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
ProjectName="$(AppName)"
RuntimeComponents="@(RuntimeComponents)"
RuntimeIdentifier="$(RuntimeIdentifier)"
StripDebugSymbols="$(StripDebugSymbols)">
StripDebugSymbols="$(StripDebugSymbols)"
StaticLinkedRuntime="$(StaticLinkedRuntime)">
<Output TaskParameter="ApkBundlePath" PropertyName="ApkBundlePath" />
<Output TaskParameter="ApkPackageId" PropertyName="ApkPackageId" />
</AndroidAppBuilderTask>
Expand Down
4 changes: 3 additions & 1 deletion src/mono/sample/Android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DEPLOY_AND_RUN?=true
RUNTIME_FLAVOR?=mono
R2R?=false
R2R_COMPOSITE?=false
STATIC_LINKING?=false

#If DIAGNOSTIC_PORTS is enabled, @(RuntimeComponents) must also include 'diagnostics_tracing'.
#If @(RuntimeComponents) includes 'diagnostics_tracing', DIAGNOSTIC_PORTS is optional.
Expand Down Expand Up @@ -57,7 +58,8 @@ run: appbuilder
/p:RuntimeFlavor=$(RUNTIME_FLAVOR) \
/p:PublishReadyToRun=$(R2R) \
/p:PublishReadyToRunComposite=$(R2R_COMPOSITE) \
/p:StaticLinkedRuntime=$(STATIC_LINKING) \
/bl
clean:
rm -rf $(REPO_DIR)/artifacts/bin/AndroidSampleApp
rm -rf $(REPO_DIR)/artifacts/obj/mono/AndroidSampleApp
rm -rf $(REPO_DIR)/artifacts/obj/mono/AndroidSampleApp
6 changes: 6 additions & 0 deletions src/native/minipal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ add_library(minipal_sanitizer_support OBJECT
# Exclude this target from the default build as we may not have sanitzer headers available
# in a non-sanitized build.
set_target_properties(minipal_sanitizer_support PROPERTIES EXCLUDE_FROM_ALL ON)


if(CLR_CMAKE_HOST_ANDROID)
install (TARGETS minipal DESTINATION .)
endif()

34 changes: 25 additions & 9 deletions src/tasks/AndroidAppBuilder/ApkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ public ApkBuilder(TaskLoggingHelper logger)
throw new ArgumentException($"Using DiagnosticPorts targeting Mono requires diagnostics_tracing runtime component, which was not included in 'RuntimeComponents' item group. @RuntimeComponents: '{string.Join(", ", RuntimeComponents)}'");
}

if (IsCoreCLR && StaticLinkedRuntime)
{
throw new ArgumentException("Static linking is not supported for CoreCLR runtime");
}

AndroidSdkHelper androidSdkHelper = new AndroidSdkHelper(AndroidSdk, BuildApiLevel, BuildToolsVersion);

if (string.IsNullOrEmpty(MinApiLevel))
Expand Down Expand Up @@ -263,7 +258,10 @@ public ApkBuilder(TaskLoggingHelper logger)
{
runtimeLib = Path.Combine(AppDir, "libmonosgen-2.0.so");
}
else if (IsCoreCLR)
else if (StaticLinkedRuntime && IsCoreCLR)
{
runtimeLib = Path.Combine(AppDir, "libcoreclr_static.a");
}else if (IsCoreCLR)
{
runtimeLib = Path.Combine(AppDir, "libcoreclr.so");
}
Expand All @@ -277,7 +275,7 @@ public ApkBuilder(TaskLoggingHelper logger)
nativeLibraries += $"{runtimeLib}{Environment.NewLine}";
}

if (StaticLinkedRuntime)
if (StaticLinkedRuntime && IsMono)
{
string[] staticComponentStubLibs = Directory.GetFiles(AppDir, "libmono-component-*-stub-static.a");

Expand Down Expand Up @@ -313,6 +311,21 @@ public ApkBuilder(TaskLoggingHelper logger)
}
}

if (StaticLinkedRuntime && IsCoreCLR)
{
string[] staticLibs = Directory.GetFiles(AppDir, "*.a")
.Where(lib => !Path.GetFileName(lib).Equals("libcoreclr_static.a", StringComparison.OrdinalIgnoreCase))
.ToArray();

foreach (string lib in staticLibs)
{
nativeLibraries += $" {lib}{Environment.NewLine}";
}

nativeLibraries += $" libc++abi.a{Environment.NewLine}";
nativeLibraries += $" libc++_static.a{Environment.NewLine}";
}

StringBuilder extraLinkerArgs = new StringBuilder();
foreach (ITaskItem item in ExtraLinkerArguments)
{
Expand Down Expand Up @@ -401,7 +414,8 @@ public ApkBuilder(TaskLoggingHelper logger)
envVariables += $"\t\tsetEnv(\"{name}\", \"{value}\");\n";
}

string jniLibraryName = (IsLibraryMode) ? ProjectName! : "System.Security.Cryptography.Native.Android";
string jniLibraryName = (IsLibraryMode) ? ProjectName! :
(StaticLinkedRuntime && IsCoreCLR) ? "monodroid" : "System.Security.Cryptography.Native.Android";
string monoRunner = Utils.GetEmbeddedResource("MonoRunner.java")
.Replace("%EntryPointLibName%", Path.GetFileName(mainLibraryFileName))
.Replace("%JNI_LIBRARY_NAME%", jniLibraryName)
Expand Down Expand Up @@ -461,7 +475,9 @@ public ApkBuilder(TaskLoggingHelper logger)
excludedLibs.Add("libmscordaccore.so");
}
}
dynamicLibs.AddRange(Directory.GetFiles(AppDir, "*.so").Where(file => !excludedLibs.Contains(Path.GetFileName(file))));

if (!StaticLinkedRuntime)
dynamicLibs.AddRange(Directory.GetFiles(AppDir, "*.so").Where(file => !excludedLibs.Contains(Path.GetFileName(file))));
}

// add all *.so files to lib/%abi%/
Expand Down
Loading