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

how to build release version of coreclr for android? #33237

Open
gemSender opened this issue Mar 5, 2020 · 38 comments
Open

how to build release version of coreclr for android? #33237

gemSender opened this issue Mar 5, 2020 · 38 comments

Comments

@gemSender
Copy link

I append “cmakeargs -DBUILD_TYPE=Release" at the end of build command and still got debug version with huge size of "libcoreclr.so"

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Infrastructure-coreclr untriaged New issue has not been triaged by the area owner labels Mar 5, 2020
@janvorli
Copy link
Member

janvorli commented Mar 5, 2020

Which .sh script are you using for the build? You don't need to use -DBUILD_TYPE=Release, there is an option of the build script that sets that. If you build it using the build.sh in the src/coreclr, then you just add Release to the command line. If you build it using the build.sh in the root, the option is -runtimeConfiguration Release, but I think that it has been recently changed to be the default.
There is also a -stripsymbols option to strip the symbols from the binaries.

@jkotas
Copy link
Member

jkotas commented Mar 5, 2020

cc @am11

@am11
Copy link
Member

am11 commented Mar 5, 2020

@gemSender, we are in process of updating the Android builds. The PRs are under review at the moment. If you could try to build runtime repo (excluding mono for now) with the PR branch following these instructions: #32800 (comment), and give us some feedback that would be help us validating the changes. :)

@am11
Copy link
Member

am11 commented Mar 5, 2020

For release build, you can add --configuration Release to the build.sh command.
(I have just rebased my branch with dotnet/master, also trying out a fresh build)

@gemSender
Copy link
Author

Which .sh script are you using for the build? You don't need to use -DBUILD_TYPE=Release, there is an option of the build script that sets that. If you build it using the build.sh in the src/coreclr, then you just add Release to the command line. If you build it using the build.sh in the root, the option is -runtimeConfiguration Release, but I think that it has been recently changed to be the default.
There is also a -stripsymbols option to strip the symbols from the binaries.

I'v tried this but got new error messages when building v2.2.8 released . Then I tried v3.0.3 and got blocked by "liblttng-ust-devel building test" in "src/pal/src/configure.cmake" even if i installed liblttng-ust-devel for ndk 。 I'm trying to build the branch as @am11 mentioned.

@gemSender
Copy link
Author

For release build, you can add --configuration Release to the build.sh command.
(I have just rebased my branch with dotnet/master, also trying out a fresh build)

i tried this but got cmake configure error blew:

CMake Error at /home/razor/coreclr_runtime_src/eng/native/configuretools.cmake:66 (message):
objcopy not found
Call Stack (most recent call first):
CMakeLists.txt:6 (include)

-- Configuring incomplete, errors occurred!
See also "/home/razor/coreclr_runtime_src/artifacts/obj/android.28-arm64.Release/CMakeFiles/CMakeOutput.log".

/home/razor/coreclr_runtime_src/src/installer/corehost/build.proj(43,5): error MSB3073: The command "/home/razor/coreclr_runtime_src/src/installer/corehost/build.sh Release arm64 -apphostver "5.0.0-dev" -hostver "5.0.0-dev" -fxrver "5.0.0-dev" -policyver "5.0.0-dev" -commithash "0065943756c868a7603d9c0d4d0dc46fc1ad72ee" -cross" exited with code 1.

then I enter command "find .tools/android-rootfs/android-ndk-r21 | grep objcopy"

.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/i686-linux-android/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/aarch64-linux-android-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/x86_64-linux-android-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/i686-linux-android-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/arm-linux-androideabi-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/arm-linux-androideabi/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/x86_64-4.9/prebuilt/linux-x86_64/x86_64-linux-android/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/x86_64-4.9/prebuilt/linux-x86_64/share/man/man1/x86_64-linux-android-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/x86-4.9/prebuilt/linux-x86_64/i686-linux-android/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/x86-4.9/prebuilt/linux-x86_64/share/man/man1/i686-linux-android-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/share/man/man1/arm-linux-androideabi-objcopy.1
.tools/android-rootfs/android-ndk-r21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objcopy
.tools/android-rootfs/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/share/man/man1/aarch64-linux-android-objcopy.1

