Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1dc0361

Browse files
committed
Merge pull request #6845 from leemgs/crossbuild-documentation
Documentation: cross build of corefx for arm
2 parents 0f9c6c2 + 565e6f7 commit 1dc0361

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Cross Compilation for ARM on Linux
2+
==================================
3+
4+
Through cross compilation, on Linux it is possible to build CoreFX for arm or arm64.
5+
It is very similar to the cross compilation procedure of CoreCLR.
6+
7+
Requirements
8+
------------
9+
10+
You need a Debian based host and the following packages needs to be installed:
11+
12+
lgs@ubuntu ~/git/corefx/ $ sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
13+
14+
In addition, to cross compile CoreFX the binutils for the target are required. So for arm you need:
15+
16+
lgs@ubuntu ~/git/corefx/ $ sudo apt-get install binutils-arm-linux-gnueabihf
17+
18+
and conversely for arm64:
19+
20+
lgs@ubuntu ~/git/corefx/ $ sudo apt-get install binutils-aarch64-linux-gnu
21+
22+
23+
Generating the rootfs
24+
---------------------
25+
The `cross\build-rootfs.sh` script can be used to download the files needed for cross compilation. It will generate an Ubuntu 14.04 rootfs as this is what CoreFX targets.
26+
27+
Usage: build-rootfs.sh [BuildArch]
28+
BuildArch can be: arm, arm64
29+
30+
The `build-rootfs.sh` script must be run as root as it has to make some symlinks to the system. It will by default generate the rootfs in `cross\rootfs\<BuildArch>` however this can be changed by setting the `ROOTFS_DIR` environment variable.
31+
32+
For example, to generate an arm rootfs:
33+
34+
lgs@ubuntu ~/git/corefx/ $ sudo ./cross/build-rootfs.sh arm
35+
36+
and if you wanted to generate the rootfs elsewhere:
37+
38+
lgs@ubuntu ~/git/corefx/ $ sudo ROOTFS_DIR=/home/lgs/corefx-cross/arm ./build-rootfs.sh arm
39+
40+
41+
Cross compiling for native CoreFX
42+
---------------------------------
43+
Once the rootfs has been generated, it will be possible to cross compile CoreFX. If `ROOTFS_DIR` was set when generating the rootfs, then it must also be set when running `build.sh`.
44+
45+
So, without `ROOTFS_DIR`:
46+
47+
lgs@ubuntu ~/git/corefx/ $ ./build.sh native arm debug verbose clean cross
48+
49+
And with:
50+
51+
lgs@ubuntu ~/git/corefx/ $ ROOTFS_DIR=/home/lgs/corefx-cross/arm ./build.sh native arm debug verbose clean cross
52+
53+
As usual the generated binaries will be found in `bin/BuildOS.BuildArch.BuildType/Native` as following:
54+
55+
lgs@ubuntu ~/git/corefx/ ls -al ./bin/Linux.arm.Debug/Native
56+
total 988
57+
drwxrwxr-x 2 lgs lgs 4096 3 6 18:33 .
58+
drwxrwxr-x 3 lgs lgs 4096 3 6 18:33 ..
59+
-rw-r--r-- 1 lgs lgs 19797 3 6 18:33 System.IO.Compression.Native.so
60+
-rw-r--r-- 1 lgs lgs 428232 3 6 18:33 System.Native.a
61+
-rw-r--r-- 1 lgs lgs 228279 3 6 18:33 System.Native.so
62+
-rw-r--r-- 1 lgs lgs 53089 3 6 18:33 System.Net.Http.Native.so
63+
-rw-r--r-- 1 lgs lgs 266720 3 6 18:33 System.Security.Cryptography.Native.so
64+
lgs@ubuntu ~/git/corefx/ file ./bin/Linux.arm.Debug/Native/System.Native.so
65+
./bin/Linux.arm.Debug/Native/System.Native.so:
66+
ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV),
67+
dynamically linked, BuildID[sha1]=fac50f1bd657c1759f0ad6cf5951511ddf252e67, not stripped
68+
69+
70+
Compiling for managed CoreFX
71+
============================
72+
In order to generate managed CoreFX for ARM, we can compile CoreFX with native build because managed CoreFX is architecture independent.
73+
74+
Many of the managed binaries are OS-independent, System.Linq.dll. However, some are OS-specific, System.IO.FileSystem.dll, with different builds for Windows vs Linux.
75+
76+
lgs@ubuntu ~/git/corefx/ $ ./build.sh managed debug clean verbose
77+
78+
The output is at bin/<BuildOS>.AnyCPU.Debug.
79+
80+
lgs@ubuntu ~/git/corefx/ $ ls -al ./bin
81+
drwxrwxr-x 17 lgs lgs 4096 3 6 21:00 .
82+
drwxrwxr-x 10 lgs lgs 4096 3 12 15:04 ..
83+
drwx------ 98 lgs lgs 4096 3 6 21:36 AnyOS.AnyCPU.Debug
84+
drwx------ 98 lgs lgs 4096 3 6 19:40 AnyOS.AnyCPU.Release
85+
drwx------ 284 lgs lgs 20480 3 6 22:30 Linux.AnyCPU.Debug
86+
drwx------ 284 lgs lgs 20480 3 6 20:45 Linux.AnyCPU.Release
87+
drwx------ 33 lgs lgs 4096 3 6 21:33 Windows_NT.AnyCPU.Debug
88+
drwx------ 33 lgs lgs 4096 3 6 19:36 Windows_NT.AnyCPU.Release
89+
90+

0 commit comments

Comments
 (0)