Skip to content

Commit ec3b102

Browse files
authored
Merge pull request #613 from hvdijk/update-cross
Simplify toolchain files, update cross build docs.
2 parents 2b65cba + f96dc2d commit ec3b102

File tree

5 files changed

+141
-398
lines changed

5 files changed

+141
-398
lines changed

doc/developer-guide.md

Lines changed: 120 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ cmake llvm -G"Visual Studio 16 2019 Win64" ^
462462
-Bbuild-x86_64 ^
463463
-DCMAKE_BUILD_TYPE=Release ^
464464
-DCMAKE_INSTALL_PREFIX=%CD%\build-x86_64\install ^
465-
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" ^
465+
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;RISCV" ^
466466
-DLLVM_ENABLE_PROJECTS=clang ^
467467
```
468468

@@ -741,7 +741,7 @@ Note that this is not part of the regular testing of OCK, but should work.
741741
All CMake cross-compilation configurations set `CMAKE_TOOLCHAIN_FILE` to inform
742742
CMake how to compile for the target architecture, this sets up various CMake
743743
variables which specify the locations of executables such as the C and C++
744-
compilers, assembler, linker, target file system root, etc.
744+
compilers, target file system root, etc.
745745

746746
The examples provided should be sufficient to get up and running, for more fine
747747
grained control of how to compile the oneAPI Construction Kit consult the list of
@@ -761,32 +761,27 @@ LLVMNativeInstall=${CMAKE_INSTALL_PREFIX}
761761

762762
### Cross-compiling LLVM
763763

764-
#### Cross-compiling LLVM from Upstream
765-
766764
To cross-compile LLVM the appropriate CMake toolchain file from the oneAPI
767-
Construction Kit repository is required, the path to this will be specified
768-
by the `$ONEAPI_CON_KIT` variable in the following examples.
765+
Construction Kit repository may be used; the path to this repository will be
766+
specified by the `$ONEAPI_CON_KIT` variable in the following examples.
769767

770-
##### Cross-compiling LLVM for Arm from Upstream
768+
##### Cross-compiling LLVM for ARM
771769

772-
For cross-compilation targeting Arm only the `ARM` target back end is enabled.
773-
Run the following command to configure an LLVM build targeting Arm from the root
774-
of the repository.
770+
For cross-compilation targeting ARM, only the `ARM` target back end needs to be
771+
enabled. Run the following command to configure an LLVM build targeting ARM from
772+
the root of the LLVM repository.
775773

776774
```sh
777-
cmake . -GNinja \
775+
cmake llvm -GNinja \
778776
-Bbuild-arm \
779777
-DCMAKE_BUILD_TYPE=Release \
780-
-DCMAKE_TOOLCHAIN_FILE=$ONEAPI_CON_KIT/scripts/toolchains/arm-toolchain.cmake \
778+
-DCMAKE_TOOLCHAIN_FILE=$ONEAPI_CON_KIT/platform/arm-linux/arm-toolchain.cmake \
781779
-DCMAKE_INSTALL_PREFIX=$PWD/build-arm/install \
782-
-DLLVM_TARGET_ARCH=ARM \
780+
-DLLVM_HOST_TRIPLE=arm-unknown-linux-gnueabihf \
783781
-DLLVM_TARGETS_TO_BUILD=ARM \
784-
-DLLVM_HOST_TRIPLE=arm-unknown-linux-gnu \
785-
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-unknown-linux-gnu \
786-
-DLLVM_ENABLE_ZLIB=OFF \
787-
-DLLVM_ENABLE_ZSTD=OFF \
788-
-DLLVM_TABLEGEN=$LLVMNativeInstall/bin/llvm-tblgen \
789-
-DCLANG_TABLEGEN=$LLVMNativeBuild/bin/clang-tblgen
782+
-DLLVM_ENABLE_PROJECTS=clang \
783+
-DLLVM_BUILD_LLVM_DYLIB=ON \
784+
-DLLVM_LINK_LLVM_DYLIB=ON
790785
```
791786

792787
Now the build directory is configured, build the `install` target.
@@ -795,26 +790,23 @@ Now the build directory is configured, build the `install` target.
795790
ninja -C build-arm install
796791
```
797792

798-
##### Cross-compiling LLVM for AArch64 from Upstream
793+
##### Cross-compiling LLVM for AArch64
799794

