Building .net core on an unsupported Linux platform

Introduction

I need to a product that I own from Windows to Amazon Linux. However, Amazon Linux is not a supported platform for running .net core by Microsoft. Although there is a Amazon Linux 2 image with .net core 2.1 preinstalled and it is possible to install the CentOS version of .net core on Amazon Linux 1, I went on a journey to build and test .net core on Amazon Linux to have confidence that my product will not hit a wall.

.net core require LLVM 3.9 to build. However, we can only get LLVM 3.6.3 from the yum repository. So we have to build LLVM 3.9.LLVM 3.9 requires Cmake 3.11 or later, but we can only get Cmake 2.8.12 from the yum repository. So we have to start from building CMake.

Building CMake

The procedure to build CMake can be found in https://askubuntu.com/questions/355565/how-do-i-install-the-latest-version-of-cmake-from-the-command-line.

Here is what I did:

sudo yum groupinstall "Development Tools"

Sudo yum install swig python27-devel libedit-devel

version=3.11
build=1
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build.tar.gz
tar -xzvf cmake-$version.$build.tar.gz
cd cmake-$version.$build/

./bootstrap

make -j4
sudo make install

Building CLang and LVVM

With CMake installed, we can build LLVM. My procedure of building Clang and LLVM is similar to the procedure in https://github.com/dotnet/coreclr/blob/master/Documentation/building/buildinglldb.md.

Please also refer to https://releases.llvm.org/3.9.1/docs/CMake.html for additional information.

cd $HOME
git clone http://llvm.org/git/llvm.git
cd $HOME/llvm
git checkout release_39
cd $HOME/llvm/tools
git clone http://llvm.org/git/clang.git
git clone http://llvm.org/git/lldb.git
cd $HOME/llvm/tools/clang
git checkout release_39
cd $HOME/llvm/tools/lldb
git checkout release_39

Before we start building, we need to patch LLVM source code for Amazon Linux triplet.Otherwise LLVM cannot find the c++ compiler on Amazon Linux.

To patch, find file ./tools/clang/lib/Driver/ToolChains.cpp, find an array that looks like:

"x86_64-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu",
      "x86_64-redhat-linux6E", "x86_64-redhat-linux", "x86_64-suse-linux",
      "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", "x86_64-slackware-linux",
      "x86_64-linux-android", "x86_64-unknown-linux"

Append "x86_64-amazon-linux" to the last line.

Similar, append "i686-amazon-linux" to "i686-montavista-linux", "i686-linux-android", "i586-linux-gnu"

Now we can build:

mkdir -p $HOME/build/release   
cd $HOME/build/release
cmake -DCMAKE_BUILD_TYPE=release $HOME/llvm

make –j4

sudo make install

Building CoreCLR and CoreFx

With Clang/LLVM 3.9 installed, we can now build CoreCLR and CoreFx.


https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md

We need to install the prerequisites first:

sudo yum install lttng-ust-devel libunwind-devel gettext libicu-devel libcurl-devel openssl-devel krb5-devel libuuid-devel libcxx

sudo yum install redhat-lsb-core cppcheck sloccount

mkdir ~/git

git clone https://github.com/dotnet/coreclr.git
git clone https://github.com/dotnet/corefx.git

Go to each directory and check out a version, for eample:

git checkout tags/v2.0.7

Now just follow https://github.com/dotnet/coreclr/blob/master/Documentation/building/linux-instructions.md to the build.

./clean.sh -all
./build.sh -RuntimeOS=linux
./build-tests.sh

Also look at: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md and

https://github.com/dotnet/corefx/issues/22509

Conclusions

With the steps above, I was able to build and test .net core on Amazon Linux 1 and 2.

Note that .net core requires GLIBC_2.14 to run. To find the version of GLIBC on your version of Amazon Linux, run:

strings /lib64/libc.so.6 | grep GLIBC

If you don’t see 2.14 on the list, .net core will not run. try “sudo yum update” to see if you can update to a later version of GLIBC.

Additionally, since many newer programming languages were build on LLVM, this exercise also allow us to build other languages that require newer version of LLVM than the version in the yum repository.

1 Comment

  • Since .NET Core 2.0 there is a generic Linux build available with RID linux-x64 - it will run on any Linux system that has glibc 2.14+

Comments have been disabled for this content.