Skip to content

Commit 2767245

Browse files
committed
feat(repo) & fix(ci): Do a file structure change on the repo, aswell as make ci.yml be based on a matrix
1 parent 1e06403 commit 2767245

28 files changed

+2281
-2184
lines changed
650 Bytes
Binary file not shown.

.clangd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CompileFlags:
2-
Add: [-Wall, -Wextra]
2+
Add: [-Wall, -Wextra, -I./]

.github/workflows/ci.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
name: C Test CI
22
on:
33
push:
4-
branches: [$default-branch]
4+
branches: [main]
55
pull_request:
6-
branches: [$default-branch]
6+
branches: [main]
77
jobs:
88
build:
9-
runs-on: ubuntu-24.04
9+
strategy:
10+
matrix:
11+
os: [ubuntu-24.04, windows-latest]
12+
runs-on: ${{ matrix.os }}
1013
steps:
1114
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
12-
- name: Install mold
15+
- name: Install mold on ubuntu systems
16+
if: matrix.os == 'ubuntu-24.04'
1317
uses: rui314/setup-mold@2e332a0b602c2fc65d2d3995941b1b29a5f554a0 # v1
1418
- name: Install just
1519
uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2
1620
- name: Test build
1721
shell: bash
18-
run: "just build \n"
22+
run: just build
1923
- name: Run unit-tests
2024
shell: bash
21-
run: |-
22-
just test
25+
run: just test

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
/bin/
2-
/out/
1+
/build/bin/
2+
/build/out/
3+
/build/tests/
34
/hsh
45
/hamon
56
/tests/unity
67
/vgcore
8+
/compile_commands.json

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(hamon)
3+
4+
include_directories(include)
5+
6+
add_executable(main src/main.c)

scripts/build.sh build/build.sh

+31-13
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ __LICENSE__="BSD 3-Clause License"
4646
__VERSION__="0.1.0"
4747

4848
SRC="$(pwd)/src"
49-
OUT="$(pwd)/out"
50-
BIN="$(pwd)/bin"
49+
BUILD="$(pwd)/build"
50+
OUT="${BUILD}/out"
51+
BIN="${BUILD}/bin"
5152
DIR="${SRC}/hamon"
5253

5354
TESTS="$(pwd)/tests"
54-
TESTS_OUT="${TESTS}/out"
55-
TESTS_BIN="${TESTS}/bin"
55+
TESTS_OUT="${BUILD}/tests/out"
56+
TESTS_BIN="${BUILD}/tests/bin"
57+
58+
UNITY_TAG="v2.6.0"
5659

5760
#INCLUDE="$(pwd)/include"
5861
COLOR=true
@@ -69,7 +72,7 @@ if ${COLOR}; then
6972
CLEAR="${ESCAPE}[0m"
7073
fi
7174

72-
CFLAGS="-O3 -Wall -Wextra"
75+
CFLAGS="-O3 -Wall -Wextra -I./"
7376

7477
LINKER_FLAGS="-Wall -Wextra"
7578

@@ -125,6 +128,12 @@ Cleans all files in ${CYAN}${BIN}/${CLEAR} & ${CYAN}${OUT}/${CLEAR}
125128
${RED}-vg${CLEAR} | ${RED}--delete-cores${CLEAR} | ${RED}--delete-vgcores${CLEAR} | ${RED}--clean-vgcores${CLEAR} | ${RED}--clean-cores${CLEAR}
126129
Cleans all vgcore files generated by valgrind in the repo.
127130
131+
${RED}-h${CLEAR} | ${RED}--help${CLEAR}
132+
Shows this message.
133+
134+
${RED}-f${CLEAR} | ${RED}--fix-clangd${CLEAR}
135+
Generates a compile_commands.json for clangd.
136+
128137
Made with ${RED}<3${CLEAR} by ${__AUTHOR__}
129138
EOF
130139
}
@@ -218,9 +227,9 @@ setup_unity() {
218227
mkdir temp_dir
219228

220229
pushd temp_dir >/dev/null || handle_failure "Failed to pushd"
221-
git clone https://github.com/ThrowTheSwitch/Unity
230+
git clone --branch "${UNITY_TAG}" https://github.com/ThrowTheSwitch/Unity
222231

223-
rm Unity/src/meson.buildhttps://crackboard.dev/
232+
rm Unity/src/meson.build
224233
mv Unity/src/* "${TESTS}/unity"
225234

226235
popd >/dev/null || handle_failure "Failed to popd"
@@ -249,19 +258,19 @@ unit_test() {
249258
fi
250259

251260
if [[ ! -d ${TESTS_OUT} ]]; then
252-
mkdir "${TESTS_OUT}"
261+
mkdir -p "${TESTS_OUT}"
253262
fi
254263

255264
if [[ ! -d ${TESTS_OUT}/unity ]]; then
256-
mkdir "${TESTS_OUT}/unity"
265+
mkdir -p "${TESTS_OUT}/unity"
257266
fi
258267

259268
if [[ ! -d ${TESTS_OUT}/deps ]]; then
260-
mkdir "${TESTS_OUT}/deps"
269+
mkdir -p "${TESTS_OUT}/deps"
261270
fi
262271

263272
if [[ ! -d ${TESTS_BIN} ]]; then
264-
mkdir "${TESTS_BIN}"
273+
mkdir -p "${TESTS_BIN}"
265274
fi
266275

267276
mapfile -t TEST_FILES < <(find "${TESTS}" -maxdepth 1 -type f -name "*.c")
@@ -336,7 +345,7 @@ unit_test() {
336345

337346
popd >/dev/null || handle_failure "Failed to popd" # || echo "Failed to popd" && exit 1
338347

339-
rm -fr "${TESTS_OUT}" "${TESTS_BIN}"
348+
#rm -fr "${TESTS_OUT}" "${TESTS_BIN}"
340349
}
341350

342351
# removes dangling object files that shouldn't be there, used to be required, not that much as of lately though.
@@ -420,6 +429,12 @@ clear_vgcores() {
420429
done
421430
}
422431

432+
fix_clangd() {
433+
cmake -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=ON >/dev/null
434+
mv build/compile_commands.json .
435+
find build -mindepth 1 ! -path "build/bin" ! -path "build/out" ! -path "build/tests" ! -name "build.sh" -exec rm -rf {} +
436+
}
437+
423438
case $1 in
424439
"-c" | "--compile")
425440
compile
@@ -440,7 +455,10 @@ case $1 in
440455
"-vg" | "--delete-cores" | "--delete-vgcores" | "--clean-vgcores" | "--clean-cores")
441456
clear_vgcores
442457
;;
443-
"--help" | "-h" | "-?" | *)
458+
"-f" | "--fix-clangd")
459+
fix_clangd
460+
;;
461+
"--help" | "-h" | *)
444462
print_help "${@}"
445463
;;
446464
esac
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)