Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor + marshal methods failure #8800

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
path = external/xamarin-android-tools
url = https://github.com/xamarin/xamarin-android-tools
branch = main
[submodule "external/libunwind"]
path = external/libunwind
url = https://github.com/libunwind/libunwind.git
[submodule "external/xxHash"]
path = external/xxHash
url = https://github.com/Cyan4973/xxHash.git
Expand Down
4 changes: 4 additions & 0 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<IgnoreMaxMonoVersion Condition=" '$(IgnoreMaxMonoVersion)' == '' ">True</IgnoreMaxMonoVersion>
<OpenTKSourceDirectory>$(MSBuildThisFileDirectory)external\opentk</OpenTKSourceDirectory>
<SqliteSourceDirectory Condition=" '$(SqliteSourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\sqlite</SqliteSourceDirectory>
<LibUnwindSourceDirectory Condition=" '$(LibUnwindSourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\libunwind</LibUnwindSourceDirectory>
<LibUnwindGeneratedHeadersDirectory Condition=" '$(LibUnwindGeneratedHeadersDirectory)' == '' ">$(BootstrapOutputDirectory)\libunwind</LibUnwindGeneratedHeadersDirectory>
<XamarinAndroidSourcePath>$(MSBuildThisFileDirectory)</XamarinAndroidSourcePath>
<ThirdPartySourcePath>$(MSBuildThisFileDirectory)src-ThirdParty\</ThirdPartySourcePath>
<AllSupported32BitTargetAndroidAbis>armeabi-v7a;x86</AllSupported32BitTargetAndroidAbis>
Expand Down Expand Up @@ -144,6 +146,8 @@
<JavaInteropFullPath>$([System.IO.Path]::GetFullPath ('$(JavaInteropSourceDirectory)'))</JavaInteropFullPath>
<MonoSourceFullPath>$([System.IO.Path]::GetFullPath ('$(MonoSourceDirectory)'))</MonoSourceFullPath>
<SqliteSourceFullPath>$([System.IO.Path]::GetFullPath ('$(SqliteSourceDirectory)'))</SqliteSourceFullPath>
<LibUnwindSourceFullPath>$([System.IO.Path]::GetFullPath ('$(LibUnwindSourceDirectory)'))</LibUnwindSourceFullPath>
<LibUnwindGeneratedHeadersFullPath>$([System.IO.Path]::GetFullPath ('$(LibUnwindGeneratedHeadersDirectory)'))</LibUnwindGeneratedHeadersFullPath>
<OpenTKSourceFullPath>$([System.IO.Path]::GetFullPath ('$(OpenTKSourceDirectory)'))</OpenTKSourceFullPath>
<JavaInteropTargetFrameworkVersion>net8.0</JavaInteropTargetFrameworkVersion>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions TheoriesToTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* See if it's a threading issue - add full locking to `get_function_pointer` instead of atomics that we use now
* See if it's an ALC issue - call `get_function_pointer` every time and check the returned pointer value
* Implement Jon's idea to always have the "old" dynamic registration stuff in JCW and only use it when some flag
is set and marshal methods are active.
2 changes: 2 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Diagnost
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Cecil", "external\Java.Interop\src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil.csproj", "{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libunwind", "src\libunwind-xamarin\libunwind-xamarin.csproj", "{F8E4961B-C427-47F9-92D6-0BEB5B76B3D7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "monodroid", "src\monodroid\monodroid.csproj", "{53EE4C57-1C03-405A-8243-8DA539546C88}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}"
Expand Down
144 changes: 143 additions & 1 deletion build-tools/cmake/xa_common.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,143 @@
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake")

if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(DEBUG_BUILD True)
else()
set(DEBUG_BUILD False)
endif()

set(XA_NO_INLINE "$ENV{XA_NO_INLINE}")
if(XA_NO_INLINE)
set(DONT_INLINE_DEFAULT ON)
else()
set(DONT_INLINE_DEFAULT OFF)
endif()

set(XA_NO_STRIP "$ENV{XA_NO_STRIP}")
if(XA_NO_STRIP OR DEBUG_BUILD)
set(STRIP_DEBUG_DEFAULT OFF)
endif()

option(ENABLE_CLANG_ASAN "Enable the clang AddressSanitizer support" OFF)
option(ENABLE_CLANG_UBSAN "Enable the clang UndefinedBehaviorSanitizer support" OFF)

if(ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN)
set(STRIP_DEBUG_DEFAULT OFF)
set(ANALYZERS_ENABLED ON)
else()
if(NOT XA_NO_STRIP)
set(STRIP_DEBUG_DEFAULT ON)
endif()
set(ANALYZERS_ENABLED OFF)
endif()

option(COMPILER_DIAG_COLOR "Show compiler diagnostics/errors in color" ON)
option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFAULT})
option(DISABLE_DEBUG "Disable the built-in debugging code" OFF)
option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ON)
option(DONT_INLINE "Do not inline any functions which are usually inlined, to get better stack traces" ${DONT_INLINE_DEFAULT})

