Skip to content

Commit f28141e

Browse files
authored
add loongarch64 CI (#975)
1 parent 4ab1626 commit f28141e

File tree

5 files changed

+118
-3
lines changed

5 files changed

+118
-3
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Ubuntu LoongArch64 (GCC 14)
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
jobs:
23+
ubuntu-build:
24+
strategy:
25+
fail-fast: false
26+
runs-on: ubuntu-24.04
27+
steps:
28+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
- name: Setup ENV
30+
run: |
31+
sudo apt-get update -y
32+
sudo apt-get install -y cmake curl ninja-build \
33+
g++-14-loongarch64-linux-gnu \
34+
gcc-14-loongarch64-linux-gnu-base \
35+
gcc-14-loongarch64-linux-gnu
36+
sudo curl -L https://github.com/loongson/build-tools/releases/download/2025.06.06/qemu-loongarch64 --output /usr/local/bin/qemu-loongarch64
37+
sudo chmod +x /usr/local/bin/qemu-loongarch64
38+
- name: Build
39+
run: |
40+
export QEMU_LD_PREFIX="/usr/loongarch64-linux-gnu"
41+
export QEMU_CPU="la464"
42+
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains-dev/loongarch64.cmake \
43+
-DADA_TESTING=ON \
44+
-DADA_USE_SIMDUTF=ON \
45+
-DCMAKE_BUILD_TYPE=Release \
46+
-G Ninja -B build
47+
cmake --build build -j=4
48+
- name: Test
49+
run: |
50+
export QEMU_LD_PREFIX="/usr/loongarch64-linux-gnu"
51+
export QEMU_CPU="la464"
52+
ctest --output-on-failure --test-dir build

cmake/add-cpp-test.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ function(add_cpp_test TEST_NAME)
4141
)
4242
set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE)
4343
else()
44-
add_test(${TEST_NAME} ${TEST_NAME})
44+
if (CMAKE_CROSSCOMPILING_EMULATOR)
45+
add_test(${TEST_NAME} ${CMAKE_CROSSCOMPILING_EMULATOR} ${TEST_NAME})
46+
else()
47+
add_test(${TEST_NAME} ${TEST_NAME})
48+
endif()
4549

4650
# Add to <label>_tests make targets
4751
foreach(label ${ARGS_LABELS})

cmake/toolchains-dev/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# LoongArch64
2+
You can now build and run the LoongArch64 code as needed:
3+
GCC >= 14.1
4+
Binutils >= 2.41
5+
QEMU >= 9.2
6+
7+
Note that the compiler may be named `loongarch64-linux-gnu-g++`, without the `unknown` part.
8+
Please adjust to your system.
9+
10+
```
11+
$ sudo curl -L https://github.com/loongson/build-tools/releases/download/2025.06.06/qemu-loongarch64 --output /opt/qemu-loongarch64
12+
$ sudo chmod +x /opt/qemu-loongarch64
13+
$ export PATH=/opt:$PATH
14+
15+
$ export QEMU_LD_PREFIX="/usr/loongarch64-linux-gnu" # ubuntu 24.04
16+
$ export QEMU_CPU="la464"
17+
$ mkdir build && cd build
18+
$ cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains-dev/loongarch64.cmake -DADA_TESTING=ON ../
19+
$ make
20+
```
21+
22+
Running tests with qemu
23+
```
24+
$ make test
25+
or
26+
$ ctest --output-on-failure --test-dir build
27+
or
28+
$ qemu-loongarch64 build/singleheader/cdemo
29+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Usage:
2+
# $ cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains-dev/loongarch64.cmake
3+
set(CMAKE_SYSTEM_NAME Generic)
4+
5+
#set(target loongarch64-unknown-linux-gnu)
6+
set(target loongarch64-linux-gnu)
7+
set(version 14)
8+
set(c_compiler gcc)
9+
set(cxx_compiler g++)
10+
11+
set(CMAKE_C_COMPILER "${target}-${c_compiler}-${version}")
12+
set(CMAKE_CXX_COMPILER "${target}-${cxx_compiler}-${version}")
13+
14+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
15+
16+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
17+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
18+
19+
set(LOONGARCH64_ISA "loongarch64")
20+
set(CMAKE_CROSSCOMPILING_EMULATOR "qemu-${LOONGARCH64_ISA}")
21+
22+
set(CMAKE_CXX_FLAGS "-mlsx")

singleheader/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,19 @@ if (Python3_Interpreter_FOUND)
7878
endif()
7979
target_compile_definitions(demo_no_url_pattern PRIVATE ADA_INCLUDE_URL_PATTERN=0)
8080

81-
add_test(demo_no_url_pattern demo_no_url_pattern)
81+
if (CMAKE_CROSSCOMPILING_EMULATOR)
82+
add_test(demo_no_url_pattern ${CMAKE_CROSSCOMPILING_EMULATOR} demo_no_url_pattern)
83+
else()
84+
add_test(demo_no_url_pattern demo_no_url_pattern)
85+
endif()
8286

8387
add_executable(cdemo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/demo.c>)
8488
target_link_libraries(cdemo ada-singleheader-lib)
85-
add_test(cdemo cdemo)
89+
if (CMAKE_CROSSCOMPILING_EMULATOR)
90+
add_test(cdemo ${CMAKE_CROSSCOMPILING_EMULATOR} cdemo)
91+
else()
92+
add_test(cdemo cdemo)
93+
endif()
8694
endif()
8795
else()
8896
MESSAGE( STATUS "Python not found, we are unable to test amalgamate.py." )

0 commit comments

Comments
 (0)