Skip to content

Commit

Permalink
build: use Ninja on all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jan 1, 2024
1 parent 5b35fe9 commit e019063
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
CMAKE_GENERATOR: Ninja

jobs:
build:
Expand All @@ -20,6 +21,13 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
with_rust: ['true', 'false']
rust_version: ['1.70', 'stable']
include:
- os: ubuntu-latest
c_compiler: cc
- os: windows-latest
c_compiler: cl.exe
- os: macos-latest
c_compiler: cc
exclude:
- with_rust: 'false'
rust_version: 'stable'
Expand All @@ -31,12 +39,23 @@ jobs:
with:
submodules: 'true'

- if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get install ninja-build
- if: ${{ matrix.os == 'macos-latest' }}
run: brew install ninja
- if: ${{ matrix.os == 'windows-latest' }}
run: choco install ninja
- if: ${{ matrix.os == 'windows-latest' }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756

- name: Setup rustup
run: |
rustup default ${{ matrix.rust_version }}
rustup update
- name: Build
env:
CC: ${{ matrix.c_compiler }}
run: cargo xtask build --build-type ${{env.BUILD_TYPE}} --with-rust ${{matrix.with_rust}} --verbose true

- name: Test
Expand All @@ -50,6 +69,8 @@ jobs:
with:
submodules: 'true'

- run: sudo apt-get install ninja-build

- name: Build
run: cargo xtask build --build-type ${{env.BUILD_TYPE}} --with-rust false --with-hash true --verbose true

Expand All @@ -61,13 +82,15 @@ jobs:
matrix:
with_rust: ['true', 'false']
runs-on: ubuntu-latest
name: with_rust=${{ matrix.with_rust }}
name: Coverage with_rust=${{ matrix.with_rust }}

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- run: sudo apt-get install ninja-build

- name: Setup rustup
run: |
rustup default stable
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
endif()
elseif(MSVC)
elseif(CMAKE_C_COMPILER_ID MATCHES MSVC)
# /wd4819
# Without BOM, Visual Studio does not treat source file as UTF-8
# encoding, thus it will complain about invalid character. Use
Expand Down Expand Up @@ -70,7 +70,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})

option(WITH_SQLITE3 "Use sqlite3 to store userphrase" true)
option(WITH_INTERNAL_SQLITE3 "Use internal sqlite3" false)
if(MSVC)
if(CMAKE_C_COMPILER_ID MATCHES MSVC)
set(WITH_INTERNAL_SQLITE3 true)
endif()

Expand Down Expand Up @@ -274,7 +274,7 @@ if(NOT WITH_RUST)
target_link_libraries(libchewing
PRIVATE common
PRIVATE userphrase)
if(BUILD_SHARED_LIBS AND MSVC)
if(BUILD_SHARED_LIBS AND CMAKE_C_COMPILER_ID MATCHES MSVC)
target_compile_definitions(libchewing PRIVATE CHEWINGDLL_EXPORTS)
endif()
endif()
Expand All @@ -297,7 +297,7 @@ if(WITH_RUST)
PRIVATE LINKER:-exported_symbols_list,${CMAKE_BINARY_DIR}/symbols.map
PRIVATE LINKER:-dead_strip
)
elseif(MSVC)
elseif(CMAKE_C_COMPILER_ID MATCHES MSVC)
target_link_options(libchewing PRIVATE "/DEF ${CMAKE_BINARY_DIR}/symbols.map")
set_target_properties(libchewing PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ foreach(target ${ALL_TESTS})
add_executable(${target} ${TEST_SRC_DIR}/${target}.c)
target_link_libraries(${target} testhelper)
# XXX workaround MSVC issue
if(MSVC AND WITH_RUST)
if(CMAKE_C_COMPILER_ID MATCHES MSVC AND WITH_RUST)
target_link_libraries(${target} chewing)
else()
target_link_libraries(${target} libchewing)
Expand Down

0 comments on commit e019063

Please sign in to comment.