Skip to content

Commit dedbd6d

Browse files
committed
[RISC-V] Adapt the build scripts for standard Ubuntu cross build container because there is no CBL Mariner container for RISC-V. Besides, it's more convenient to work in one docker only.
1 parent 88a1883 commit dedbd6d

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

build-coredistools.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ CMakeOSXArchitectures=
1717
LLVMTargetsToBuild="AArch64;ARM;X86"
1818

1919
# Figure out which `strip` to use. Prefer `llvm-strip` if it is available.
20-
# `llvm-strip` is available in CBL-Mariner container; `strip` is available on macOS.
21-
StripTool=$(command -v llvm-strip)
20+
# `llvm-strip` is available in CBL-Mariner container,
21+
# `llvm-strip-<version>` is available on standard cross build Ubuntu container,
22+
# `strip` is available on macOS.
23+
StripTool=$(command -v llvm-strip{,-{20..15}} strip | head -n 1)
2224
if [ -z "$StripTool" ]; then
23-
StripTool=$(command -v strip)
24-
if [ -z "$StripTool" ]; then
25-
echo "Strip tool not found"
26-
exit 1
27-
fi
25+
echo "Strip tool not found"
26+
exit 1
2827
fi
2928

3029
TblGenTool=$(command -v llvm-tblgen)
@@ -33,13 +32,14 @@ if [ -z "$TblGenTool" ]; then
3332
exit 1
3433
fi
3534

36-
C_COMPILER=$(command -v clang)
35+
# Take first match from: clang clang-20 clang-19 .. clang-15
36+
C_COMPILER=$(command -v clang{,-{20..15}} | head -n 1)
3737
if [ -z "$C_COMPILER" ]; then
3838
echo "C compiler not found"
3939
# Keep going in case cmake can find one?
4040
fi
4141

42-
CXX_COMPILER=$(command -v clang++)
42+
CXX_COMPILER=$(command -v clang++{,-{20..15}} | head -n 1)
4343
if [ -z "$CXX_COMPILER" ]; then
4444
echo "C++ compiler not found"
4545
# Keep going in case cmake can find one?
@@ -83,6 +83,7 @@ case "$TargetOSArchitecture" in
8383
CMakeCrossCompiling=ON
8484
LLVMHostTriple=riscv64-linux-gnu
8585
LLVMTargetsToBuild="RISCV"
86+
EnsureCrossRootfsDirectoryExists
8687
;;
8788

8889
osx-arm64)

build-tblgen.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ fi
7070

7171
pushd "$BinariesDirectory"
7272

73+
# Take first match from: clang clang-20 clang-19 .. clang-15
74+
C_COMPILER=$(command -v clang{,-{20..15}} | head -n 1)
75+
CXX_COMPILER=$(command -v clang++{,-{20..15}} | head -n 1)
76+
7377
if [ -z "$CrossRootfsDirectory" ]; then
7478
BUILD_FLAGS=""
7579
cmake \
7680
-G "Unix Makefiles" \
7781
-DCMAKE_BUILD_TYPE=Release \
7882
-DCMAKE_CROSSCOMPILING=$CMakeCrossCompiling \
79-
-DCMAKE_C_COMPILER=$(command -v clang) \
80-
-DCMAKE_CXX_COMPILER=$(command -v clang++) \
83+
-DCMAKE_C_COMPILER=$C_COMPILER \
84+
-DCMAKE_CXX_COMPILER=$CXX_COMPILER \
8185
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
8286
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
8387
-DCMAKE_INSTALL_PREFIX=$RootDirectory \
@@ -92,8 +96,8 @@ elif [ $CrossBuildUsingMariner -eq 1 ]; then
9296
-DCMAKE_BUILD_TYPE=Release \
9397
-DCMAKE_INSTALL_PREFIX=$RootDirectory \
9498
-DCMAKE_CROSSCOMPILING=$CMakeCrossCompiling \
95-
-DCMAKE_C_COMPILER=$(command -v clang) \
96-
-DCMAKE_CXX_COMPILER=$(command -v clang++) \
99+
-DCMAKE_C_COMPILER=$C_COMPILER \
100+
-DCMAKE_CXX_COMPILER=$CXX_COMPILER \
97101
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
98102
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
99103
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
@@ -109,8 +113,8 @@ else
109113
-DCMAKE_BUILD_TYPE=Release \
110114
-DCMAKE_INSTALL_PREFIX=$RootDirectory \
111115
-DCMAKE_CROSSCOMPILING=$CMakeCrossCompiling \
112-
-DCMAKE_C_COMPILER=$(command -v clang) \
113-
-DCMAKE_CXX_COMPILER=$(command -v clang++) \
116+
-DCMAKE_C_COMPILER=$C_COMPILER \
117+
-DCMAKE_CXX_COMPILER=$CXX_COMPILER \
114118
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
115119
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
116120
-DCMAKE_INCLUDE_PATH=$CrossRootfsDirectory/usr/include \

doc/building-coredistools.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,17 @@ sudo tdnf install -y ncurses-compat
105105
export PATH=$(pwd)/bin:$PATH
106106
./build-coredistools.sh linux-arm /crossrootfs/arm
107107
```
108+
109+
8. Build `libcoredistools.so` for Linux riscv64 under Docker:
110+
There is no CBL Mariner container for RISC-V so use the standard Ubuntu cross build container used for e.g. dotnet/runtime.
111+
```
112+
docker run -it --rm --entrypoint /bin/bash -v ~/git/jitutils:/opt/code -w /opt/code mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-22.04-cross-riscv64
113+
apt install libtinfo5
114+
115+
# If you haven't built llvm-tblgen in step 5, you can do so in the same docker (pass "/" as crossrootfs).
116+
./build-tblgen.sh linux-x64 /
117+
118+
# Now, the main course
119+
export PATH=$(pwd)/bin:$PATH
120+
./build-coredistools.sh linux-riscv64 /crossrootfs/riscv64
121+
```

0 commit comments

Comments
 (0)