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

Fix macOS host + linux-bionic-arm64 target cross-compile build #9

Conversation

jonpryor
Copy link
Contributor

Context: dotnet/runtime#101727

Previously, trying to use dotnet publish from a macOS host would result in obscure build failures, e.g.

% dotnet publish -c Release
…
clang : error : invalid linker name in argument '-fuse-ld=lld'

Apply the workaround from dotnet/runtime#101727 to workaround this. The $(ANDROID_NDK_HOME) environment variable requuired:

# we're all xamarin-android devs here, right? ;-)
% export ANDROID_NDK_HOME=$HOME/android-toolchain/ndk
% dotnet publish -c Release
# Creates DotNet/bin/Release/net8.0/linux-bionic-arm64/publish/libdotnet.so

Context: dotnet/runtime#101727

Previously, trying to use `dotnet publish` from a macOS host would
result in obscure build failures, e.g.

	% dotnet publish -c Release
	…
	clang : error : invalid linker name in argument '-fuse-ld=lld'

Apply the workaround from dotnet/runtime#101727 to workaround this.
The `$(ANDROID_NDK_HOME)` environment variable requuired:

	# we're all xamarin-android devs here, right? ;-)
	% export ANDROID_NDK_HOME=$HOME/android-toolchain/ndk
	% dotnet publish -c Release
	# Creates DotNet/bin/Release/net8.0/linux-bionic-arm64/publish/libdotnet.so
@jonathanpeppers jonathanpeppers merged commit a2fd74c into jonathanpeppers:main Apr 30, 2024
1 check passed
@jonpryor
Copy link
Contributor Author

jonpryor commented May 1, 2024

lol, so

While libdotnet.so builds on macOS, the resulting binary is not usable as-is. Trying to use the resulting libdotnet.so on-device results in:

E AndroidRuntime: java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/~~4oPnKwAB0bVVIZs6TwgFWg==/com.jonathanpeppers.nativeaot-ZfYIxey30jLo8YEB5UVaPw==/lib/arm64/libnativeaot.so": dlopen failed: libra
ry "libc++_shared.so" not found: needed by /data/app/~~4oPnKwAB0bVVIZs6TwgFWg==/com.jonathanpeppers.nativeaot-ZfYIxey30jLo8YEB5UVaPw==/lib/arm64/libdotnet.so in namespace clns-4

This is because libdotnet.so has a library reference to libc++_shared.so, which doesn't exist.

Fortunately this is "easy" to solve: copy libc++_shared.so from the NDK into your project:

% mkdir  Native/app/src/main/jniLibs/arm64-v8a
% cp $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so \
    Native/app/src/main/jniLibs/arm64-v8a

Build, install, run…

% ./gradlew assembleRelease
% adb install app/build/outputs/apk/release/app-release.apk
% adb shell am start com.jonathanpeppers.nativeaot/android.app.NativeActivity

…and it crashes.

I think the NativeAOT + macOS host + linux-bionic toolchain is broken:

F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
F DEBUG   : Build fingerprint: 'google/raven/raven:14/AP1A.240305.019.A1/11445699:user/release-keys'
F DEBUG   : Revision: 'MP1.0'
F DEBUG   : ABI: 'arm64'
F DEBUG   : Timestamp: 2024-05-01 11:01:48.710687354-0400
F DEBUG   : Process uptime: 1s
F DEBUG   : Cmdline: com.jonathanpeppers.nativeaot
F DEBUG   : pid: 10516, tid: 10516, name: ppers.nativeaot  >>> com.jonathanpeppers.nativeaot <<<
F DEBUG   : uid: 10371
F DEBUG   : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000006
F DEBUG   : Cause: null pointer dereference
F DEBUG   :     x0  0000000000000006  x1  0000007fda6f3340  x2  0000007eb6852980  x3  0000007fda6ef330
F DEBUG   :     x4  0000007eb6852a00  x5  0000000000000004  x6  0000000001414d4c  x7  0000007eb6852004
F DEBUG   :     x8  0000007eb6852980  x9  0000000000000006  x10 000000000000000f  x11 757274736e6f6320
F DEBUG   :     x12 676e696c6c61632c  x13 000180000045dfd0  x14 0000000000018510  x15 0000000000000000
F DEBUG   :     x16 0000007eb7b3d680  x17 0000007eb7a5fb00  x18 0000007eb6d90000  x19 0000007fda6f3340
F DEBUG   :     x20 0000007eb6852980  x21 0000000000000006  x22 0000007eb7b4b000  x23 0000007eb67c9e70
F DEBUG   :     x24 0000007fda6f0518  x25 0000000000000022  x26 0000007eb6843c00  x27 0000007fda6f0500
F DEBUG   :     x28 0000007eb7b49000  x29 0000007fda6ef2e0
F DEBUG   :     lr  0000007b57aebc80  sp  0000007fda6ef2c0  pc  0000007b57aebcb0  pst 0000000080001000
F DEBUG   : 1 total frames
F DEBUG   : backtrace:
F DEBUG   :       #00 pc 00000000000c1cb0  /data/app/~~y5LQdnO4d1iwNk2Z6I4Jpg==/com.jonathanpeppers.nativeaot-HJbM4Jw2CNRiWe4-Rn2IxA==/lib/arm64/libdotnet.so (BuildId: 21c56035e6fc411dab6ab373715ba35e82c0fb5f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants