Skip to content

Commit

Permalink
Embed framework through cmake on iOS. Add android fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Pfister committed Jan 12, 2023
1 parent 1d8483b commit 6cc724f
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 25 deletions.
1 change: 1 addition & 0 deletions eng/testing/tests.android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<BundleTestAppTargets>$(BundleTestAppTargets);BundleTestAndroidApp</BundleTestAppTargets>
</PropertyGroup>

<Import Project="$(MonoProjectRoot)\msbuild\common\LibraryBuilder.props" />
<Import Project="$(MonoProjectRoot)\msbuild\android\build\AndroidApp.props" />
<Import Project="$(MonoProjectRoot)\msbuild\android\build\AndroidApp.InTree.targets" />

Expand Down
1 change: 1 addition & 0 deletions eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</PropertyGroup>

<PropertyGroup>
<GenerateAppBundle Condition="'$(GenerateAppBundle)' == ''">true</GenerateAppBundle>
<RunAOTCompilation Condition="'$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS'">true</RunAOTCompilation>
</PropertyGroup>

Expand Down
11 changes: 4 additions & 7 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5206,9 +5206,9 @@ add_wrappers (MonoAotCompile *acfg)
MONO_DISABLE_WARNING (4310) // cast truncates constant value
g_assert (*named != (char)0xFF);
MONO_RESTORE_WARNING
slen = mono_metadata_decode_value (named, &named);
slen = mono_metadata_decode_value (named, &named) + (int)strlen(acfg->user_symbol_prefix);
export_name = (char *)g_malloc (slen + 1);
memcpy (export_name, named, slen);
sprintf (export_name, "%s%s", acfg->user_symbol_prefix, named);
export_name [slen] = 0;
named += slen;
}
Expand Down Expand Up @@ -5242,13 +5242,10 @@ MONO_RESTORE_WARNING
for (j = 0; j < decoded_args->named_args_num; ++j) {
if (decoded_args->named_args_info [j].field && !strcmp (decoded_args->named_args_info [j].field->name, "EntryPoint")) {
named = (const char *)decoded_args->named_args[j]->value.primitive;
slen = mono_metadata_decode_value (named, &named);
slen = slen + strlen(acfg->user_symbol_prefix);
slen = mono_metadata_decode_value (named, &named) + (int)strlen(acfg->user_symbol_prefix);
export_name = (char *)g_malloc (slen + 1);
memcpy (export_name, named, slen);
sprintf (export_name, "%s%s", acfg->user_symbol_prefix, named);
export_name [slen] = 0;

strcat(export_name, )
}
}
mono_reflection_free_custom_attr_data_args_noalloc (decoded_args);
Expand Down
1 change: 1 addition & 0 deletions src/mono/msbuild/android/build/AndroidApp.InTree.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<UsingTask TaskName="NetTraceToMibcConverter" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />
<UsingTask TaskName="RuntimeConfigParserTask" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />

<Import Project="..\..\common\LibraryBuilder.targets" />
<Import Project="$(MSBuildThisFileDirectory)AndroidApp.targets" />

<!-- Use local runtime pack -->
Expand Down
3 changes: 3 additions & 0 deletions src/mono/msbuild/android/build/AndroidApp.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
<UseMonoRuntime>true</UseMonoRuntime>
<UseMonoJustInterp Condition="'$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' == 'true'">true</UseMonoJustInterp>

<_NativeLibraryTarget Condition="'$(NativeLibrary)' != ''">_BuildNativeLibrary;</_NativeLibraryTarget>

<AndroidBuildAppAfterThisTarget Condition="'$(AndroidBuildAppAfterThisTarget)' == ''">Publish</AndroidBuildAppAfterThisTarget>
<AndroidBuildAppDependsOn>
_InitializeCommonProperties;
_BeforeAndroidBuildApp;
_AndroidResolveReferences;
_AndroidPrepareProfiledAot;
_AndroidAotCompileApp;
$(_NativeLibraryTarget)
_AndroidGenerateAppBundle;
_AfterAndroidBuildApp
</AndroidBuildAppDependsOn>
Expand Down
94 changes: 93 additions & 1 deletion src/mono/msbuild/android/build/AndroidApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,96 @@
<PropertyGroup>
<_MobileIntermediateOutputPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'mobile'))</_MobileIntermediateOutputPath>
</PropertyGroup>

