dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.24k stars 4.73k forks source link

Mono can't cross compile for alpine arm64 #43244

Open safern opened 4 years ago

safern commented 4 years ago

We tried to run the libraries outerloop tests on Mono in alpine arm64 and it failed to build mono with:

checking whether the C compiler works... no
  configure: error: in `/__w/1/s/artifacts/obj/mono/Linux.arm64.Release':
  configure: error: C compiler cannot create executables
  See `config.log' for more details
/__w/1/s/src/mono/mono.proj(755,5): error MSB3073: The command "bash -c 'source /__w/1/s/eng/native/init-compiler.sh arm64 clang && /__w/1/s/src/mono/configure --with-core=only --enable-maintainer-mode --enable-compile-warnings --prefix=/__w/1/s/artifacts/obj/mono/Linux.arm64.Release/out --host=aarch64-linux-gnu --target=aarch64-linux-gnu  CFLAGS="-O2 -g -Wl,--build-id=sha1 --sysroot=/crossrootfs/arm64 --target=aarch64-linux-gnu" CXXFLAGS="-O2 -g -Wl,--build-id=sha1 --sysroot=/crossrootfs/arm64 --target=aarch64-linux-gnu"   LDFLAGS="--sysroot=/crossrootfs/arm64 --target=aarch64-linux-gnu" CCLDFLAGS="-XCClinker --target=aarch64-linux-gnu"   AR="aarch64-linux-gnu-ar" AS="aarch64-linux-gnu-as"    LD="aarch64-linux-gnu-ld"  RANLIB="aarch64-linux-gnu-ranlib"  STRIP="aarch64-linux-gnu-strip"'" exited with code 77.

cc: @akoeplinger @steveisok @directhex

ghost commented 4 years ago

Tagging subscribers to this area: @directhex See info in area-owners.md if you want to be subscribed.

akoeplinger commented 4 years ago

One issue I found while experimenting with this over the weekend is that we pass aarch64-linux-gnu instead of aarch64-linux-musl as the tuple in mono.proj which can be fixed by this:

diff --git a/src/mono/mono.proj b/src/mono/mono.proj
index 66a5ef711f1..3113d2f0105 100644
--- a/src/mono/mono.proj
+++ b/src/mono/mono.proj
@@ -589,8 +589,10 @@

     <!-- ARM Linux cross build options -->
     <PropertyGroup Condition="'$(TargetsAndroid)' != 'true' and '$(MonoCrossDir)' != '' and ('$(TargetArchitecture)' == 'arm' Or '$(TargetArchitecture)' == 'arm64')">
-      <_MonoTuple Condition="'$(TargetArchitecture)' == 'arm64'">aarch64-linux-gnu</_MonoTuple>
-      <_MonoTuple Condition="'$(TargetArchitecture)' == 'arm'">arm-linux-gnueabihf</_MonoTuple>
+      <_MonoTuple Condition="'$(TargetArchitecture)' == 'arm64' and '$(RuntimeOS)' != 'linux-musl'">aarch64-linux-gnu</_MonoTuple>
+      <_MonoTuple Condition="'$(TargetArchitecture)' == 'arm64' and '$(RuntimeOS)' == 'linux-musl'">aarch64-linux-musl</_MonoTuple>
+      <_MonoTuple Condition="'$(TargetArchitecture)' == 'arm' and '$(RuntimeOS)' != 'linux-musl'">arm-linux-gnueabihf</_MonoTuple>
+      <_MonoTuple Condition="'$(TargetArchitecture)' == 'arm' and '$(RuntimeOS)' == 'linux-musl'">arm-linux-musleabihf</_MonoTuple>

       <_MonoRANLIBOption>RANLIB="$(_MonoTuple)-ranlib"</_MonoRANLIBOption>
       <_MonoAROption>AR="$(_MonoTuple)-ar"</_MonoAROption>

It still fails though due to clang using the native linker from the host which results in /usr/bin/ld: unrecognised emulation mode: aarch64linux

CoffeeFlux commented 4 years ago

This is probably the result of issues in our build system rather than infrastructure. More complete build logs would make it much easier to spot the (probably various) issues. Cross compiling is hard :(