if(USE_CCACHE)
if(CMAKE_CXX_COMPILER MATCHES "/ccache/")
message(STATUS "ccache: compiler already uses ccache")
else()
find_program(CCACHE ccache)
if(CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}")
message(STATUS "ccache: compiler will be lauched with ${CCACHE}")
endif()
endif()
endif()

if(ANDROID_STL STREQUAL none)
set(USES_LIBSTDCPP False)
else()
set(USES_LIBSTDCPP True)
endif()

#
# General config
#
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(IS_LINUX True)
else()
set(IS_LINUX False)
endif()

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
set(IS_MACOS True)
else()
set(IS_MACOS False)
endif()

set(XA_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/Build${XA_BUILD_CONFIGURATION}")
include("${XA_BUILD_DIR}/xa_build_configuration.cmake")

#
# Paths
#
if(ANDROID_ABI MATCHES "^arm64-v8a")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM64}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_arm64-v8a_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^armeabi-v7a")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_armeabi-v7a_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^x86_64")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86_64}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_64_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^x86")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_TRIPLE}")
else()
message(FATAL "${ANDROID_ABI} is not supported for .NET 6+ builds")
endif()

file(REAL_PATH "../../" REPO_ROOT_DIR)
set(EXTERNAL_DIR "${REPO_ROOT_DIR}/external")
set(JAVA_INTEROP_SRC_PATH "${EXTERNAL_DIR}/Java.Interop/src/java-interop")
set(SHARED_SOURCES_DIR "${REPO_ROOT_DIR}/src/native/shared")
set(TRACING_SOURCES_DIR "${REPO_ROOT_DIR}/src/native/tracing")
#
# Include directories
#
include_directories(SYSTEM ${CMAKE_SYSROOT}/usr/include/c++/v1/)
include_directories(SYSTEM "${NET_RUNTIME_DIR}/native/include/mono-2.0")
include_directories("${JAVA_INTEROP_SRC_PATH}")
include_directories("${SHARED_SOURCES_DIR}")
include_directories("${TRACING_SOURCES_DIR}")

#
# Compiler defines
#
add_compile_definitions(XA_VERSION="${XA_VERSION}")
add_compile_definitions(_REENTRANT)
add_compile_definitions(PLATFORM_ANDROID)

if(DEBUG_BUILD AND NOT DISABLE_DEBUG)
add_compile_definitions(DEBUG)
endif()

if(ANDROID_ABI MATCHES "^(arm64-v8a|x86_64)")
add_compile_definitions(ANDROID64)
endif()

if (ANDROID_NDK_MAJOR LESS 20)
add_compile_definitions(__ANDROID_API_Q__=29)
endif()

#
# Shared sources
#
set(XA_SHARED_SOURCES
${SHARED_SOURCES_DIR}/helpers.cc
${SHARED_SOURCES_DIR}/new_delete.cc
)
3 changes: 2 additions & 1 deletion build-tools/cmake/xa_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ function(xa_common_prepare)
-fstack-protector-strong
-fstrict-return
-fno-strict-aliasing
-ffunction-sections
-fno-function-sections
-fno-data-sections
-funswitch-loops
-Wa,-noexecstack
-fPIC
Expand Down
7 changes: 7 additions & 0 deletions build-tools/cmake/xa_preamble.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12)

#
# Read product version
#
file(STRINGS "../../Directory.Build.props" XA_PRODUCT_VERSION_XML REGEX "^[ \t]*<ProductVersion>(.*)</ProductVersion>")
string(REGEX REPLACE "^[ \t]*<ProductVersion>(.*)</ProductVersion>" "\\1" XA_VERSION "${XA_PRODUCT_VERSION_XML}")
2 changes: 2 additions & 0 deletions build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ projects that use the Microsoft.Android framework in .NET 6+.
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.debug.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.release.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-debug-app-helper.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmarshal-methods-tracing.a" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-native-tracing.so" />
<FrameworkListFileClass Include="@(_AndroidRuntimePackAssemblies->'%(Filename)%(Extension)')" Profile="Android" />
<FrameworkListFileClass Include="@(_AndroidRuntimePackAssets->'%(Filename)%(Extension)')" Profile="Android" />
</ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,20 @@
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)ManifestOverlays\Timing.xml" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\liblog.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\liblog.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\liblog.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\liblog.so" />
</ItemGroup>
<ItemGroup>
<_MSBuildTargetsSrcFiles Include="$(MSBuildTargetsSrcDir)\Xamarin.Android.AvailableItems.targets" />
Expand Down
6 changes: 6 additions & 0 deletions build-tools/scripts/cmake-android.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_CmakeAndroidFlags>--debug-output -GNinja -DCMAKE_MAKE_PROGRAM="$(NinjaPath)" -DXA_BUILD_CONFIGURATION=$(Configuration) -DXA_LIB_TOP_DIR=$(MicrosoftAndroidSdkOutDir) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DMONO_PATH="$(MonoSourceFullPath)" -DANDROID_STL="none" -DANDROID_CPP_FEATURES="no-rtti no-exceptions" -DANDROID_TOOLCHAIN=clang -DCMAKE_TOOLCHAIN_FILE="$(AndroidNdkDirectory)/build/cmake/android.toolchain.cmake" -DANDROID_NDK=$(AndroidNdkDirectory)</_CmakeAndroidFlags>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static class KnownProperties
public const string JavaInteropFullPath = "JavaInteropFullPath";
public const string JavaSdkDirectory = "JavaSdkDirectory";
public const string JdkIncludePath = "JdkIncludePath";
public const string LibUnwindGeneratedHeadersFullPath = nameof (LibUnwindGeneratedHeadersFullPath);
public const string LibUnwindSourceFullPath = nameof (LibUnwindSourceFullPath);
public const string LibZipSourceFullPath = "LibZipSourceFullPath";
public const string ManagedRuntime = "ManagedRuntime";
public const string MicrosoftAndroidSdkOutDir = "MicrosoftAndroidSdkOutDir";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Xamarin.Android.Prepare
properties.Add (KnownProperties.JavaInteropFullPath, StripQuotes (@"@JavaInteropFullPath@"));
properties.Add (KnownProperties.JavaSdkDirectory, StripQuotes (@"@JavaSdkDirectory@"));
properties.Add (KnownProperties.JdkIncludePath, StripQuotes (@"@JdkIncludePath@"));
properties.Add (KnownProperties.LibUnwindGeneratedHeadersFullPath, StripQuotes (@"@LibUnwindGeneratedHeadersFullPath@"));
properties.Add (KnownProperties.LibUnwindSourceFullPath, StripQuotes (@"@LibUnwindSourceFullPath"));
properties.Add (KnownProperties.LibZipSourceFullPath, StripQuotes (@"@LibZipSourceFullPath@"));
properties.Add (KnownProperties.ManagedRuntime, StripQuotes (@"@ManagedRuntime@"));
properties.Add (KnownProperties.MicrosoftAndroidSdkOutDir, StripQuotes (@"@MicrosoftAndroidSdkOutDir@"));
Expand Down
1 change: 1 addition & 0 deletions build-tools/xaprepare/xaprepare/xaprepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Replacement Include="@JavaInteropFullPath@=$(JavaInteropFullPath)" />
<Replacement Include="@JavaSdkDirectory@=$(JavaSdkDirectory)" />
<Replacement Include="@JdkIncludePath@=$(JavaIncludePath)" />
<Replacement Include="@LibUnwindSourceFullPath@=$(LibUnwindSourceFullPath)" />
<Replacement Include="@LibZipSourceFullPath@=$(LibZipSourceFullPath)" />
<Replacement Include="@ManagedRuntime@=$(ManagedRuntime)" />
<Replacement Include="@MicrosoftAndroidSdkOutDir@=$(MicrosoftAndroidSdkOutDir)" />
Expand Down
1 change: 1 addition & 0 deletions external/libunwind
Submodule libunwind added at 9cc4d9
Loading
Loading