<ItemGroup>
<!-- static vs dylibs -->
<!-- add all non stub libs first -->
<!-- if runtimecompoents is empty, exclude -static.a and include -stub-static.a instead -->
<!-- if runtimecomponents is *, we're ok because all -static.a is included -->
<!-- if runtimecomponents is a list, add to items and only pull in -static.a -->
<!-- libmonosgen needs to be statically linked always -->
<_UsedComponents
Condition="'$(RuntimeComponents)' != '' and '$(RuntimeComponents)' != '*'"
Include="$(RuntimeComponents)" />

<_RuntimeLibraries
Condition="'$(_TargetsDevice)' == 'true'"
Include="$(AndroidAppDir)\*.a"
Exclude="$(AndroidAppDir)\*-stub-static.a" />
<_RuntimeLibraries
Condition="'$(_TargetsDevice)' == ''"
Include="$(AndroidAppDir)\*.dylib;$(AndroidAppDir)\libmonosgen*.a;$(AndroidAppDir)\*-static.a"
Exclude="$(AndroidAppDir)\libmonosgen*.dylib;$(AndroidAppDir)\*-stub-static.a" />

<!-- and not contains %(_UsedComponents)-static*.a -->
<!-- if count > 0, remove all *-static components except in _UsedComponents -->
<!-- if count > 0, include all stubs except the ones in _UsedComponents -->
<_RuntimeLibraries
Condition="'@(_UsedComponents->Count())' &gt; 0"
Remove="$(AndroidAppDir)\libmono-component-*-static.a" />
<_RuntimeLibraries
Condition="'@(_UsedComponents->Count())' &gt; 0"
Include="$(AndroidAppDir)\*-stub-static.a" />
<_RuntimeLibraries
Condition="'@(_UsedComponents->Count())' == 0"
Remove="$(AndroidAppDir)\*-static.a" />
<_RuntimeLibraries
Condition="'@(_UsedComponents->Count())' == 0"
Include="$(AndroidAppDir)\*-stub-static.a" />
</ItemGroup>

<!-- common linker arguments for app and library builds -->
<ItemGroup>
<_CommonLinkerArgs Include="libz.so" />
<_CommonLinkerArgs Include="log" />
<_CommonLinkerArgs Include="-u GlobalizationNative_LoadICU" />
<_CommonLinkerArgs Include="-u GlobalizationNative_GetLatestJapaneseEra" />
<_CommonLinkerArgs Include="-u GlobalizationNative_ChangeCase" />
<_CommonLinkerArgs Include="-u GlobalizationNative_CloseSortHandle" />
<_CommonLinkerArgs Include="-u GlobalizationNative_GetLocales" />
<_CommonLinkerArgs Include="-u GlobalizationNative_GetLocaleInfoInt" />
<_CommonLinkerArgs Include="-u GlobalizationNative_GetLocaleTimeFormat" />
<_CommonLinkerArgs Include="-u GlobalizationNative_ToUnicode" />
<_CommonLinkerArgs Include="-u GlobalizationNative_NormalizeString" />
<_CommonLinkerArgs Include="-u GlobalizationNative_GetTimeZoneDisplayName" />
<_CommonLinkerArgs Include="-Wl,-exported_symbols_list symbols.txt" />
</ItemGroup>

<PropertyGroup>
<_RuntimeSymbolsToKeep>
_register_aot_modules
_mono_jit_init_version
_mono_jit_exec
_mono_assembly_get_name
_mono_assembly_name_get_culture
_mono_assembly_name_get_name
_mono_assembly_open
_mono_class_get_method_from_name
_mono_class_get_name
_mono_class_get_namespace
_mono_debug_init
_mono_dllmap_insert
_mono_domain_get
_mono_gc_init_finalizer_thread
_mono_get_exception_class
_mono_install_assembly_preload_hook
_mono_install_load_aot_data_hook
_mono_install_unhandled_exception_hook
_mono_jit_cleanup
_mono_jit_parse_options
_mono_jit_set_aot_mode
_mono_object_get_class
_mono_object_get_virtual_method
_mono_runtime_invoke
_mono_set_crash_chaining
_mono_set_signal_chaining
_mono_string_to_utf8
_mono_trace_set_log_handler
_monovm_initialize
_monovm_runtimeconfig_initialize

</_RuntimeSymbolsToKeep>
</PropertyGroup>
</Target>

<Target Name="_BeforeAndroidBuildApp">
Expand Down Expand Up @@ -120,7 +210,9 @@
</Target>


<Target Name="_AndroidGenerateAppBundle" DependsOnTargets="_AndroidGenerateRuntimeConfig">
<Target Name="_AndroidGenerateAppBundle"
Condition="'$(GenerateAppBundle)' == 'true'"
DependsOnTargets="_AndroidGenerateRuntimeConfig">

<PropertyGroup>
<RuntimeComponents Condition="'$(RuntimeComponents)' == ''" >marshal-ilgen</RuntimeComponents>
Expand Down
8 changes: 4 additions & 4 deletions src/mono/msbuild/apple/build/AppleApp.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<Project>
<UsingTask TaskName="AppleAppBuilderTask"
AssemblyFile="$(AppleAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="LibraryBuilderTask"
AssemblyFile="$(LibraryBuilderTasksAssemblyPath)" />
<UsingTask Condition="'$(RunAOTCompilation)' == 'true'"
TaskName="ILStrip"
AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />
Expand Down Expand Up @@ -75,7 +73,7 @@
<_CommonLinkerArgs Include="-liconv" />
<_CommonLinkerArgs Include="-Wl,-exported_symbols_list symbols.txt" />
</ItemGroup>

<PropertyGroup>
<_RuntimeSymbolsToKeep>
_register_aot_modules
Expand Down Expand Up @@ -209,7 +207,9 @@ _monovm_runtimeconfig_initialize
</Target>


<Target Name="_AppleGenerateAppBundle" DependsOnTargets="_AppleGenerateRuntimeConfig">
<Target Name="_AppleGenerateAppBundle"
Condition="'$(GenerateAppBundle)' == 'true'"
DependsOnTargets="_AppleGenerateRuntimeConfig">
<!-- Run App bundler, it uses AOT libs (if needed), link all native bits, compile simple UI (written in ObjC)
and produce an app bundle (with xcode project) -->

Expand Down
15 changes: 3 additions & 12 deletions src/tasks/AndroidAppBuilder/Templates/CMakeLists-android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ if(ANDROID_NDK_MAJOR VERSION_LESS "23")
message(FATAL_ERROR "Error: need at least Android NDK 23, got ${ANDROID_NDK_REVISION}!")
endif()

include(${CMAKE_CURRENT_LIST_DIR}/dotnet_library.cmake)

add_library(
monodroid
SHARED
monodroid.c
%AotModulesSource%
)

%AotSources%
Expand All @@ -23,16 +24,6 @@ include_directories("%MonoInclude%")

target_link_libraries(
monodroid
%NativeLibrariesToLink%
libz.so
log
"-u GlobalizationNative_LoadICU"
"-u GlobalizationNative_GetLatestJapaneseEra"
"-u GlobalizationNative_ChangeCase"
"-u GlobalizationNative_CloseSortHandle"
"-u GlobalizationNative_GetLocales"
"-u GlobalizationNative_GetLocaleInfoInt"
"-u GlobalizationNative_GetLocaleTimeFormat"
"-u GlobalizationNative_ToUnicode"
"-u GlobalizationNative_NormalizeString"
"-u GlobalizationNative_GetTimeZoneDisplayName")
)
4 changes: 3 additions & 1 deletion src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/dotnet_library.cmake)
set_target_properties(lib-%ProjectName% PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION C
MACOSX_FRAMEWORK_IDENTIFIER lib-%LIBRARY_NAME%
MACOSX_FRAMEWORK_IDENTIFIER lib-%ProjectName%
XCODE_ATTRIBUTE_INSTALL_PATH "@executable_path/Frameworks"
XCODE_ATTRIBUTE_SUPPORTS_MACCATALYST "YES"
)
Expand All @@ -39,6 +39,7 @@ set_target_properties(%ProjectName% PROPERTIES
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING "NO"
XCODE_EMIT_EFFECTIVE_PLATFORM_NAME "YES"
XCODE_EMBED_FRAMEWORKS lib-%ProjectName%
RESOURCE "${APP_RESOURCES}"
)

Expand All @@ -65,6 +66,7 @@ endif()

target_link_libraries(
%ProjectName%
lib-%ProjectName%
"-framework Foundation"
"-framework Security"
"-framework UIKit"
Expand Down

0 comments on commit 6cc724f

Please sign in to comment.