enter command "whereis objcopy"

objcopy: /usr/bin/objcopy /usr/share/man/man1/objcopy.1.gz

@am11
Copy link
Member

am11 commented Mar 6, 2020

I was able to build coreclr with my PR branch (on Ubuntu bionic host) with the following command yesterday:

ROOTFS_DIR=$(realpath .tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory coreclr --configuration Release

git hash is tip of my PR branch:

$ git rev-parse HEAD
0065943756c868a7603d9c0d4d0dc46fc1ad72ee

$ git status
On branch feature/android-build
Your branch is up to date with 'origin/feature/android-build'.

if it all looks the same, could you try cleaning the repo with git clean -xdf, followed by eng/common/cross/build-android-rootfs.sh then execute above command. Also please show this part of the logs (where native build commences):

  Commencing CoreCLR Repo build
  __DistroRid: android.28-arm64
  __RuntimeId: android.28-arm64
  Setting up directories for build
  Checking prerequisites...
  /usr/bin/cmake
  Restoring the OptimizationData package
    Restore completed in 1.42 sec for /datadrive/projects/runtime4/src/coreclr/src/.nuget/optdata/optdata.csproj.
  Commencing build of "CoreCLR component" for Linux.arm64.Release in /datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release
    Restore completed in 782.43 ms for /datadrive/projects/runtime4/eng/empty.csproj.
  Invoking "/datadrive/projects/runtime4/eng/native/gen-buildsys.sh" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release" arm64 clang "" "" Release ""  -DCLR_ENG_NATIVE_DIR="/datadrive/projects/runtime4/eng/native" -DCLR_CMAKE_PGO_INSTRUMENT=0 -DCLR_CMAKE_OPTDATA_PATH= -DCLR_CMAKE_PGO_OPTIMIZE=1 -DCLR_REPO_ROOT_DIR="/datadrive/projects/runtime4" -DSTRIP_SYMBOLS=true
  loading initial cache file /datadrive/projects/runtime4/src/coreclr/tryrun.cmake
  -- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  -- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++

@gemSender
Copy link
Author

I was able to build coreclr with my PR branch (on Ubuntu bionic host) with the following command yesterday:

ROOTFS_DIR=$(realpath .tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory coreclr --configuration Release

git hash is tip of my PR branch:

$ git rev-parse HEAD
0065943756c868a7603d9c0d4d0dc46fc1ad72ee

$ git status
On branch feature/android-build
Your branch is up to date with 'origin/feature/android-build'.

if it all looks the same, could you try cleaning the repo with git clean -xdf, followed by eng/common/cross/build-android-rootfs.sh then execute above command. Also please show this part of the logs (where native build commences):

  Commencing CoreCLR Repo build
  __DistroRid: android.28-arm64
  __RuntimeId: android.28-arm64
  Setting up directories for build
  Checking prerequisites...
  /usr/bin/cmake
  Restoring the OptimizationData package
    Restore completed in 1.42 sec for /datadrive/projects/runtime4/src/coreclr/src/.nuget/optdata/optdata.csproj.
  Commencing build of "CoreCLR component" for Linux.arm64.Release in /datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release
    Restore completed in 782.43 ms for /datadrive/projects/runtime4/eng/empty.csproj.
  Invoking "/datadrive/projects/runtime4/eng/native/gen-buildsys.sh" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release" arm64 clang "" "" Release ""  -DCLR_ENG_NATIVE_DIR="/datadrive/projects/runtime4/eng/native" -DCLR_CMAKE_PGO_INSTRUMENT=0 -DCLR_CMAKE_OPTDATA_PATH= -DCLR_CMAKE_PGO_OPTIMIZE=1 -DCLR_REPO_ROOT_DIR="/datadrive/projects/runtime4" -DSTRIP_SYMBOLS=true
  loading initial cache file /datadrive/projects/runtime4/src/coreclr/tryrun.cmake
  -- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  -- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++

I built coreclr native library successfully with the branch you shared , Thank you for your reply !

@gemSender gemSender reopened this Mar 9, 2020
@gemSender
Copy link
Author

gemSender commented Mar 9, 2020

I was able to build coreclr with my PR branch (on Ubuntu bionic host) with the following command yesterday:

ROOTFS_DIR=$(realpath .tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory coreclr --configuration Release

git hash is tip of my PR branch:

$ git rev-parse HEAD
0065943756c868a7603d9c0d4d0dc46fc1ad72ee

$ git status
On branch feature/android-build
Your branch is up to date with 'origin/feature/android-build'.

if it all looks the same, could you try cleaning the repo with git clean -xdf, followed by eng/common/cross/build-android-rootfs.sh then execute above command. Also please show this part of the logs (where native build commences):

  Commencing CoreCLR Repo build
  __DistroRid: android.28-arm64
  __RuntimeId: android.28-arm64
  Setting up directories for build
  Checking prerequisites...
  /usr/bin/cmake
  Restoring the OptimizationData package
    Restore completed in 1.42 sec for /datadrive/projects/runtime4/src/coreclr/src/.nuget/optdata/optdata.csproj.
  Commencing build of "CoreCLR component" for Linux.arm64.Release in /datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release
    Restore completed in 782.43 ms for /datadrive/projects/runtime4/eng/empty.csproj.
  Invoking "/datadrive/projects/runtime4/eng/native/gen-buildsys.sh" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release" arm64 clang "" "" Release ""  -DCLR_ENG_NATIVE_DIR="/datadrive/projects/runtime4/eng/native" -DCLR_CMAKE_PGO_INSTRUMENT=0 -DCLR_CMAKE_OPTDATA_PATH= -DCLR_CMAKE_PGO_OPTIMIZE=1 -DCLR_REPO_ROOT_DIR="/datadrive/projects/runtime4" -DSTRIP_SYMBOLS=true
  loading initial cache file /datadrive/projects/runtime4/src/coreclr/tryrun.cmake
  -- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  -- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++

I tried to host coreclr on my Android app, but when I loaded libcoreclr.so with the dlopen function, an error occurred. I called the dlerror function, and the error it returned was "libgcc_s.so.1 not found"。 Is the error relate with linking glibc library while compiling coreclr ?

@am11
Copy link
Member

am11 commented Mar 9, 2020

I think we would need to copy the whole set of dependencies (or use termux to install them via adb shell), could you also check what ldd libcoreclr.so shows and acquire all of them on device?

BTW, I read your previous comments and thanks a lot for the feedback. I have already opened two PRs to fix the issues you mentioned. It encouraged me to test the build in a docker container (isolated environment) to see what assumptions went wrong from my previous tests. dotnet/arcade#5003, #33342. Still missing a patch (which i have locally ready and tested in docker, need some polishing) for the original Android PR. will take some cycles to smooth things out on the build side.

@gemSender
Copy link
Author

gemSender commented Mar 10, 2020

I think we would need to copy the whole set of dependencies (or use termux to install them via adb shell), could you also check what ldd libcoreclr.so shows and acquire all of them on device?

BTW, I read your previous comments and thanks a lot for the feedback. I have already opened two PRs to fix the issues you mentioned. It encouraged me to test the build in a docker container (isolated environment) to see what assumptions went wrong from my previous tests. dotnet/arcade#5003, #33342. Still missing a patch (which i have locally ready and tested in docker, need some polishing) for the original Android PR. will take some cycles to smooth things out on the build side.

It seems that the compile parameter "-fPIC" should be added for android, otherwise when the target api level is greater than 21, the function System.loadLibrary will fail to be called .

@am11
Copy link
Member

am11 commented Mar 10, 2020

It compiles all native components of product using -fPIC:

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
(exception being WebAssembly). You can check it by grepping the artifacts/obj directory

grep -lR \-fPIC artifacts/obj # from runtime repo root (after the compilation)

@gemSender
Copy link
Author

It compiles all native components of product using -fPIC:

  runtime/eng/native/configureplatform.cmake


     Line 303
  in
  13e7f19





    
      
       set(CMAKE_POSITION_INDEPENDENT_CODE ON) 

(exception being WebAssembly). You can check it by grepping the artifacts/obj directory
grep -lR -fPIC artifacts/obj # from runtime repo root (after the compilation)

Is it possible to host coreclr on an non-rooted Android device ? The process got crashes when I call the function "coreclr_initialize".

Fatal signal 31 (SIGSYS), code 1 (SYS_SECCOMP) in tid 24480 (UnityMain), pid 24456 (m.XRoom.Coreclr)

image

@am11
Copy link
Member

am11 commented Mar 10, 2020

Seems like membarrier system call is not whitelisted under https://android.googlesource.com/platform/bionic.git/+/master/libc/SYSCALLS.TXT, which InitializeFlushProcessWriteBuffers(..) makes here:

int mask = membarrier(MEMBARRIER_CMD_QUERY, 0);
. See the discussion: #12605 (comment). Maybe you can workaround it by means of LD_PRELOAD to find out if there is any other blocker?

@am11
Copy link
Member

am11 commented Mar 10, 2020

Something like:

echo "int membarrier(int cmd, int flags) { return 0; }" | gcc -xc -shared -o libcoreclr-33237-workaround.so

LD_PRELOAD=$(pwd)/libcoreclr-33237-workaround.so ./myApp

@gemSender
Copy link
Author

gemSender commented Mar 11, 2020

Something like:

echo "int membarrier(int cmd, int flags) { return 0; }" | gcc -xc -shared -o libcoreclr-33237-workaround.so

LD_PRELOAD=$(pwd)/libcoreclr-33237-workaround.so ./myApp

When I replaced membarrier with an empty function, the coreclr_initialize function no longer crashed, but it returned an error code of 0x80004005. I tried to debug the startup code by printing logs and found the EEStartupHelper function (located at "runtime/src/coreclr /src/ vm/ ceemain.cpp ") called the InitializeDebugger , this function throws an exception, causing g_EEStartupStatus to be set to E_FAIL.

I tried to disable the macro DEBUGGING_SUPPORTED by modifying the file "src/coreclr/ clrdefinitions.cmake", but got some compilation errors.

@am11
Copy link
Member

am11 commented Mar 11, 2020

Some optional features are not tested in the CI environments, where they are always enabled.
I am fixing FEATURE_EVENT_TRACE in the ongoing pull request and realized that there is quite a large matrix which is not covered by CI. I will look into disabling DEBUGGING_SUPPORTED.

@am11
Copy link
Member

am11 commented Mar 19, 2020

The first batch of changes are merged @gemSender, here is the docker file which I have used during the development:

src: https://gist.github.com/am11/a68aaab2cb803f90a78c3956910ea218

$ docker build --tag dotnet-runtime-android-arm64 - <<'EOF'

FROM        ubuntu:bionic

RUN         apt update && \
            apt install -y git wget unzip libicu-dev clang-9 liblttng-ust-dev locales

RUN         echo en_US.UTF-8 UTF-8 >> /etc/locale.gen && \
            locale-gen && \
            update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

ENV         LANG en_US.UTF-8
ENV         LANGUAGE en_US.UTF-8
ENV         LC_ALL en_US.UTF-8

ENV         CMAKE_INSTALL_SCRIPT_URL https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5-Linux-x86_64.sh
RUN         wget --show-progress --progress=bar:force:noscroll $CMAKE_INSTALL_SCRIPT_URL; sh cmake-3.16.5-Linux-x86_64.sh --skip-license

ARG         gfork=dotnet
ARG         gbranch=master

RUN         git clone https://github.com/$gfork/runtime --branch $gbranch --single-branch --depth 1

WORKDIR     runtime

RUN         ./eng/common/cross/build-android-rootfs.sh arm64

RUN         ROOTFS_DIR=$(realpath /runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory coreclr --configuration Release
RUN         ROOTFS_DIR=$(realpath /runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory libraries --configuration Release
RUN         ROOTFS_DIR=$(realpath /runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory installer --configuration Release

EOF

(for other fork or branch use, e.g. --build-arg gfork=am11 --build-arg gbranch=feature/android-build in first line before -)

some managed components in installer are failing during the crossgen due to wrong RID resolution, tracked by #33069.

I have not yet tried the device testing, or tried to make your issue somehow reproduce in emulator. Do you have any script for reproducible environment (preferably with emulator and NDK installed)?

@CircuitRCAY
Copy link

Might want to change --subsetCategory to --subset.

RUN         ROOTFS_DIR=$(realpath ~/runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subset coreclr --configuration Release
RUN         ROOTFS_DIR=$(realpath ~/runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subset libraries --configuration Release
RUN         ROOTFS_DIR=$(realpath ~/runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subset installer --configuration Release

@am11
Copy link
Member

am11 commented Jun 18, 2020

Yup, at the time Dockerfile was written, there were subset and subsetCategory options, later the latter one was squashed into the former. :)

@CircuitRCAY
Copy link

CircuitRCAY commented Jun 18, 2020

That's weird

circuitrcay@innovare:~/runtime$ ROOTFS_DIR=$(realpath ~/runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --configuration Release
__DistroRid: android.28-arm64
__RuntimeId: android.28-arm64
  Determining projects to restore...
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003: The specified task executable "sh" could not be run. System.IO.IOException: The operation is not allowed on non-connected sockets.
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Net.Sockets.NetworkStream..ctor(Socket socket, FileAccess access, Boolean ownsSocket)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Diagnostics.Process.OpenStream(Int32 fd, FileAccess access)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Diagnostics.Process.Start()
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at Microsoft.Build.Tasks.Exec.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.Execute()

Build FAILED.

/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003: The specified task executable "sh" could not be run. System.IO.IOException: The operation is not allowed on non-connected sockets.
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Net.Sockets.NetworkStream..ctor(Socket socket, FileAccess access, Boolean ownsSocket)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Diagnostics.Process.OpenStream(Int32 fd, FileAccess access)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at System.Diagnostics.Process.Start()
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at Microsoft.Build.Tasks.Exec.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
/home/circuitrcay/.nuget/packages/microsoft.dotnet.arcade.sdk/5.0.0-beta.20309.1/tools/Tools.proj(43,5): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.Execute()
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.83
Build failed (exit code '1').

Note: apparently leaving out -s/--subset builds the whole repo.

@am11
Copy link
Member

am11 commented Jun 19, 2020

91f1418 was the last hash which I tested with the aforementioned Dockerfile.

At the time mono bits in this repo did not enabled Android cross-compilation, which is why I split the build steps. Now mono subset also build, so we don't need to specify the subsets.

It would be nice if we can add the missing bits (related to CoreCLR) in official build docker (currently used for mono+libs+installer in CI without coreclr), so we can enable this:

DOTNET_DOCKER_TAG=ubuntu-18.04-android-20200612003336-e2c3f83
docker run --rm -v /datadrive/projects/runtime:/runtime -w /runtime \
    mcr.microsoft.com/dotnet-buildtools/prereqs:$DOTNET_DOCKER_TAG  \
    ./build.sh

(versions are available at https://github.com/dotnet/versions/blob/master/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-master.json)

@gemSender gemSender reopened this Aug 13, 2020
@jashook jashook removed the untriaged New issue has not been triaged by the area owner label Aug 20, 2020
@jashook jashook added this to the Future milestone Aug 20, 2020
@ericstj
Copy link
Member

ericstj commented Sep 8, 2020

@CircuitRCAY it looks like you're hitting #40727

@CircuitRCAY
Copy link

CircuitRCAY commented Sep 10, 2020

I'm building coreclr without Docker or Debian (or derivs), and I'm no longer hitting #40727.

Building this under Arch Linux is somewhat trivial: sudo pacman -S llvm lttng-ust dpkg, but I am facing a problem:

Repo successfully built.
  Product binaries are available at /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug
  Commencing Crossgenning System.Private.CoreLib
  __DistroRid: android.28-arm64
  __RuntimeId: android.28-arm64
  Setting up directories for build
  Generating native image of System.Private.CoreLib.dll for Linux.arm64.Debug. Logging to "/home/circuit/dotnet/runtime/artifacts/log/Debug/CrossgenCoreLib_Linux.arm64.Debug.log".
  /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/x64/crossgen /Platform_Assemblies_Paths /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/IL  /out /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/System.Private.CoreLib.dll /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/IL/System.Private.CoreLib.dll
  Generating symbol file for System.Private.CoreLib.dll
  /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/x64/crossgen /Platform_Assemblies_Paths /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug /CreatePerfMap /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/System.Private.CoreLib.dll
  Native System.Private.CoreLib generated.
  Product binaries are available at /home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug
  ILCompiler.DependencyAnalysisFramework -> /home/circuit/dotnet/runtime/artifacts/bin/ILCompiler.DependencyAnalysisFramework/arm64/Debug/ILCompiler.DependencyAnalysisFramework.dll
  ILCompiler.TypeSystem.ReadyToRun -> /home/circuit/dotnet/runtime/artifacts/bin/ILCompiler.TypeSystem.ReadyToRun/arm64/Debug/ILCompiler.TypeSystem.ReadyToRun.dll
  ILCompiler.ReadyToRun -> /home/circuit/dotnet/runtime/artifacts/bin/ILCompiler.ReadyToRun/arm64/Debug/ILCompiler.ReadyToRun.dll
/home/circuit/dotnet/runtime/.dotnet/sdk/5.0.100-preview.8.20362.3/Microsoft.Common.CurrentVersion.targets(4651,5): error MSB3030: Could not copy the file "/home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/libjitinterface_arm64.so" because it was not found. [/home/circuit/dotnet/runtime/src/coreclr/src/tools/aot/crossgen2/crossgen2.csproj]

Build FAILED.

/home/circuit/dotnet/runtime/.dotnet/sdk/5.0.100-preview.8.20362.3/Microsoft.Common.CurrentVersion.targets(4651,5): error MSB3030: Could not copy the file "/home/circuit/dotnet/runtime/artifacts/bin/coreclr/Linux.arm64.Debug/libjitinterface_arm64.so" because it was not found. [/home/circuit/dotnet/runtime/src/coreclr/src/tools/aot/crossgen2/crossgen2.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:01:14.05
Build failed (exit code '1').

I would have to build the experimental CoreRT to get access to that libjitinterface method, and build.sh doesn't even have the experimental CoreRT as a subset. I could try building the new runtime seperately, but I don't know. It looks like the AOT component is not building, and there's a jitinterface method on the current stable runtime.

Full log: https://hastebin.com/umucohabaj.sql

@CircuitRCAY
Copy link

CircuitRCAY commented Sep 10, 2020

Still finding issues building coreclr and the installer: https://asciinema.org/a/oMMVVJH1GO1iXY8dPll1zgACX

@nathanpovo
Copy link

I am trying to build the runtime for android (following the directions in https://github.com/dotnet/runtime/tree/a89dcada9eb18e7a370b82027c256c7e16d9e7be/docs/workflow/building/coreclr/android.md). However, the scripts seems to be outdated; there are references to scripts that no longer exist or scripts that have changed names.

The instructions mention the script coreclr/cross/init-android-rootfs.sh, which I managed to find at https://github.com/dotnet/runtime/blob/055e26fd1594e583b678703b15a792eb879d75b9/eng/common/cross/build-android-rootfs.sh .

The build-android-rootfs.sh script executes succesfully up until the commands

echo "Now to build coreclr, libraries and installers; run:"
echo ROOTFS_DIR=\$\(realpath $__ToolchainDir/sysroot\) ./build.sh --cross --arch $__BuildArch \
--subsetCategory coreclr
echo ROOTFS_DIR=\$\(realpath $__ToolchainDir/sysroot\) ./build.sh --cross --arch $__BuildArch \
--subsetCategory libraries
echo ROOTFS_DIR=\$\(realpath $__ToolchainDir/sysroot\) ./build.sh --cross --arch $__BuildArch \
--subsetCategory installer

which I edited to be executed and updated to

ROOTFS_DIR=\$\($__ToolchainDir/.tools/android-rootfs/android-ndk-r21/sysroot\) ./build.sh --cross --arch $__BuildArch --subset clr
ROOTFS_DIR=\$\($__ToolchainDir/.tools/android-rootfs/android-ndk-r21/sysroot\) ./build.sh --cross --arch $__BuildArch --subset libs
ROOTFS_DIR=\$\($__ToolchainDir/.tools/android-rootfs/android-ndk-r21/sysroot\) ./build.sh --cross --arch $__BuildArch --subset installer

which, after calling https://github.com/dotnet/runtime/blob/558d49245b050de4235d7420f06c5f0ddc41b8ed/eng/common/build.sh and https://github.com/dotnet/runtime/blob/b9d26c89e9b789dc36ef630fc1533cf912926cf1/eng/native/init-distro-rid.sh, throws an error in https://github.com/dotnet/runtime/tree/c80b6f42af88205539a88eb1d712779e30162317/eng/common/cross/toolchain.cmake at line 87

include(${CROSS_ROOTFS}/../build/cmake/android.toolchain.cmake)

when it cannot find the file android.toolchain.cmake.

Unfortunately, I am stuck at this point.

Does anyone have some guidance on how to continue or some up-to-date instructions I could follow?

My end goal is to be able to use the dotnet cli to build and run packages in the termux android application.

@janvorli
Copy link
Member

janvorli commented Nov 9, 2020

@nathanpovo I've tried to run the eng/common/cross/build-android-rootfs.sh script for both arm and arm64 and it worked without any changes just fine. I was not following the doc that is really outdated, but looked at the script to see what argument it expected. Here is what I did:
For arm64:

./eng/common/cross/build-android-rootfs.sh arm64

For arm:

./eng/common/cross/build-android-rootfs.sh arm

I've tried to build coreclr using the command the script has printed at the end and it worked too.

@nathanpovo
Copy link

nathanpovo commented Nov 10, 2020

The command

./eng/common/cross/build-android-rootfs.sh arm64

executes successfully.

The issue I am having is with the printed commands.

Running

ROOTFS_DIR=$(realpath /home/nathan/github/dotnet/runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subset clr

I get the following output:

  [ 21%] Linking CXX static library libmdhotdata_dac.a
  [ 21%] Built target mdhotdata_full_obj
  [ 21%] Built target mdhotdata_dac
  [ 21%] Linking CXX static library libmddatasource_dbi.a
  [ 21%] Built target mddatasource_dbi
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/dacdbiimpl.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/dacdbiimplstackwalk.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/dacfn.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/dacdbiimpllocks.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/daccess.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/enummem.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/fntableaccess.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/inspect.cpp.o
  [ 21%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/reimpl.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/request_svr.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/request.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/stack.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/task.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/nidump.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/datatargetadapter.cpp.o
  [ 22%] Building CXX object src/debug/daccess/CMakeFiles/daccess.dir/arm64/primitives.cpp.o
  [ 22%] Linking CXX static library libdaccess.a
  [ 22%] Built target daccess
  make: *** [Makefile:130: all] Error 2
  Failed to build "CoreCLR component".
/home/nathan/github/dotnet/runtime/src/coreclr/runtime.proj(38,5): error MSB3073: The command ""/home/nathan/github/dotnet/runtime/src/coreclr/build-runtime.sh" -arm64 -debug -cross -os Linux" exited with code 2.

Build FAILED.

/home/nathan/github/dotnet/runtime/src/coreclr/runtime.proj(38,5): error MSB3073: The command ""/home/nathan/github/dotnet/runtime/src/coreclr/build-runtime.sh" -arm64 -debug -cross -os Linux" exited with code 2.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:16.02
Build failed (exit code '1').

For some reason, the percentage does not always reach the same amount; if I rerun the command I get higher and higher percentages. I tried running the command multiple times and the highest it got was 25%.

@am11
Copy link
Member

am11 commented Nov 10, 2020

Android with CoreCLR is not an officially supported platform right now; it is a community supported platform. It is 'point in time' kind of support. If we fix it today, there is no guarantee the build will sustain tomorrow as we have evidentially seen in this thread alone; with all the infrastructural as well as the code changes being checked in.

Android with Mono is a an officially supported platform. It has libcoreclr.so build out of src/mono/netcore. It has a CI leg, which runs for every Pull Request.

If you are interested in using .NET with Android, IMO, you can try out Mono option.

If you really want CoreCLR support, then (IMO again), we should create a 'distilled' docker builder image out of these scripts, as done for FreeBSD (dotnet/dotnet-buildtools-prereqs-docker#277) and illumos (dotnet/dotnet-buildtools-prereqs-docker#324), and finally create a downstream CI for those, as done for FreeBSD: https://github.com/wfurt/freebsd-bootstrap-cli/blob/4289056/.cirrus.yml and illumos: https://github.com/am11/runtime/blob/b0c224e/.github/workflows/main.yml. This is to keep up with the daily changes.

@nathanpovo
Copy link

I was mostly experimenting to see if it was possible to build the clr for Android to be able to use it in the Termux app.

However, with all the changes it might be worth waiting for .NET 6.0 to come out which should have official support for building for Android.

Thank you for the quick response, @am11.

@janvorli
Copy link
Member

For me, the clr build command passed 100% for both arm and arm64, so it sounds like some missing build dependency or some kind of a problem with the distro you are building it on. Can you please share the full log from the failed build using a gist?

The fact that the percentages are different each time is expected. The build runs on multiple processors at the same time, so it always manages to build some sub-project before it fails on a problematic one. Since the build is incremental, next time it starts little farther.

@nathanpovo
Copy link

@janvorli where can I find the log?

@janvorli
Copy link
Member

@nathanpovo just cut and paste the console output starting at the build command.

@nathanpovo
Copy link

https://gist.github.com/nathanpovo/927aaabdc5924180d25f32b5351ec75b

I started the build from scratch to show the full log.

@janvorli
Copy link
Member

I've just found what's wrong. I've tried the build again, this time in a different checkout of the runtime repo and it failed the same way as for you. I've then checked the checkout I've tried it in before and it still worked. Looking at the state of that checkout reveals the reason. In the checkout I was trying it before, I had a state from March for some reason (commit bc28cbe at the head). At that time, it worked. Now it does not.

@janvorli
Copy link
Member

I've ran a git bisect to find the change that has broken the Android build. It was this one: #35173 - Port CoreCLR to SunOS
The problem is a failure to find an ICU include:

  In file included from /home/janvorli/git/runtime4/src/libraries/Native/Unix/System.Globalization.Native/pal_casing.c:9:
  /home/janvorli/git/runtime4/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h:23:10: fatal error: 'unicode/ucurr.h' file not found
  #include <unicode/ucurr.h>

I haven't looked at what in that change has broken it. @am11 do you happen to have any quick ideas?

@am11
Copy link
Member

am11 commented Nov 11, 2020

I've ran a git bisect to find the change that has broken the Android build

Actually I fixed the Android build in February #32800. There are dozens of breaking changes since. I am surprised that git bisect has only found my other PR, while the error @nathanpovo is encountering is:

/home/nathan/github/dotnet/runtime/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h:22:10: fatal error: 'unicode/uclean.h' file not found

and that header was added in:

5c99007#diff-7ede8c5e272d0eff6c61b098c43459717e75840c2b333caee9d5fd0fe5cce81f
(this was not me..)

My previous comment was intended as: unless someone looks after Android (or any other platform for that matter) properly, such build breakages are inevitable.

@janvorli
Copy link
Member

@am11 I completely agree that since we don't test / officially support Android with coreclr, it can break any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

10 participants