Skip to content

Commit b8b8a4c

Browse files
committed
fix cross-compilation issues
1 parent 041418f commit b8b8a4c

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

.github/workflows/_build.yaml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ on:
4545
default: 'OFF'
4646

4747
# Windows-specific
48+
generator:
49+
type: string
50+
required: false
51+
default: 'Ninja'
4852
arch:
4953
type: string
5054
required: false
@@ -130,14 +134,20 @@ jobs:
130134
if: ${{ !inputs.use_run_on_arch }}
131135
shell: bash
132136
run: |
133-
CMAKE_ARGS="-G Ninja -B build"
137+
CMAKE_ARGS="-G \"${{ inputs.generator }}\" -B build"
134138
CMAKE_ARGS="$CMAKE_ARGS -DADA_TESTING=${{ inputs.testing }}"
135139
CMAKE_ARGS="$CMAKE_ARGS -DADA_BENCHMARKS=${{ inputs.benchmarks }}"
136140
CMAKE_ARGS="$CMAKE_ARGS -DBUILD_SHARED_LIBS=${{ inputs.shared }}"
137141
CMAKE_ARGS="$CMAKE_ARGS -DADA_USE_SIMDUTF=${{ inputs.simdutf }}"
138-
if [ -n "${{ inputs.build_type }}" ]; then
142+
# For multi-config generators (Visual Studio), don't set CMAKE_BUILD_TYPE
143+
# For single-config generators (Ninja, Make), set it
144+
if [[ "${{ inputs.generator }}" != *"Visual Studio"* ]] && [ -n "${{ inputs.build_type }}" ]; then
139145
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=${{ inputs.build_type }}"
140146
fi
147+
# Visual Studio generator: add architecture
148+
if [ -n "${{ inputs.arch }}" ]; then
149+
CMAKE_ARGS="$CMAKE_ARGS -A ${{ inputs.arch }}"
150+
fi
141151
if [ -n "${{ inputs.toolchain_file }}" ]; then
142152
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${{ inputs.toolchain_file }}"
143153
fi
@@ -151,14 +161,21 @@ jobs:
151161
export QEMU_CPU="${{ inputs.qemu_cpu }}"
152162
fi
153163
echo "Running: cmake $CMAKE_ARGS"
154-
cmake $CMAKE_ARGS
164+
eval cmake $CMAKE_ARGS
155165
env:
156166
CXX: ${{ inputs.cxx }}
157167
CXXFLAGS: ${{ inputs.cxxflags }}
158168

159169
- name: Build
160170
if: ${{ !inputs.use_run_on_arch }}
161-
run: cmake --build build -j=4
171+
shell: bash
172+
run: |
173+
BUILD_ARGS="--build build -j=4"
174+
# For multi-config generators (Visual Studio), specify config at build time
175+
if [[ "${{ inputs.generator }}" == *"Visual Studio"* ]] && [ -n "${{ inputs.build_type }}" ]; then
176+
BUILD_ARGS="$BUILD_ARGS --config ${{ inputs.build_type }}"
177+
fi
178+
cmake $BUILD_ARGS
162179
163180
- name: Test
164181
if: ${{ !inputs.use_run_on_arch && inputs.run_tests }}
@@ -170,7 +187,12 @@ jobs:
170187
if [ -n "${{ inputs.qemu_cpu }}" ]; then
171188
export QEMU_CPU="${{ inputs.qemu_cpu }}"
172189
fi
173-
ctest --output-on-failure --test-dir build
190+
TEST_ARGS="--output-on-failure --test-dir build"
191+
# For multi-config generators (Visual Studio), specify config at test time
192+
if [[ "${{ inputs.generator }}" == *"Visual Studio"* ]] && [ -n "${{ inputs.build_type }}" ]; then
193+
TEST_ARGS="$TEST_ARGS -C ${{ inputs.build_type }}"
194+
fi
195+
ctest $TEST_ARGS
174196
175197
- name: Run benchmarks
176198
if: ${{ !inputs.use_run_on_arch && inputs.run_benchmarks }}

.github/workflows/windows.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ concurrency:
2121
cancel-in-progress: true
2222

2323
jobs:
24-
# MSVC builds
24+
# MSVC builds (use Visual Studio generator for native MSVC support)
2525
msvc:
2626
strategy:
2727
fail-fast: false
2828
matrix:
2929
include:
30-
- { build_type: Release, shared: OFF, cmake_args: '' }
31-
- { build_type: Debug, shared: OFF, cmake_args: '-DADA_DEVELOPMENT_CHECKS=ON' }
32-
- { build_type: Debug, shared: ON, cmake_args: '-DADA_DEVELOPMENT_CHECKS=ON' }
30+
- { build_type: Release, shared: OFF, arch: x64, cmake_args: '' }
31+
- { build_type: Debug, shared: OFF, arch: x64, cmake_args: '-DADA_DEVELOPMENT_CHECKS=ON' }
32+
- { build_type: Debug, shared: ON, arch: x64, cmake_args: '-DADA_DEVELOPMENT_CHECKS=ON' }
3333
name: msvc (${{ matrix.build_type }}, shared=${{ matrix.shared }})
3434
uses: ./.github/workflows/_build.yaml
3535
with:
3636
runner: windows-2025
37+
generator: 'Visual Studio 17 2022'
38+
arch: ${{ matrix.arch }}
3739
shared: ${{ matrix.shared }}
3840
build_type: ${{ matrix.build_type }}
3941
cmake_args: ${{ matrix.cmake_args }}
@@ -49,4 +51,4 @@ jobs:
4951
with:
5052
runner: windows-2025
5153
build_type: ${{ matrix.build_type }}
52-
cmake_args: '-DADA_DEVELOPMENT_CHECKS=ON -DCMAKE_CXX_COMPILER=clang-cl'
54+
cmake_args: '-DADA_DEVELOPMENT_CHECKS=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl'

tests/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@ endif()
5252
macro(add_gtest_test exe cpp)
5353
add_executable(${exe} ${cpp})
5454
target_link_libraries(${exe} PRIVATE simdjson GTest::gtest_main)
55-
gtest_discover_tests(${exe} PROPERTIES TEST_DISCOVERY_TIMEOUT 600)
55+
# Use PRE_TEST discovery mode for cross-compilation where the test binary
56+
# cannot be executed at build time (e.g., LoongArch via QEMU).
57+
# Use POST_BUILD (default) for native builds to avoid DLL/PATH issues on Windows.
58+
if(CMAKE_CROSSCOMPILING)
59+
set(GTEST_DISCOVERY_MODE PRE_TEST)
60+
else()
61+
set(GTEST_DISCOVERY_MODE POST_BUILD)
62+
endif()
63+
gtest_discover_tests(${exe}
64+
DISCOVERY_MODE ${GTEST_DISCOVERY_MODE}
65+
PROPERTIES TEST_DISCOVERY_TIMEOUT 600
66+
)
5667
set_source_files_properties(${cpp} PROPERTIES SKIP_LINTING ON)
5768
endmacro()
5869

0 commit comments

Comments
 (0)