800-
For cross-compilation targeting AArch64 only the `AArch64` target back end is
801-
enabled. Run the following command to configure an LLVM build targeting Arm from
802-
the root of the repository.
795+
For cross-compilation targeting AArch64 only the `AArch64` target back end needs
796+
to be enabled. Run the following command to configure an LLVM build targeting
797+
AArch64 from the root of the repository.
803798

804799
```sh
805-
cmake . -GNinja \
800+
cmake llvm -GNinja \
806801
-Bbuild-aarch64 \
807802
-DCMAKE_BUILD_TYPE=Release \
808-
-DCMAKE_TOOLCHAIN_FILE=$ONEAPI_CON_KIT/scripts/toolchains/aarch64-toolchain.cmake \
803+
-DCMAKE_TOOLCHAIN_FILE=$ONEAPI_CON_KIT/platform/arm-linux/aarch64-toolchain.cmake \
809804
-DCMAKE_INSTALL_PREFIX=$PWD/build-aarch64/install \
810-
-DLLVM_TARGET_ARCH=AArch64 \
811-
-DLLVM_TARGETS_TO_BUILD=AArch64 \
812805
-DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu \
813-
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-unknown-linux-gnu \
814-
-DLLVM_ENABLE_ZLIB=OFF \
815-
-DLLVM_ENABLE_ZSTD=OFF \
816-
-DLLVM_TABLEGEN=$LLVMNativeInstall/bin/llvm-tblgen \
817-
-DCLANG_TABLEGEN=$LLVMNativeBuild/bin/clang-tblgen
806+
-DLLVM_TARGETS_TO_BUILD=AArch64 \
807+
-DLLVM_ENABLE_PROJECTS=clang \
808+
-DLLVM_BUILD_LLVM_DYLIB=ON \
809+
-DLLVM_LINK_LLVM_DYLIB=ON
818810
```
819811

