Skip to content

Commit fed3a36

Browse files
authored
Use Ninja for faster build (#233)
* Use Ninja for faster build * Build with multicore * Clean up
1 parent d109a01 commit fed3a36

18 files changed

Lines changed: 205 additions & 200 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ jobs:
1818
- name: Prepare
1919
run: bash scripts/install_dependency.sh
2020
- name: Configure CMake
21-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
21+
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
2222
- name: Build
23-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
23+
run: ninja -C ${{github.workspace}}/build
2424
- name: Test
2525
working-directory: ${{github.workspace}}/build
26-
run: |
27-
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
26+
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
2827

2928
ubuntu:
3029
runs-on: ubuntu-latest
@@ -34,12 +33,12 @@ jobs:
3433
run: bash scripts/install_dependency.sh
3534
- name: Configure CMake with LSan
3635
run: |
37-
cmake -B ${{github.workspace}}/build \
36+
cmake -G Ninja -B ${{github.workspace}}/build \
3837
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
3938
-DCMAKE_C_FLAGS="-fsanitize=leak" \
4039
-DCMAKE_CXX_FLAGS="-fsanitize=leak"
4140
- name: Build
42-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
41+
run: ninja -C ${{github.workspace}}/build
4342
- name: Test with LSan
4443
working-directory: ${{github.workspace}}/build
4544
run: |
@@ -51,12 +50,9 @@ jobs:
5150
steps:
5251
- uses: actions/checkout@v4
5352
- name: Configure CMake
54-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_GLCACHE=on -DENABLE_LRB=on
53+
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_GLCACHE=on -DENABLE_LRB=on
5554
- name: Build
56-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
55+
run: ninja -C ${{github.workspace}}/build
5756
- name: Test
5857
working-directory: ${{github.workspace}}/build
5958
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
60-
61-
62-

.github/workflows/code-quality.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install dependencies
1515
run: |
1616
sudo apt-get update
17-
sudo apt-get install -y clang-format clang-tidy cmake g++ make
17+
sudo apt-get install -y clang-format clang-tidy cmake g++ ninja-build
1818
bash scripts/install_dependency.sh
1919
2020
- name: Get changed C/C++ files
@@ -36,15 +36,15 @@ jobs:
3636
run: |
3737
echo "Running clang-format checks..."
3838
FORMAT_ERRORS=0
39-
39+
4040
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
4141
echo "Checking formatting for $file"
4242
if ! clang-format --dry-run --Werror "$file" >> logs/format.log 2>&1; then
4343
echo "::error file=$file::Formatting issues in $file"
4444
FORMAT_ERRORS=$((FORMAT_ERRORS + 1))
4545
fi
4646
done
47-
47+
4848
if [ $FORMAT_ERRORS -gt 0 ]; then
4949
echo "Found formatting issues in $FORMAT_ERRORS files."
5050
echo "You can fix these issues with: clang-format -i <file>"
@@ -57,7 +57,7 @@ jobs:
5757
- name: Configure CMake
5858
if: steps.changed-files.outputs.any_changed == 'true'
5959
run: |
60-
cmake -B build -DCMAKE_BUILD_TYPE=Debug \
60+
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Debug \
6161
-DCMAKE_C_FLAGS="-Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs" \
6262
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs" \
6363
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
@@ -68,11 +68,11 @@ jobs:
6868
# run: |
6969
# echo "Running clang-tidy checks..."
7070
# FILES_WITH_ISSUES=0
71-
71+
7272
# for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
7373
# echo "Checking $file with clang-tidy"
7474
# LOG_FILE="logs/tidy_$(basename "$file").log"
75-
75+
7676
# # Run clang-tidy with selected checks (same as pre-commit hook)
7777
# if ! clang-tidy -p=build \
7878
# -checks='-*,bugprone-*,cert-*,clang-analyzer-*,cppcoreguidelines-*,performance-*,portability-*,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-cppcoreguidelines-avoid-magic-numbers,-readability-identifier-length,-clang-diagnostic-unused-command-line-argument' \
@@ -82,7 +82,7 @@ jobs:
8282
# FILES_WITH_ISSUES=$((FILES_WITH_ISSUES + 1))
8383
# fi
8484
# done
85-
85+
8686
# if [ $FILES_WITH_ISSUES -gt 0 ]; then
8787
# echo "clang-tidy found issues in $FILES_WITH_ISSUES files."
8888
# exit 1
@@ -94,10 +94,10 @@ jobs:
9494
if: steps.changed-files.outputs.any_changed == 'true'
9595
run: |
9696
echo "Checking for compilation warnings..."
97-
if cmake --build build -j$(nproc) > logs/compile.log 2>&1; then
97+
if ninja -C build > logs/compile.log 2>&1; then
9898
echo "Compilation successful!"
9999
else
100100
echo "Compilation failed. Please fix the warnings."
101101
cat logs/compile.log
102102
exit 1
103-
fi
103+
fi

.github/workflows/npm-release.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ jobs:
1919
outputs:
2020
release_created: ${{ steps.release.outputs.release_created }}
2121
version: ${{ steps.package.outputs.version }}
22-
22+
2323
steps:
2424
- name: Checkout code
2525
uses: actions/checkout@v4
26-
26+
2727
- name: Synchronize Node.js binding version
2828
run: |
2929
echo "Synchronizing Node.js binding version with main project..."
3030
python3 scripts/sync_node_version.py
31-
31+
3232
- name: Get package version
3333
id: package
3434
working-directory: libCacheSim-node
3535
run: |
3636
VERSION=$(node -p "require('./package.json').version")
3737
echo "version=$VERSION" >> $GITHUB_OUTPUT
3838
echo "Version: $VERSION"
39-
39+
4040
- name: Check if release exists
4141
id: check_release
4242
run: |
@@ -50,7 +50,7 @@ jobs:
5050
fi
5151
env:
5252
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
53+
5454
- name: Create GitHub Release
5555
id: release
5656
if: steps.check_release.outputs.exists == 'false'
@@ -62,15 +62,15 @@ jobs:
6262
release_name: Release v${{ steps.package.outputs.version }}
6363
body: |
6464
Release v${{ steps.package.outputs.version }}
65-
65+
6666
## Installation
6767
```bash
6868
npm install libcachesim-node
6969
```
70-
70+
7171
## Supported Platforms
7272
- Linux x64
73-
73+
7474
Pre-compiled binaries are automatically downloaded during installation.
7575
draft: false
7676
prerelease: false
@@ -79,48 +79,48 @@ jobs:
7979
if: github.event_name == 'release'
8080
needs: create-release
8181
runs-on: ubuntu-latest
82-
82+
8383
steps:
8484
- name: Checkout code
8585
uses: actions/checkout@v4
8686
with:
8787
fetch-depth: 0
88-
88+
8989
- name: Synchronize Node.js binding version
9090
run: |
9191
echo "Synchronizing Node.js binding version with main project..."
9292
python3 scripts/sync_node_version.py
93-
93+
9494
- name: Setup Node.js
9595
uses: actions/setup-node@v4
9696
with:
9797
node-version: '18'
9898
registry-url: 'https://registry.npmjs.org'
99-
99+
100100
- name: Install system dependencies
101101
run: |
102102
sudo apt-get update
103-
sudo apt-get install -y build-essential cmake libglib2.0-dev libzstd-dev
104-
103+
sudo apt-get install -y build-essential cmake ninja-build libglib2.0-dev libzstd-dev
104+
105105
- name: Build libCacheSim
106106
run: |
107107
echo "Building libCacheSim for Linux x64..."
108108
mkdir -p _build
109109
cd _build
110-
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} .. -DCMAKE_VERBOSE_MAKEFILE=ON
110+
cmake -G Ninja -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} .. -DCMAKE_VERBOSE_MAKEFILE=ON
111111
echo "Starting build..."
112-
make -j$(nproc) VERBOSE=1
113-
112+
ninja -v
113+
114114
- name: Prepare vendored library
115115
run: |
116116
mkdir -p libCacheSim-node/vendor/include
117117
cp _build/liblibCacheSim.a libCacheSim-node/vendor/
118118
cp -r libCacheSim/include/* libCacheSim-node/vendor/include/
119-
119+
120120
- name: Install Node.js dependencies
121121
working-directory: libCacheSim-node
122122
run: npm install
123-
123+
124124
- name: Build and upload prebuilt binary
125125
working-directory: libCacheSim-node
126126
run: |
@@ -132,7 +132,7 @@ jobs:
132132
CFLAGS=-fPIC CXXFLAGS=-fPIC npx prebuild --upload-all --verbose
133133
env:
134134
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135-
135+
136136
- name: Test binary
137137
working-directory: libCacheSim-node
138138
run: |
@@ -145,33 +145,33 @@ jobs:
145145
if: github.event_name == 'release'
146146
needs: build-and-publish
147147
runs-on: ubuntu-latest
148-
148+
149149
steps:
150150
- name: Checkout code
151151
uses: actions/checkout@v4
152-
152+
153153
- name: Synchronize Node.js binding version
154154
run: |
155155
echo "Synchronizing Node.js binding version with main project..."
156156
python3 scripts/sync_node_version.py
157-
157+
158158
- name: Setup Node.js
159159
uses: actions/setup-node@v4
160160
with:
161161
node-version: '18'
162162
registry-url: 'https://registry.npmjs.org'
163-
163+
164164
- name: Install system dependencies
165165
run: |
166166
sudo apt-get update
167-
sudo apt-get install -y build-essential cmake libglib2.0-dev libzstd-dev
167+
sudo apt-get install -y build-essential cmake ninja-build libglib2.0-dev libzstd-dev
168168
169169
- name: Build libCacheSim
170170
run: |
171171
mkdir -p _build
172172
cd _build
173-
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ..
174-
make -j$(nproc)
173+
cmake -G Ninja -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ..
174+
ninja
175175
176176
- name: Prepare vendored library
177177
run: |
@@ -184,4 +184,4 @@ jobs:
184184
working-directory: libCacheSim-node
185185
run: npm publish --access public
186186
env:
187-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
187+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)