Skip to content

Commit d5e1770

Browse files
authored
Improve development and build environment (#5)
* Improve development and build environment * Misc. updates * Fix linting and formatting
1 parent 862f00b commit d5e1770

24 files changed

Lines changed: 185 additions & 84 deletions

.clang-format

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ BreakBeforeBraces: Attach
66
AllowShortIfStatementsOnASingleLine: false
77
AllowShortLoopsOnASingleLine: false
88
AllowShortFunctionsOnASingleLine: Inline
9-
ColumnLimit: 0
9+
ColumnLimit: 120
10+
AlignEscapedNewlines: Left

.clang-tidy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Checks: >
2+
clang-analyzer-*,
3+
bugprone-*,
4+
misc-*,
5+
readability-*,
6+
-readability-magic-numbers,
7+
-readability-identifier-length,
8+
-misc-unused-parameters,
9+
-misc-include-cleaner
10+
11+
HeaderFilterRegex: 'src/.*'

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.DS_Store
2-
*.o
3-
.so
4-
*.dylib
5-
build
2+
*log*.txt
63

4+
/tmp
5+
/build
6+
7+
# VSCode
78
.vscode/*
89
!.vscode/c_cpp_properties.json
10+
!.vscode/extensions.json
911
!.vscode/launch.json
1012
!.vscode/settings.json
1113
!.vscode/tasks.json
14+

.vscode/c_cpp_properties.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
6+
"compilerPath": "/usr/bin/clang",
7+
"cStandard": "c11",
8+
"intelliSenseMode": "macos-clang-arm64"
9+
}
10+
],
11+
"version": 4
12+
}

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode.cpptools",
4+
"ms-vscode.cmake-tools"
5+
]
6+
}

.vscode/settings.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@
66
"editor.formatOnSave": true,
77
"editor.defaultFormatter": "ms-vscode.cpptools"
88
},
9+
"[json]": {
10+
"editor.defaultFormatter": "vscode.json-language-features"
11+
},
12+
"[markdown]": {
13+
"editor.defaultFormatter": "denoland.vscode-deno",
14+
"editor.formatOnSave": true
15+
},
16+
"files.associations": {
17+
"*.jsonl": "json",
18+
".clang-format": "yaml",
19+
},
920
"cSpell.words": [
1021
"armv",
1122
"CMSIS",
23+
"cppcheck",
1224
"ctest",
1325
"Dryrun",
1426
"eabi",
1527
"libnewlib",
1628
"noninteractive",
1729
"tinyclib",
18-
"trunc"
30+
"trunc",
31+
"xcrun"
1932
],
20-
"files.associations": {
21-
".clang-format": "yaml",
22-
}
2333
}

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

3-
See https://common-changelog.org for commit guidelines.
3+
See https://common-changelog.org for commit guidelines and https://semver.org
4+
for versioning.
45

56
## v0.1.1 - 2025-04-27
67

CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
cmake_minimum_required(VERSION 3.25)
22

3-
project(tinyclib VERSION 0.1.0 LANGUAGES C)
3+
project(tinyclib VERSION 0.1.1 LANGUAGES C)
44

5-
# Set the output directories
5+
# Settings
6+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
67
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
78
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
89
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
910

11+
# Dependencies
12+
include(FetchContent)
1013
# Sources
1114
file(GLOB SOURCES CONFIGURE_DEPENDS src/*.c)
1215

1316
# Add the library (BUILD_SHARED_LIBS is handled by CMake)
1417
add_library(tinyclib ${SOURCES})
1518

16-
# Set the C standard to C11 for now
19+
# Set the C standard
1720
set_property(TARGET tinyclib PROPERTY C_STANDARD 11)
1821
set_property(TARGET tinyclib PROPERTY C_STANDARD_REQUIRED ON)
1922
set_property(TARGET tinyclib PROPERTY C_EXTENSIONS OFF)
@@ -81,22 +84,22 @@ if(BUILD_TESTS)
8184

8285
# FetchContent for Unity testing framework
8386
FetchContent_Declare(
84-
Unity
85-
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
86-
GIT_TAG v2.6.1
87+
Unity
88+
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
89+
GIT_TAG v2.6.1
8790
)
8891
FetchContent_MakeAvailable(Unity)
8992
FetchContent_GetProperties(Unity)
9093

9194
if(NOT TARGET Unity)
92-
add_library(Unity STATIC ${unity_SOURCE_DIR}/src/unity.c)
95+
add_library(Unity STATIC ${unity_SOURCE_DIR}/src/unity.c)
9396
endif()
9497
target_include_directories(Unity PUBLIC ${unity_SOURCE_DIR}/src)
9598

9699
enable_testing()
97100
foreach(t app config debug error test)
98101
add_executable(tl_${t}_test tests/arch/generic/tl_${t}_test.c)
99-
target_link_libraries(tl_${t}_test Unity tinyclib)
102+
target_link_libraries(tl_${t}_test unity tinyclib)
100103
add_test(NAME tl_${t}_test COMMAND tl_${t}_test)
101104
endforeach()
102105
endif()

CMakePresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"binaryDir": "${sourceDir}/build",
1212
"cacheVariables": {
1313
"CMAKE_BUILD_TYPE": "Debug",
14+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
1415
"BUILD_TESTS": "ON"
1516
}
1617
}

Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.PHONY: help install build clean test format lint check check-all fix
2+
3+
BUILD_DIR := build
4+
CLANG_FORMAT := $(shell if command -v clang-format >/dev/null 2>&1; then echo clang-format; fi)
5+
CLANG_TIDY := $(shell if command -v clang-tidy >/dev/null 2>&1; then echo clang-tidy; fi)
6+
CPPCHECK := $(shell if command -v cppcheck >/dev/null 2>&1; then echo cppcheck; fi)
7+
CLANG_TIDY_EXTRA_ARGS := $(shell if [ "$$(uname)" = "Darwin" ]; then echo "--extra-arg=--sysroot=$$(xcrun --show-sdk-path)"; fi)
8+
9+
SRC_FILES := src/*.c include/*.h
10+
TEST_FILES := tests/arch/generic/*.c
11+
ALL_FILES := $(SRC_FILES) $(TEST_FILES)
12+
13+
help: ## Show available make targets
14+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
15+
awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'
16+
17+
configure: ## Configure cmake
18+
cmake --preset default
19+
20+
build: ## Build the project
21+
cmake --build --preset default
22+
23+
clean: ## Remove build directory
24+
@test -n "$(CURDIR)" && [ "$(CURDIR)" != "/" ]
25+
rm -rf "$(CURDIR)/$(BUILD_DIR)"
26+
27+
test: ## Build and run tests
28+
cmake --workflow --preset default
29+
30+
format: ## Check code formatting
31+
@test -n "$(CLANG_FORMAT)" || { echo "error: clang-format not found"; exit 1; }
32+
$(CLANG_FORMAT) --dry-run --Werror $(ALL_FILES) --verbose
33+
34+
lint: ## Check code linting
35+
@test -n "$(CLANG_TIDY)" || { echo "error: clang-tidy not found"; exit 1; }
36+
$(CLANG_TIDY) -p $(BUILD_DIR) $(CLANG_TIDY_EXTRA_ARGS) \
37+
--header-filter="^$(CURDIR)/(src|include|tests)/" src/*.c tests/arch/generic/*.c
38+
39+
check: ## Static analysis
40+
@test -n "$(CPPCHECK)" || { echo "error: cppcheck not found"; exit 1; }
41+
$(CPPCHECK) --enable=warning,style,performance,portability --error-exitcode=1 \
42+
--project=$(BUILD_DIR)/compile_commands.json --suppress=missingIncludeSystem \
43+
-i$(BUILD_DIR)
44+
45+
check-all: format lint check ## Run all checks
46+
47+
fix: ## Fix code formatting and linting issues
48+
@test -n "$(CLANG_FORMAT)" || { echo "error: clang-format not found"; exit 1; }
49+
$(CLANG_FORMAT) -i $(ALL_FILES)

0 commit comments

Comments
 (0)