820812
Now the build directory is configured, build the `install` target.
@@ -823,21 +815,70 @@ Now the build directory is configured, build the `install` target.
823815
ninja -C build-aarch64 install
824816
```
825817

818+
##### Cross-compiling LLVM for RISC-V
819+
820+
For cross-compilation targeting RISC-V only the `RISCV` target back end needs
821+
to be enabled. Run the following command to configure an LLVM build targeting
822+
AArch64 from the root of the repository.
823+
824+
```sh
825+
cmake llvm -GNinja \
826+
-Bbuild-riscv64 \
827+
-DCMAKE_BUILD_TYPE=Release \
828+
-DCMAKE_TOOLCHAIN_FILE=$ONEAPI_CON_KIT/platform/riscv64-linux/riscv64-gcc-toolchain.cmake \
829+
-DCMAKE_INSTALL_PREFIX=$PWD/build-riscv64/install \
830+
-DLLVM_HOST_TRIPLE=riscv64-unknown-linux-gnu \
831+
-DLLVM_TARGETS_TO_BUILD=RISCV \
832+
-DLLVM_ENABLE_PROJECTS=clang \
833+
-DLLVM_BUILD_LLVM_DYLIB=ON \
834+
-DLLVM_LINK_LLVM_DYLIB=ON
835+
```
836+
837+
Now the build directory is configured, build the `install` target.
838+
839+
```sh
840+
ninja -C build-riscv64 install
841+
```
842+
826843
### Cross-compiling the oneAPI Construction Kit
827844

828-
Cross-compiling the oneAPI Construction Kit requires a LLVM install to link
845+
Cross-compiling the oneAPI Construction Kit requires an LLVM install to link
829846
against, follow the [LLVM guide](#cross-compiling-llvm) to build a suitable
830847
install, the `$LLVMInstall` variable specifies the path to this install.
831848

832849
oneAPI Construction Kit uses tools from an LLVM install during the build
833-
process. For a native x86_64 build no additional install is required, although
834-
build times can be [improved](#compiling-debug-oneapi-construction-kit-on-linux)
835-
by doing so. For cross-compilation a native LLVM install is also required, the
836-
`$LLVMNativeInstall` variable specifies the path to this install.
850+
process. For this, an additional native LLVM install is usually required, and
851+
even when not required, build times can be improved by providing one.
852+
853+
#### Compiling the native LLVM
854+
855+
For building the native LLVM, no specific target back end needs to be enabled.
856+
However, it is important for the `LLVM_ENABLE_ZLIB` and `LLVM_ENABLE_ZSTD`
857+
settings to not be enabled unless the cross-compiled LLVM is also built with
858+
support for this.
859+
860+
```sh
861+
cmake llvm -GNinja \
862+
-Bbuild-native \
863+
-DCMAKE_BUILD_TYPE=Release \
864+
-DCMAKE_INSTALL_PREFIX=$PWD/build-native/install \
865+
-DLLVM_TARGETS_TO_BUILD= \
866+
-DLLVM_ENABLE_PROJECTS=clang \
867+
-DLLVM_ENABLE_ZLIB=OFF \
868+
-DLLVM_ENABLE_ZSTD=OFF \
869+
-DLLVM_BUILD_LLVM_DYLIB=ON \
870+
-DLLVM_LINK_LLVM_DYLIB=ON
871+
```
872+
873+
Now the build directory is configured, build the `install` target.
874+
875+
```sh
876+
ninja -C build-native install
877+
```
837878

838-
#### Cross-compiling the oneAPI Construction Kit for Arm
879+
#### Cross-compiling the oneAPI Construction Kit for ARM
839880

840-
Configure an Arm cross-compile build using the following command.
881+
Configure an ARM cross-compile build using the following command.
841882

842883
```sh
843884
cmake . -GNinja \
@@ -855,10 +896,9 @@ Now the build directory is configured, build the `install` target.
855896
ninja -C build-arm install
856897
```
857898

858-
If `qemu-arm` is installed on the system `arm-toolchain.cmake` will
859-
automatically detect it and set the `CMAKE_CROSSCOMPILING_EMULATOR` variable,
860-
the oneAPI Construction Kit uses this to enable emulated testing using the
861-
`check` target.
899+
The provided `arm-toolchain.cmake` will set the `CMAKE_CROSSCOMPILING_EMULATOR`
900+
variable to `qemu-armhf`; if available, the oneAPI Construction Kit can use this
901+
to enable emulated testing using the `check` target.
862902

863903
```sh
864904
ninja -C build-arm check
@@ -884,15 +924,49 @@ Now the build directory is configured, build the `install` target.
884924
ninja -C build-aarch64 install
885925
```
886926

887-
If `qemu-aarch64` is installed on the system `aarch64-toolchain.cmake` will
888-
automatically detect it and set the `CMAKE_CROSSCOMPILING_EMULATOR` variable,
889-
the oneAPI Construction Kit uses this to enable emulated testing using the
927+
The provided `aarch64-toolchain.cmake` will set the
928+
`CMAKE_CROSSCOMPILING_EMULATOR` variable to `qemu-aarch64`; if available, the
929+
oneAPI Construction Kit can use this to enable emulated testing using the
890930
`check` target.
891931

892932
```sh
893933
ninja -C build-aarch64 check
894934
```
895935

936+
#### Cross-compiling the oneAPI Construction Kit for RISC-V
937+
938+
Configure a RISC-V 64-bit cross-compile build using the following command.
939+
940+
```sh
941+
cmake . -GNinja \
942+
-Bbuild-riscv64 \
943+
-DCMAKE_BUILD_TYPE=Release \
944+
-DCMAKE_TOOLCHAIN_FILE=$PWD/platform/riscv64-linux/riscv64-gcc-toolchain.cmake \
945+
-DCMAKE_INSTALL_PREFIX=$PWD/build-riscv64/install \
946+
-DCA_LLVM_INSTALL_DIR=$LLVMInstall \
947+
-DCA_BUILTINS_TOOLS_DIR=$LLVMNativeInstall/bin
948+
```
949+
950+
This uses the [default platform settings for `riscv64-linux-gnu`](https://wiki.debian.org/RISC-V#Hardware_baseline_and_ABI_choice)
951+
which is `RV64GC`. To enable additional extensions by default, such as RVV, the
952+
`CA_HOST_TARGET_RISCV64_FEATURES` variable may additionally be set in the above
953+
command.
954+
955+
Now the build directory is configured, build the `install` target.
956+
957+
```sh
958+
ninja -C build-riscv64 install
959+
```
960+
961+
The provided `riscv64-gcc-toolchain.cmake` will set the
962+
`CMAKE_CROSSCOMPILING_EMULATOR` variable to `qemu-riscv64`; if available, the
963+
oneAPI Construction Kit can use this to enable emulated testing using the
964+
`check` target.
965+
966+
```sh
967+
ninja -C build-riscv64 check
968+
```
969+
896970
#### Cross-compiling the oneAPI Construction Kit for Windows with the MinGW toolchain
897971

898972
oneAPI Construction Kit for Windows can be built on Linux using MinGW. This

platform/arm-linux/aarch64-toolchain.cmake

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,107 +14,15 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1616

17-
set(CMAKE_SYSTEM_VERSION 1)
17+
set(CMAKE_SYSTEM_NAME Linux)
18+
set(CMAKE_SYSTEM_PROCESSOR aarch64)
19+
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc CACHE STRING "")
20+
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++ CACHE STRING "")
21+
set(PKG_CONFIG_EXECUTABLE aarch64-linux-gnu-pkg-config)
1822

19-
set(TRIPLE "aarch64-linux-gnu")
20-
set(TOOLCHAIN_ROOT /usr)
21-
22-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
23-
set(TOOL_OS_SUFFIX .exe)
24-
else()
25-
set(TOOL_OS_SUFFIX)
26-
endif()
27-
28-
set(CMAKE_SYSTEM_NAME Linux
29-
CACHE STRING "operating system" FORCE)
30-
set(CMAKE_SYSTEM_PROCESSOR aarch64
31-
CACHE STRING "processor architecture" FORCE)
32-
33-
find_program(CMAKE_C_COMPILER NAMES
34-
"${TRIPLE}-gcc${TOOL_OS_SUFFIX}"
35-
"${TRIPLE}-gcc-14${TOOL_OS_SUFFIX}"
36-
"${TRIPLE}-gcc-13${TOOL_OS_SUFFIX}"
37-
"${TRIPLE}-gcc-12${TOOL_OS_SUFFIX}"
38-
"${TRIPLE}-gcc-11${TOOL_OS_SUFFIX}"
39-
"${TRIPLE}-gcc-10${TOOL_OS_SUFFIX}"
40-
"${TRIPLE}-gcc-9${TOOL_OS_SUFFIX}"
41-
"${TRIPLE}-gcc-8${TOOL_OS_SUFFIX}"
42-
"${TRIPLE}-gcc-7${TOOL_OS_SUFFIX}"
43-
"${TRIPLE}-gcc-6${TOOL_OS_SUFFIX}"
44-
"${TRIPLE}-gcc-5${TOOL_OS_SUFFIX}"
45-
"${TRIPLE}-gcc-4.9${TOOL_OS_SUFFIX}"
46-
"${TRIPLE}-gcc-4.8${TOOL_OS_SUFFIX}"
47-
"gcc-${TRIPLE}${TOOL_OS_SUFFIX}"
48-
"gcc-14-${TRIPLE}${TOOL_OS_SUFFIX}"
49-
"gcc-13-${TRIPLE}${TOOL_OS_SUFFIX}"
50-
"gcc-12-${TRIPLE}${TOOL_OS_SUFFIX}"
51-
"gcc-11-${TRIPLE}${TOOL_OS_SUFFIX}"
52-
"gcc-10-${TRIPLE}${TOOL_OS_SUFFIX}"
53-
"gcc-9-${TRIPLE}${TOOL_OS_SUFFIX}"
54-
"gcc-8-${TRIPLE}${TOOL_OS_SUFFIX}"
55-
"gcc-7-${TRIPLE}${TOOL_OS_SUFFIX}"
56-
"gcc-6-${TRIPLE}${TOOL_OS_SUFFIX}"
57-
"gcc-5-${TRIPLE}${TOOL_OS_SUFFIX}"
58-
"gcc-4.9-${TRIPLE}${TOOL_OS_SUFFIX}"
59-
"gcc-4.8-${TRIPLE}${TOOL_OS_SUFFIX}"
60-
PATHS "${TOOLCHAIN_ROOT}/bin/" DOC "gcc")
61-
62-
find_program(CMAKE_CXX_COMPILER NAMES
63-
"${TRIPLE}-g++${TOOL_OS_SUFFIX}"
64-
"${TRIPLE}-g++-14${TOOL_OS_SUFFIX}"
65-
"${TRIPLE}-g++-13${TOOL_OS_SUFFIX}"
66-
"${TRIPLE}-g++-12${TOOL_OS_SUFFIX}"
67-
"${TRIPLE}-g++-11${TOOL_OS_SUFFIX}"
68-
"${TRIPLE}-g++-10${TOOL_OS_SUFFIX}"
69-
"${TRIPLE}-g++-9${TOOL_OS_SUFFIX}"
70-
"${TRIPLE}-g++-8${TOOL_OS_SUFFIX}"
71-
"${TRIPLE}-g++-7${TOOL_OS_SUFFIX}"
72-
"${TRIPLE}-g++-6${TOOL_OS_SUFFIX}"
73-
"${TRIPLE}-g++-5${TOOL_OS_SUFFIX}"
74-
"${TRIPLE}-g++-4.9${TOOL_OS_SUFFIX}"
75-
"${TRIPLE}-g++-4.8${TOOL_OS_SUFFIX}"
76-
"g++-${TRIPLE}${TOOL_OS_SUFFIX}"
77-
"g++-14-${TRIPLE}${TOOL_OS_SUFFIX}"
78-
"g++-13-${TRIPLE}${TOOL_OS_SUFFIX}"
79-
"g++-12-${TRIPLE}${TOOL_OS_SUFFIX}"
80-
"g++-11-${TRIPLE}${TOOL_OS_SUFFIX}"
81-
"g++-10-${TRIPLE}${TOOL_OS_SUFFIX}"
82-
"g++-9-${TRIPLE}${TOOL_OS_SUFFIX}"
83-
"g++-8-${TRIPLE}${TOOL_OS_SUFFIX}"
84-
"g++-7-${TRIPLE}${TOOL_OS_SUFFIX}"
85-
"g++-6-${TRIPLE}${TOOL_OS_SUFFIX}"
86-
"g++-5-${TRIPLE}${TOOL_OS_SUFFIX}"
87-
"g++-4.9-${TRIPLE}${TOOL_OS_SUFFIX}"
88-
"g++-4.8-${TRIPLE}${TOOL_OS_SUFFIX}"
89-
PATHS "${TOOLCHAIN_ROOT}/bin/" DOC "g++")
90-
91-
set(CMAKE_AR "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ar${TOOL_OS_SUFFIX}"
92-
CACHE PATH "archive" FORCE)
93-
set(CMAKE_LINKER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ld${TOOL_OS_SUFFIX}"
94-
CACHE PATH "linker" FORCE)
95-
set(CMAKE_NM "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-nm${TOOL_OS_SUFFIX}"
96-
CACHE PATH "nm" FORCE)
97-
set(CMAKE_OBJCOPY "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-objcopy${TOOL_OS_SUFFIX}"
98-
CACHE PATH "objcopy" FORCE)
99-
set(CMAKE_OBJDUMP "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-objdump${TOOL_OS_SUFFIX}"
100-
CACHE PATH "objdump" FORCE)
101-
set(CMAKE_STRIP "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-strip${TOOL_OS_SUFFIX}"
102-
CACHE PATH "strip" FORCE)
103-
set(CMAKE_RANLIB "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ranlib${TOOL_OS_SUFFIX}"
104-
CACHE PATH "ranlib" FORCE)
105-
106-
set(CMAKE_FIND_ROOT_PATH /usr/${TRIPLE})
23+
set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu)
10724
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
10825
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
10926
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
11027

111-
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> \
112-
<LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> ${LINKER_LIBS}"
113-
CACHE STRING "Linker command line" FORCE)
114-
115-
find_program(QEMU_AARCH64_EXECUTABLE qemu-aarch64)
116-
if(NOT QEMU_AARCH64_EXECUTABLE MATCHES NOTFOUND)
117-
set(CMAKE_CROSSCOMPILING_EMULATOR
118-
${QEMU_AARCH64_EXECUTABLE} -L ${CMAKE_FIND_ROOT_PATH}
119-
CACHE STRING "qemu" FORCE)
120-
endif()
28+
set(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64 -L ${CMAKE_FIND_ROOT_PATH} CACHE STRING "")

0 commit comments

Comments
 (0)