@cubis/foundry 0.3.71 → 0.3.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/dist/cli/core.js +9 -22
  3. package/dist/cli/core.js.map +1 -1
  4. package/package.json +1 -1
  5. package/src/cli/core.ts +13 -22
  6. package/workflows/powers/accessibility/POWER.md +83 -94
  7. package/workflows/powers/accessibility/SKILL.md +82 -94
  8. package/workflows/powers/agent-design/POWER.md +201 -0
  9. package/workflows/powers/agent-design/SKILL.md +198 -0
  10. package/workflows/powers/agent-design/references/clarification-patterns.md +153 -0
  11. package/workflows/powers/agent-design/references/skill-testing.md +164 -0
  12. package/workflows/powers/agent-design/references/workflow-patterns.md +226 -0
  13. package/workflows/powers/agentic-eval/POWER.md +62 -0
  14. package/workflows/powers/agentic-eval/SKILL.md +59 -0
  15. package/workflows/powers/agentic-eval/references/rubric-and-regression-checklist.md +11 -0
  16. package/workflows/powers/api-designer/POWER.md +43 -71
  17. package/workflows/powers/api-designer/SKILL.md +43 -71
  18. package/workflows/powers/api-patterns/POWER.md +42 -56
  19. package/workflows/powers/api-patterns/SKILL.md +42 -57
  20. package/workflows/powers/architecture-designer/POWER.md +43 -60
  21. package/workflows/powers/architecture-designer/SKILL.md +43 -60
  22. package/workflows/powers/ask-questions-if-underspecified/POWER.md +51 -3
  23. package/workflows/powers/auth-architect/POWER.md +69 -0
  24. package/workflows/powers/auth-architect/SKILL.md +66 -0
  25. package/workflows/powers/auth-architect/references/session-token-policy-checklist.md +45 -0
  26. package/workflows/powers/behavioral-modes/POWER.md +100 -9
  27. package/workflows/powers/c-pro/POWER.md +105 -0
  28. package/workflows/powers/c-pro/SKILL.md +102 -0
  29. package/workflows/powers/c-pro/references/build-systems-and-toolchains.md +148 -0
  30. package/workflows/powers/c-pro/references/common-ub-and-portability.md +166 -0
  31. package/workflows/powers/c-pro/references/debugging-with-sanitizers.md +205 -0
  32. package/workflows/powers/c-pro/references/memory-safety-and-build-checklist.md +60 -0
  33. package/workflows/powers/c-pro/references/posix-and-platform-apis.md +244 -0
  34. package/workflows/powers/changelog-generator/POWER.md +127 -63
  35. package/workflows/powers/changelog-generator/SKILL.md +126 -63
  36. package/workflows/powers/ci-cd-pipelines/POWER.md +156 -0
  37. package/workflows/powers/ci-cd-pipelines/SKILL.md +153 -0
  38. package/workflows/powers/ci-cd-pipelines/references/github-actions-patterns.md +160 -0
  39. package/workflows/powers/ci-cd-pipelines/references/pipeline-security-checklist.md +57 -0
  40. package/workflows/powers/cli-developer/POWER.md +152 -95
  41. package/workflows/powers/cli-developer/SKILL.md +152 -95
  42. package/workflows/powers/cpp-pro/POWER.md +111 -0
  43. package/workflows/powers/cpp-pro/SKILL.md +108 -0
  44. package/workflows/powers/cpp-pro/references/concurrency-primitives.md +266 -0
  45. package/workflows/powers/cpp-pro/references/move-semantics-and-value-types.md +149 -0
  46. package/workflows/powers/cpp-pro/references/performance-and-profiling.md +191 -0
  47. package/workflows/powers/cpp-pro/references/raii-and-modern-cpp-checklist.md +87 -0
  48. package/workflows/powers/cpp-pro/references/template-and-concepts-patterns.md +205 -0
  49. package/workflows/powers/csharp-pro/POWER.md +47 -22
  50. package/workflows/powers/csharp-pro/SKILL.md +47 -22
  51. package/workflows/powers/dart-pro/POWER.md +68 -0
  52. package/workflows/powers/dart-pro/SKILL.md +65 -0
  53. package/workflows/powers/dart-pro/references/isolate-and-concurrency.md +180 -0
  54. package/workflows/powers/dart-pro/references/null-safety-and-async-patterns.md +133 -0
  55. package/workflows/powers/dart-pro/references/package-structure-and-linting.md +193 -0
  56. package/workflows/powers/dart-pro/references/sealed-records-patterns.md +173 -0
  57. package/workflows/powers/dart-pro/references/testing-and-mocking.md +235 -0
  58. package/workflows/powers/database-design/POWER.md +47 -33
  59. package/workflows/powers/database-design/SKILL.md +47 -33
  60. package/workflows/powers/database-optimizer/POWER.md +43 -64
  61. package/workflows/powers/database-optimizer/SKILL.md +43 -64
  62. package/workflows/powers/database-skills/POWER.md +59 -93
  63. package/workflows/powers/database-skills/SKILL.md +59 -93
  64. package/workflows/powers/debugging-strategies/POWER.md +69 -0
  65. package/workflows/powers/debugging-strategies/SKILL.md +66 -0
  66. package/workflows/powers/debugging-strategies/references/reproduce-isolate-verify-checklist.md +42 -0
  67. package/workflows/powers/deep-research/POWER.md +67 -0
  68. package/workflows/powers/deep-research/SKILL.md +64 -0
  69. package/workflows/powers/deep-research/references/multi-round-research-loop.md +80 -0
  70. package/workflows/powers/design-system-builder/POWER.md +130 -116
  71. package/workflows/powers/design-system-builder/SKILL.md +130 -116
  72. package/workflows/powers/devops-engineer/POWER.md +120 -57
  73. package/workflows/powers/devops-engineer/SKILL.md +120 -57
  74. package/workflows/powers/docker-kubernetes/POWER.md +94 -0
  75. package/workflows/powers/docker-kubernetes/SKILL.md +91 -0
  76. package/workflows/powers/docker-kubernetes/references/dockerfile-optimization-checklist.md +35 -0
  77. package/workflows/powers/docker-kubernetes/references/kubernetes-deployment-patterns.md +59 -0
  78. package/workflows/powers/documentation-templates/POWER.md +158 -127
  79. package/workflows/powers/documentation-templates/SKILL.md +158 -127
  80. package/workflows/powers/drizzle-expert/POWER.md +66 -0
  81. package/workflows/powers/drizzle-expert/SKILL.md +63 -0
  82. package/workflows/powers/drizzle-expert/references/runtime-pairing-matrix.md +16 -0
  83. package/workflows/powers/drizzle-expert/references/schema-and-migration-playbook.md +18 -0
  84. package/workflows/powers/error-ux-observability/POWER.md +144 -131
  85. package/workflows/powers/error-ux-observability/SKILL.md +143 -131
  86. package/workflows/powers/fastapi-expert/POWER.md +46 -60
  87. package/workflows/powers/fastapi-expert/SKILL.md +46 -60
  88. package/workflows/powers/firebase/POWER.md +65 -0
  89. package/workflows/powers/firebase/SKILL.md +62 -0
  90. package/workflows/powers/firebase/references/platform-routing.md +16 -0
  91. package/workflows/powers/firebase/references/rules-and-indexes-checklist.md +11 -0
  92. package/workflows/powers/flutter-design-system/POWER.md +63 -0
  93. package/workflows/powers/flutter-design-system/SKILL.md +60 -0
  94. package/workflows/powers/flutter-design-system/references/shared-widgets.md +29 -0
  95. package/workflows/powers/flutter-design-system/references/tokens-and-theme.md +34 -0
  96. package/workflows/powers/flutter-drift/POWER.md +65 -0
  97. package/workflows/powers/flutter-drift/SKILL.md +62 -0
  98. package/workflows/powers/flutter-drift/references/migrations.md +22 -0
  99. package/workflows/powers/flutter-drift/references/query-patterns.md +26 -0
  100. package/workflows/powers/flutter-feature/POWER.md +65 -0
  101. package/workflows/powers/flutter-feature/SKILL.md +62 -0
  102. package/workflows/powers/flutter-feature/references/architecture-rules.md +85 -0
  103. package/workflows/powers/flutter-feature/references/composite-provider.md +58 -0
  104. package/workflows/powers/flutter-feature/references/outbox-pattern.md +87 -0
  105. package/workflows/powers/flutter-feature/references/testing-patterns.md +218 -0
  106. package/workflows/powers/flutter-go-router/POWER.md +64 -0
  107. package/workflows/powers/flutter-go-router/SKILL.md +61 -0
  108. package/workflows/powers/flutter-go-router/references/guards-and-deeplinks.md +20 -0
  109. package/workflows/powers/flutter-go-router/references/typed-routes.md +27 -0
  110. package/workflows/powers/flutter-offline-sync/POWER.md +62 -0
  111. package/workflows/powers/flutter-offline-sync/SKILL.md +59 -0
  112. package/workflows/powers/flutter-offline-sync/references/outbox-full.md +44 -0
  113. package/workflows/powers/flutter-repository/POWER.md +64 -0
  114. package/workflows/powers/flutter-repository/SKILL.md +61 -0
  115. package/workflows/powers/flutter-repository/references/drift-patterns.md +21 -0
  116. package/workflows/powers/flutter-repository/references/retrofit-patterns.md +20 -0
  117. package/workflows/powers/flutter-riverpod/POWER.md +70 -0
  118. package/workflows/powers/flutter-riverpod/SKILL.md +67 -0
  119. package/workflows/powers/flutter-riverpod/references/async-and-mutations.md +19 -0
  120. package/workflows/powers/flutter-riverpod/references/async-lifecycle.md +19 -0
  121. package/workflows/powers/flutter-riverpod/references/provider-selection.md +20 -0
  122. package/workflows/powers/flutter-riverpod/references/testing.md +21 -0
  123. package/workflows/powers/flutter-riverpod/references/version-matrix.md +24 -0
  124. package/workflows/powers/flutter-state-machine/POWER.md +62 -0
  125. package/workflows/powers/flutter-state-machine/SKILL.md +59 -0
  126. package/workflows/powers/flutter-state-machine/references/app-state-contract.md +23 -0
  127. package/workflows/powers/flutter-state-machine/references/ui-rendering.md +14 -0
  128. package/workflows/powers/flutter-testing/POWER.md +64 -0
  129. package/workflows/powers/flutter-testing/SKILL.md +61 -0
  130. package/workflows/powers/flutter-testing/references/offline-sync-tests.md +16 -0
  131. package/workflows/powers/flutter-testing/references/test-layers.md +33 -0
  132. package/workflows/powers/frontend-code-review/POWER.md +137 -0
  133. package/workflows/powers/frontend-code-review/SKILL.md +134 -0
  134. package/workflows/powers/frontend-code-review/references/common-antipatterns.md +86 -0
  135. package/workflows/powers/frontend-code-review/references/performance-budgets.md +56 -0
  136. package/workflows/powers/frontend-code-review/references/review-checklists.md +47 -0
  137. package/workflows/powers/frontend-design/POWER.md +163 -362
  138. package/workflows/powers/frontend-design/SKILL.md +163 -362
  139. package/workflows/powers/game-development/POWER.md +57 -140
  140. package/workflows/powers/game-development/SKILL.md +57 -140
  141. package/workflows/powers/geo-fundamentals/POWER.md +64 -126
  142. package/workflows/powers/geo-fundamentals/SKILL.md +64 -127
  143. package/workflows/powers/git-workflow/POWER.md +135 -0
  144. package/workflows/powers/git-workflow/SKILL.md +132 -0
  145. package/workflows/powers/git-workflow/references/pr-review-checklist.md +63 -0
  146. package/workflows/powers/golang-pro/POWER.md +46 -35
  147. package/workflows/powers/golang-pro/SKILL.md +46 -35
  148. package/workflows/powers/graphql-architect/POWER.md +44 -62
  149. package/workflows/powers/graphql-architect/SKILL.md +44 -62
  150. package/workflows/powers/i18n-localization/POWER.md +118 -103
  151. package/workflows/powers/i18n-localization/SKILL.md +118 -103
  152. package/workflows/powers/java-pro/POWER.md +47 -22
  153. package/workflows/powers/java-pro/SKILL.md +47 -22
  154. package/workflows/powers/javascript-pro/POWER.md +47 -34
  155. package/workflows/powers/javascript-pro/SKILL.md +47 -34
  156. package/workflows/powers/kotlin-pro/POWER.md +46 -23
  157. package/workflows/powers/kotlin-pro/SKILL.md +46 -23
  158. package/workflows/powers/legacy-modernizer/POWER.md +43 -60
  159. package/workflows/powers/legacy-modernizer/SKILL.md +43 -60
  160. package/workflows/powers/mcp-builder/POWER.md +65 -0
  161. package/workflows/powers/mcp-builder/SKILL.md +62 -0
  162. package/workflows/powers/mcp-builder/references/testing-and-evals.md +17 -0
  163. package/workflows/powers/mcp-builder/references/transport-and-tool-design.md +17 -0
  164. package/workflows/powers/microservices-architect/POWER.md +43 -70
  165. package/workflows/powers/microservices-architect/SKILL.md +43 -70
  166. package/workflows/powers/mobile-design/POWER.md +110 -345
  167. package/workflows/powers/mobile-design/SKILL.md +110 -345
  168. package/workflows/powers/mongodb/POWER.md +67 -0
  169. package/workflows/powers/mongodb/SKILL.md +64 -0
  170. package/workflows/powers/mongodb/references/mongodb-checklist.md +20 -0
  171. package/workflows/powers/mysql/POWER.md +67 -0
  172. package/workflows/powers/mysql/SKILL.md +64 -0
  173. package/workflows/powers/mysql/references/mysql-checklist.md +20 -0
  174. package/workflows/powers/neki/POWER.md +67 -0
  175. package/workflows/powers/neki/SKILL.md +64 -0
  176. package/workflows/powers/neki/references/neki-checklist.md +18 -0
  177. package/workflows/powers/nestjs-expert/POWER.md +45 -91
  178. package/workflows/powers/nestjs-expert/SKILL.md +45 -91
  179. package/workflows/powers/nextjs-developer/POWER.md +51 -44
  180. package/workflows/powers/nextjs-developer/SKILL.md +51 -44
  181. package/workflows/powers/nodejs-best-practices/POWER.md +48 -29
  182. package/workflows/powers/nodejs-best-practices/SKILL.md +48 -29
  183. package/workflows/powers/observability/POWER.md +109 -0
  184. package/workflows/powers/observability/SKILL.md +106 -0
  185. package/workflows/powers/observability/references/alerting-and-slo-checklist.md +87 -0
  186. package/workflows/powers/observability/references/opentelemetry-setup-guide.md +121 -0
  187. package/workflows/powers/openai-docs/POWER.md +61 -0
  188. package/workflows/powers/openai-docs/SKILL.md +58 -0
  189. package/workflows/powers/openai-docs/references/official-source-playbook.md +10 -0
  190. package/workflows/powers/performance-profiling/POWER.md +61 -114
  191. package/workflows/powers/performance-profiling/SKILL.md +61 -114
  192. package/workflows/powers/php-pro/POWER.md +116 -0
  193. package/workflows/powers/php-pro/SKILL.md +113 -0
  194. package/workflows/powers/php-pro/references/architecture-and-di.md +239 -0
  195. package/workflows/powers/php-pro/references/modern-php-features.md +189 -0
  196. package/workflows/powers/php-pro/references/performance-and-deployment.md +197 -0
  197. package/workflows/powers/php-pro/references/php84-strict-typing-checklist.md +161 -0
  198. package/workflows/powers/php-pro/references/testing-and-static-analysis.md +235 -0
  199. package/workflows/powers/playwright-e2e/POWER.md +85 -0
  200. package/workflows/powers/playwright-e2e/SKILL.md +82 -0
  201. package/workflows/powers/playwright-e2e/references/locator-trace-flake-checklist.md +80 -0
  202. package/workflows/powers/postgres/POWER.md +67 -0
  203. package/workflows/powers/postgres/SKILL.md +64 -0
  204. package/workflows/powers/postgres/references/postgres-checklist.md +20 -0
  205. package/workflows/powers/prompt-engineer/POWER.md +47 -30
  206. package/workflows/powers/prompt-engineer/SKILL.md +47 -30
  207. package/workflows/powers/python-pro/POWER.md +47 -36
  208. package/workflows/powers/python-pro/SKILL.md +47 -36
  209. package/workflows/powers/react-best-practices/POWER.md +56 -33
  210. package/workflows/powers/react-best-practices/SKILL.md +56 -33
  211. package/workflows/powers/react-expert/POWER.md +47 -37
  212. package/workflows/powers/react-expert/SKILL.md +47 -37
  213. package/workflows/powers/redis/POWER.md +67 -0
  214. package/workflows/powers/redis/SKILL.md +64 -0
  215. package/workflows/powers/redis/references/redis-checklist.md +19 -0
  216. package/workflows/powers/ruby-pro/POWER.md +118 -0
  217. package/workflows/powers/ruby-pro/SKILL.md +115 -0
  218. package/workflows/powers/ruby-pro/references/modern-ruby-features.md +189 -0
  219. package/workflows/powers/ruby-pro/references/object-design-patterns.md +220 -0
  220. package/workflows/powers/ruby-pro/references/performance-and-profiling.md +224 -0
  221. package/workflows/powers/ruby-pro/references/ruby-concurrency-and-testing.md +190 -0
  222. package/workflows/powers/ruby-pro/references/testing-and-rspec.md +236 -0
  223. package/workflows/powers/rust-pro/POWER.md +45 -31
  224. package/workflows/powers/rust-pro/SKILL.md +45 -31
  225. package/workflows/powers/security-engineer/POWER.md +129 -0
  226. package/workflows/powers/security-engineer/SKILL.md +126 -0
  227. package/workflows/powers/seo-fundamentals/POWER.md +59 -102
  228. package/workflows/powers/seo-fundamentals/SKILL.md +59 -102
  229. package/workflows/powers/serverless-patterns/POWER.md +171 -0
  230. package/workflows/powers/serverless-patterns/SKILL.md +168 -0
  231. package/workflows/powers/skill-creator/POWER.md +90 -0
  232. package/workflows/powers/skill-creator/SKILL.md +87 -0
  233. package/workflows/powers/skill-creator/references/platform-formats.md +181 -0
  234. package/workflows/powers/skill-creator/references/schemas.md +430 -0
  235. package/workflows/powers/spec-miner/POWER.md +49 -57
  236. package/workflows/powers/spec-miner/SKILL.md +49 -57
  237. package/workflows/powers/sqlite/POWER.md +67 -0
  238. package/workflows/powers/sqlite/SKILL.md +64 -0
  239. package/workflows/powers/sqlite/references/sqlite-checklist.md +19 -0
  240. package/workflows/powers/sre-engineer/POWER.md +123 -64
  241. package/workflows/powers/sre-engineer/SKILL.md +123 -64
  242. package/workflows/powers/static-analysis/POWER.md +121 -77
  243. package/workflows/powers/static-analysis/SKILL.md +121 -77
  244. package/workflows/powers/stripe-best-practices/POWER.md +140 -17
  245. package/workflows/powers/stripe-best-practices/SKILL.md +139 -17
  246. package/workflows/powers/supabase/POWER.md +67 -0
  247. package/workflows/powers/supabase/SKILL.md +64 -0
  248. package/workflows/powers/supabase/references/supabase-checklist.md +19 -0
  249. package/workflows/powers/swift-pro/POWER.md +118 -0
  250. package/workflows/powers/swift-pro/SKILL.md +115 -0
  251. package/workflows/powers/swift-pro/references/concurrency-patterns.md +165 -0
  252. package/workflows/powers/swift-pro/references/protocol-and-generics.md +172 -0
  253. package/workflows/powers/swift-pro/references/sendable-and-isolation.md +116 -0
  254. package/workflows/powers/swift-pro/references/swift-concurrency-and-protocols.md +260 -0
  255. package/workflows/powers/swift-pro/references/testing-and-packages.md +192 -0
  256. package/workflows/powers/tailwind-patterns/POWER.md +71 -240
  257. package/workflows/powers/tailwind-patterns/SKILL.md +71 -240
  258. package/workflows/powers/testing-patterns/POWER.md +155 -10
  259. package/workflows/powers/testing-patterns/SKILL.md +155 -10
  260. package/workflows/powers/typescript-pro/POWER.md +47 -38
  261. package/workflows/powers/typescript-pro/SKILL.md +47 -38
  262. package/workflows/powers/vitess/POWER.md +67 -0
  263. package/workflows/powers/vitess/SKILL.md +64 -0
  264. package/workflows/powers/vitess/references/vitess-checklist.md +19 -0
  265. package/workflows/powers/vulnerability-scanner/POWER.md +146 -10
  266. package/workflows/powers/vulnerability-scanner/SKILL.md +146 -10
  267. package/workflows/powers/web-perf/POWER.md +43 -170
  268. package/workflows/powers/web-perf/SKILL.md +43 -170
  269. package/workflows/powers/webapp-testing/POWER.md +43 -164
  270. package/workflows/powers/webapp-testing/SKILL.md +43 -164
  271. package/workflows/workflows/agent-environment-setup/platforms/antigravity/rules/GEMINI.md +65 -42
  272. package/workflows/workflows/agent-environment-setup/platforms/claude/rules/CLAUDE.md +8 -6
  273. package/workflows/workflows/agent-environment-setup/platforms/codex/rules/AGENTS.md +65 -41
  274. package/workflows/workflows/agent-environment-setup/platforms/copilot/rules/copilot-instructions.md +8 -6
  275. package/workflows/workflows/agent-environment-setup/shared/rules/STEERING.md +9 -8
  276. package/workflows/workflows/agent-environment-setup/shared/rules/overrides/codex.md +1 -1
@@ -0,0 +1,148 @@
1
+ # Build Systems and Toolchains
2
+
3
+ ## CMake Modern Practices
4
+
5
+ ```cmake
6
+ # CMakeLists.txt — modern CMake (3.21+)
7
+ cmake_minimum_required(VERSION 3.21)
8
+ project(mylib VERSION 1.0.0 LANGUAGES C)
9
+
10
+ # Set C standard project-wide
11
+ set(CMAKE_C_STANDARD 23)
12
+ set(CMAKE_C_STANDARD_REQUIRED ON)
13
+ set(CMAKE_C_EXTENSIONS OFF) # disable GNU extensions for portability
14
+
15
+ # Library target
16
+ add_library(mylib
17
+ src/core.c
18
+ src/parser.c
19
+ src/util.c
20
+ )
21
+
22
+ target_include_directories(mylib
23
+ PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
24
+ PRIVATE src/
25
+ )
26
+
27
+ # Compiler warnings as errors
28
+ target_compile_options(mylib PRIVATE
29
+ $<$<C_COMPILER_ID:GNU,Clang>:-Wall -Wextra -Wpedantic -Werror>
30
+ $<$<C_COMPILER_ID:MSVC>:/W4 /WX>
31
+ )
32
+
33
+ # Sanitizers for debug builds
34
+ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
35
+ target_compile_options(mylib PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer)
36
+ target_link_options(mylib PRIVATE -fsanitize=address,undefined)
37
+ endif()
38
+
39
+ # Tests
40
+ enable_testing()
41
+ add_executable(test_core tests/test_core.c)
42
+ target_link_libraries(test_core PRIVATE mylib)
43
+ add_test(NAME test_core COMMAND test_core)
44
+
45
+ # Install rules
46
+ install(TARGETS mylib EXPORT mylibTargets)
47
+ install(DIRECTORY include/ DESTINATION include)
48
+ ```
49
+
50
+ ## Meson Build System
51
+
52
+ ```meson
53
+ # meson.build — lightweight alternative to CMake
54
+ project('mylib', 'c',
55
+ version: '1.0.0',
56
+ default_options: ['c_std=c23', 'warning_level=3', 'werror=true']
57
+ )
58
+
59
+ src = files('src/core.c', 'src/parser.c', 'src/util.c')
60
+ inc = include_directories('include')
61
+
62
+ mylib = library('mylib', src, include_directories: inc)
63
+ mylib_dep = declare_dependency(link_with: mylib, include_directories: inc)
64
+
65
+ # Tests
66
+ test_core = executable('test_core', 'tests/test_core.c', dependencies: mylib_dep)
67
+ test('core', test_core)
68
+ ```
69
+
70
+ ## Cross-Compilation
71
+
72
+ ```cmake
73
+ # toolchain-arm.cmake — cross-compile for ARM
74
+ set(CMAKE_SYSTEM_NAME Linux)
75
+ set(CMAKE_SYSTEM_PROCESSOR arm)
76
+
77
+ set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
78
+ set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
79
+
80
+ set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabihf)
81
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
82
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
83
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
84
+ ```
85
+
86
+ ```bash
87
+ # Build with cross-compilation toolchain
88
+ cmake -B build-arm -DCMAKE_TOOLCHAIN_FILE=toolchain-arm.cmake
89
+ cmake --build build-arm
90
+ ```
91
+
92
+ ## CI Matrix Configuration
93
+
94
+ ```yaml
95
+ # GitHub Actions — multi-compiler, multi-platform
96
+ jobs:
97
+ build:
98
+ strategy:
99
+ matrix:
100
+ os: [ubuntu-latest, macos-latest]
101
+ compiler: [gcc-13, clang-17]
102
+ runs-on: ${{ matrix.os }}
103
+ steps:
104
+ - uses: actions/checkout@v4
105
+ - name: Configure
106
+ run: |
107
+ cmake -B build \
108
+ -DCMAKE_C_COMPILER=${{ matrix.compiler }} \
109
+ -DCMAKE_BUILD_TYPE=Debug
110
+ - name: Build
111
+ run: cmake --build build
112
+ - name: Test
113
+ run: ctest --test-dir build --output-on-failure
114
+ - name: Sanitizer build
115
+ run: |
116
+ cmake -B build-san \
117
+ -DCMAKE_C_COMPILER=${{ matrix.compiler }} \
118
+ -DCMAKE_BUILD_TYPE=Debug \
119
+ -DENABLE_SANITIZERS=ON
120
+ cmake --build build-san
121
+ ctest --test-dir build-san
122
+ ```
123
+
124
+ ## Dependency Management
125
+
126
+ ```cmake
127
+ # FetchContent for pinned dependencies
128
+ include(FetchContent)
129
+
130
+ FetchContent_Declare(cjson
131
+ GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
132
+ GIT_TAG v1.7.17 # pin exact version
133
+ )
134
+ FetchContent_MakeAvailable(cjson)
135
+ target_link_libraries(mylib PRIVATE cjson)
136
+
137
+ # vcpkg for larger dependency sets
138
+ # Install: cmake -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
139
+ ```
140
+
141
+ ## Reproducible Builds Checklist
142
+
143
+ 1. Pin compiler version in CI (e.g., `gcc-13`, not `gcc`).
144
+ 2. Pin all external dependencies to exact versions or commit hashes.
145
+ 3. Use deterministic build flags (`-frandom-seed=`, `-ffile-prefix-map=`).
146
+ 4. Commit `CMakePresets.json` or equivalent for consistent local/CI builds.
147
+ 5. Disable compiler plugins and extensions that vary by environment.
148
+ 6. Verify with two independent builds and `diffoscope` or binary hash comparison.
@@ -0,0 +1,166 @@
1
+ # Common Undefined Behavior and Portability
2
+
3
+ ## Undefined Behavior Catalog
4
+
5
+ These are the most common sources of UB in C code. Sanitizers catch many at runtime, but prevention through coding discipline is the primary defense.
6
+
7
+ ### Signed Integer Overflow
8
+
9
+ ```c
10
+ // UB — signed overflow is undefined in C
11
+ int x = INT_MAX;
12
+ x += 1; // UB: compiler may assume this never happens and optimize accordingly
13
+
14
+ // SAFE — check before arithmetic
15
+ if (x <= INT_MAX - 1) {
16
+ x += 1;
17
+ }
18
+
19
+ // SAFE — use unsigned for wrapping arithmetic
20
+ unsigned int y = UINT_MAX;
21
+ y += 1; // defined: wraps to 0
22
+ ```
23
+
24
+ ### Null Pointer Dereference
25
+
26
+ ```c
27
+ // UB — dereferencing NULL
28
+ int *p = NULL;
29
+ int val = *p; // UB
30
+
31
+ // SAFE — check before dereference
32
+ if (p != NULL) {
33
+ int val = *p;
34
+ }
35
+
36
+ // Gotcha: compiler may remove NULL checks after dereference
37
+ int val = *p; // if this executes, compiler assumes p != NULL
38
+ if (p == NULL) { ... } // compiler may optimize this away as "unreachable"
39
+ ```
40
+
41
+ ### Buffer Overflow and Out-of-Bounds Access
42
+
43
+ ```c
44
+ // UB — reading/writing past allocation
45
+ int arr[10];
46
+ arr[10] = 42; // UB: index 10 is one past the end
47
+
48
+ // UB — string function overflow
49
+ char buf[8];
50
+ strcpy(buf, "this string is too long"); // UB: writes past buf
51
+
52
+ // SAFE — use bounded functions
53
+ char buf[8];
54
+ strncpy(buf, source, sizeof(buf) - 1);
55
+ buf[sizeof(buf) - 1] = '\0'; // ensure null termination
56
+
57
+ // Better: use snprintf for formatted strings
58
+ snprintf(buf, sizeof(buf), "%s", source);
59
+ ```
60
+
61
+ ### Use After Free and Double Free
62
+
63
+ ```c
64
+ // UB — use after free
65
+ char *data = malloc(100);
66
+ free(data);
67
+ data[0] = 'x'; // UB: data is freed
68
+
69
+ // UB — double free
70
+ free(data);
71
+ free(data); // UB: second free on already-freed pointer
72
+
73
+ // SAFE — NULL after free
74
+ free(data);
75
+ data = NULL; // prevents use-after-free (dereference NULL → crash, not silent corruption)
76
+ ```
77
+
78
+ ### Strict Aliasing Violations
79
+
80
+ ```c
81
+ // UB — accessing memory through incompatible pointer type
82
+ float f = 3.14f;
83
+ int *ip = (int *)&f;
84
+ int bits = *ip; // UB: strict aliasing violation
85
+
86
+ // SAFE — use memcpy for type punning
87
+ float f = 3.14f;
88
+ int bits;
89
+ memcpy(&bits, &f, sizeof(bits)); // defined behavior
90
+
91
+ // SAFE — union-based type punning (C99+, implementation-defined but widely supported)
92
+ union { float f; int i; } u;
93
+ u.f = 3.14f;
94
+ int bits = u.i;
95
+ ```
96
+
97
+ ### Uninitialized Variable Reads
98
+
99
+ ```c
100
+ // UB — reading uninitialized automatic variable
101
+ int x;
102
+ printf("%d\n", x); // UB: x has indeterminate value
103
+
104
+ // SAFE — always initialize
105
+ int x = 0;
106
+ ```
107
+
108
+ ## Implementation-Defined Behavior Traps
109
+
110
+ These are defined by the compiler/platform but differ across implementations:
111
+
112
+ | Behavior | Varies by | Recommendation |
113
+ | ----------------------------- | ------------------- | ----------------------------------------------------------------- |
114
+ | `sizeof(int)` | Platform | Use fixed-width types (`int32_t`, `uint64_t`) for data structures |
115
+ | Bit-shift of negative values | Compiler | Avoid shifting signed integers; use unsigned |
116
+ | Struct padding and alignment | Compiler + platform | Use `offsetof`, `_Alignof`; pack with attributes only when needed |
117
+ | Char signedness (`char`) | Compiler | Use `signed char` or `unsigned char` explicitly for arithmetic |
118
+ | Evaluation order of arguments | Compiler | Avoid side effects in function argument expressions |
119
+
120
+ ## Cross-Platform Portability
121
+
122
+ ```c
123
+ // Use fixed-width integers for portable data structures
124
+ #include <stdint.h>
125
+
126
+ typedef struct {
127
+ uint32_t id;
128
+ int64_t timestamp;
129
+ uint16_t flags;
130
+ } __attribute__((packed)) WireMessage; // packed for network protocol
131
+
132
+ // Endianness-safe serialization
133
+ #include <arpa/inet.h> // or use manual byte swapping
134
+
135
+ void serialize(const WireMessage *msg, uint8_t *buf) {
136
+ uint32_t id_be = htonl(msg->id);
137
+ memcpy(buf, &id_be, sizeof(id_be));
138
+ // ... continue for other fields
139
+ }
140
+
141
+ // Feature detection with preprocessor
142
+ #if defined(__linux__)
143
+ #include <sys/epoll.h>
144
+ #elif defined(__APPLE__)
145
+ #include <sys/event.h>
146
+ #elif defined(_WIN32)
147
+ #include <winsock2.h>
148
+ #endif
149
+ ```
150
+
151
+ ## Compiler Warning Flags for UB Detection
152
+
153
+ ```bash
154
+ # GCC — maximum diagnostic coverage
155
+ gcc -Wall -Wextra -Wpedantic -Werror \
156
+ -Wformat=2 -Wformat-overflow -Wformat-truncation \
157
+ -Wconversion -Wsign-conversion \
158
+ -Wshadow -Wdouble-promotion \
159
+ -Wnull-dereference -Wuninitialized \
160
+ -Wstrict-aliasing=2 \
161
+ -fstack-protector-strong
162
+
163
+ # Clang — additional checks
164
+ clang -Weverything -Wno-padded -Wno-disabled-macro-expansion \
165
+ -fsanitize=undefined,address
166
+ ```
@@ -0,0 +1,205 @@
1
+ # Debugging with Sanitizers
2
+
3
+ ## AddressSanitizer (ASan)
4
+
5
+ Detects: buffer overflow, use-after-free, use-after-return, double-free, memory leaks.
6
+
7
+ ```bash
8
+ # Compile with ASan
9
+ gcc -fsanitize=address -fno-omit-frame-pointer -g -O1 -o myapp myapp.c
10
+ clang -fsanitize=address -fno-omit-frame-pointer -g -O1 -o myapp myapp.c
11
+
12
+ # Run — crashes with detailed report on first error
13
+ ./myapp
14
+ # Output shows: error type, stack trace, shadow memory state
15
+ ```
16
+
17
+ ```c
18
+ // ASan catches this at runtime
19
+ void trigger_heap_overflow(void) {
20
+ int *arr = malloc(10 * sizeof(int));
21
+ arr[10] = 42; // heap-buffer-overflow detected
22
+ free(arr);
23
+ }
24
+
25
+ // ASan catches use-after-free
26
+ void trigger_uaf(void) {
27
+ int *p = malloc(sizeof(int));
28
+ free(p);
29
+ *p = 42; // heap-use-after-free detected
30
+ }
31
+ ```
32
+
33
+ ### ASan Options
34
+
35
+ ```bash
36
+ # Environment variable to control ASan behavior
37
+ export ASAN_OPTIONS="detect_leaks=1:halt_on_error=0:print_stats=1"
38
+
39
+ # detect_leaks=1 — also report memory leaks at exit
40
+ # halt_on_error=0 — continue after first error (find multiple issues)
41
+ # print_stats=1 — show memory allocation statistics
42
+ # suppressions=file — suppress known false positives
43
+ ```
44
+
45
+ ## UndefinedBehaviorSanitizer (UBSan)
46
+
47
+ Detects: signed integer overflow, null pointer dereference, misaligned access, shift overflow, division by zero.
48
+
49
+ ```bash
50
+ # Compile with UBSan
51
+ gcc -fsanitize=undefined -fno-omit-frame-pointer -g -o myapp myapp.c
52
+
53
+ # Common sub-sanitizers (can be selected individually)
54
+ gcc -fsanitize=signed-integer-overflow,null,alignment,shift -g -o myapp myapp.c
55
+ ```
56
+
57
+ ```c
58
+ // UBSan detects signed overflow
59
+ int overflow(void) {
60
+ int x = INT_MAX;
61
+ return x + 1; // runtime error: signed integer overflow
62
+ }
63
+
64
+ // UBSan detects misaligned access
65
+ void misaligned(void) {
66
+ char buf[8] = {0};
67
+ int *p = (int *)(buf + 1); // misaligned pointer
68
+ *p = 42; // runtime error: misaligned access
69
+ }
70
+ ```
71
+
72
+ ## ThreadSanitizer (TSan)
73
+
74
+ Detects: data races, lock-order violations, deadlocks.
75
+
76
+ ```bash
77
+ # Compile with TSan (cannot combine with ASan)
78
+ gcc -fsanitize=thread -fno-omit-frame-pointer -g -o myapp myapp.c -lpthread
79
+ ```
80
+
81
+ ```c
82
+ // TSan detects this data race
83
+ static int counter = 0;
84
+
85
+ void *increment(void *arg) {
86
+ (void)arg;
87
+ for (int i = 0; i < 1000; i++) {
88
+ counter++; // data race: unsynchronized access
89
+ }
90
+ return NULL;
91
+ }
92
+
93
+ // Fix: use mutex or atomic
94
+ #include <stdatomic.h>
95
+ static atomic_int counter = 0;
96
+
97
+ void *increment_safe(void *arg) {
98
+ (void)arg;
99
+ for (int i = 0; i < 1000; i++) {
100
+ atomic_fetch_add(&counter, 1); // no race
101
+ }
102
+ return NULL;
103
+ }
104
+ ```
105
+
106
+ ## MemorySanitizer (MSan) — Clang Only
107
+
108
+ Detects: reads of uninitialized memory.
109
+
110
+ ```bash
111
+ # Clang-only (not available in GCC)
112
+ clang -fsanitize=memory -fno-omit-frame-pointer -g -O1 -o myapp myapp.c
113
+
114
+ # All linked libraries must also be compiled with MSan
115
+ # Use with libc++ compiled with MSan for best results
116
+ ```
117
+
118
+ ## GDB / LLDB Debugging Workflow
119
+
120
+ ```bash
121
+ # Compile for debugging
122
+ gcc -g -O0 -o myapp myapp.c
123
+
124
+ # GDB basics
125
+ gdb ./myapp
126
+ (gdb) break main # set breakpoint
127
+ (gdb) run # start execution
128
+ (gdb) next # step over
129
+ (gdb) step # step into
130
+ (gdb) print variable # inspect variable
131
+ (gdb) backtrace # show call stack
132
+ (gdb) watch *ptr # break when memory changes
133
+ (gdb) info threads # list threads
134
+ (gdb) thread 2 # switch to thread 2
135
+
136
+ # LLDB equivalents
137
+ lldb ./myapp
138
+ (lldb) breakpoint set -n main
139
+ (lldb) run
140
+ (lldb) thread step-over
141
+ (lldb) thread step-in
142
+ (lldb) frame variable
143
+ (lldb) thread backtrace
144
+ (lldb) watchpoint set variable counter
145
+ ```
146
+
147
+ ## Core Dump Analysis
148
+
149
+ ```bash
150
+ # Enable core dumps
151
+ ulimit -c unlimited
152
+
153
+ # Set core dump pattern (Linux)
154
+ echo "/tmp/core.%e.%p" | sudo tee /proc/sys/kernel/core_pattern
155
+
156
+ # Analyze core dump
157
+ gdb ./myapp /tmp/core.myapp.12345
158
+ (gdb) backtrace # see where it crashed
159
+ (gdb) frame 3 # examine specific frame
160
+ (gdb) info locals # see local variables
161
+ ```
162
+
163
+ ## Valgrind (Alternative to ASan)
164
+
165
+ ```bash
166
+ # Memory error detection
167
+ valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./myapp
168
+
169
+ # Cache profiling
170
+ valgrind --tool=cachegrind ./myapp
171
+ cg_annotate cachegrind.out.<pid>
172
+
173
+ # Call graph profiling
174
+ valgrind --tool=callgrind ./myapp
175
+ kcachegrind callgrind.out.<pid>
176
+ ```
177
+
178
+ ## Sanitizer Compatibility Matrix
179
+
180
+ | Sanitizer | GCC | Clang | Combinable with |
181
+ | ---------------- | --- | ----- | ----------------------- |
182
+ | AddressSanitizer | Yes | Yes | UBSan |
183
+ | UBSan | Yes | Yes | ASan, MSan, TSan |
184
+ | ThreadSanitizer | Yes | Yes | UBSan |
185
+ | MemorySanitizer | No | Yes | UBSan |
186
+ | LeakSanitizer | Yes | Yes | ASan (often integrated) |
187
+
188
+ Cannot combine: ASan + TSan, ASan + MSan, TSan + MSan.
189
+
190
+ ## CI Integration
191
+
192
+ ```bash
193
+ # Run multiple sanitizer builds in CI
194
+ # Build 1: ASan + UBSan
195
+ cmake -B build-asan -DCMAKE_C_FLAGS="-fsanitize=address,undefined -g -O1"
196
+ cmake --build build-asan && ctest --test-dir build-asan
197
+
198
+ # Build 2: TSan (separate because incompatible with ASan)
199
+ cmake -B build-tsan -DCMAKE_C_FLAGS="-fsanitize=thread -g -O1"
200
+ cmake --build build-tsan && ctest --test-dir build-tsan
201
+
202
+ # Build 3: Regular optimized build (for performance tests)
203
+ cmake -B build-release -DCMAKE_BUILD_TYPE=Release
204
+ cmake --build build-release && ctest --test-dir build-release
205
+ ```
@@ -0,0 +1,60 @@
1
+ # Memory Safety and Build Checklist
2
+
3
+ ## Ownership rules
4
+
5
+ - Every heap allocation has exactly one owner. Document who allocates and who frees.
6
+ - Functions that return allocated memory must document whether the caller owns the result.
7
+ - Functions that receive pointers must document whether they borrow or take ownership.
8
+ - Use naming conventions to signal ownership: `create_*` allocates (caller frees), `get_*` borrows (caller must not free).
9
+
10
+ ## Buffer safety
11
+
12
+ - Always pass buffer size alongside buffer pointer. Never rely on null terminators for binary data.
13
+ - Check return values of `snprintf`, `read`, `recv` — they may write fewer bytes than requested.
14
+ - Use `sizeof(array)` only on stack-allocated arrays, never on decayed pointers.
15
+ - Prefer bounded variants: `strnlen` over `strlen`, `snprintf` over `sprintf`, `strncpy` with explicit termination.
16
+
17
+ ## Initialization
18
+
19
+ - Initialize all stack variables at declaration. Uninitialized reads are undefined behavior.
20
+ - Zero-initialize structs with `= {0}` or `memset` before populating fields.
21
+ - Use compound literals `(struct Foo){.field = val}` for partial initialization — remaining fields are zero.
22
+
23
+ ## Arena allocator pattern
24
+
25
+ ```c
26
+ // Simple arena: bump allocator with single free at scope end
27
+ typedef struct { char *base; size_t offset; size_t capacity; } Arena;
28
+ void *arena_alloc(Arena *a, size_t size); // bump offset, return pointer
29
+ void arena_reset(Arena *a); // reset offset to 0
30
+ ```
31
+
32
+ - Allocate arena at scope entry, reset or free at scope exit. No per-object free needed.
33
+ - Useful for request-scoped or frame-scoped allocations (servers, games, parsers).
34
+
35
+ ## Sanitizer configuration
36
+
37
+ | Sanitizer | Flag | Catches |
38
+ | -------------------------- | -------------------------------- | ------------------------------------------------------------- |
39
+ | AddressSanitizer | `-fsanitize=address` | Use-after-free, buffer overflow, stack overflow, memory leaks |
40
+ | UndefinedBehaviorSanitizer | `-fsanitize=undefined` | Signed overflow, null deref, alignment, shift out of range |
41
+ | ThreadSanitizer | `-fsanitize=thread` | Data races, lock order violations |
42
+ | MemorySanitizer | `-fsanitize=memory` (Clang only) | Reads of uninitialized memory |
43
+
44
+ - Run ASAN + UBSAN together in CI debug builds. TSAN requires a separate build (incompatible with ASAN).
45
+ - Set `ASAN_OPTIONS=detect_leaks=1:halt_on_error=1` for strict leak detection.
46
+
47
+ ## Build system hygiene
48
+
49
+ - Pin compiler version in CI (e.g., `gcc-13`, `clang-17`). Document minimum required version.
50
+ - Use `-Wall -Wextra -Werror -Wpedantic -Wconversion -Wshadow` for maximum diagnostic coverage.
51
+ - Run builds on at least GCC + Clang. They catch different issues.
52
+ - Use `compile_commands.json` (CMake: `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`) for IDE and static analyzer integration.
53
+ - Enable LTO (`-flto`) for release builds. Verify with tests — LTO can expose bugs that per-TU compilation hides.
54
+
55
+ ## ABI boundary review
56
+
57
+ - Export only the minimum necessary symbols. Use `__attribute__((visibility("default")))` or export maps.
58
+ - Keep struct layouts stable across versions. Add fields at the end, never reorder.
59
+ - Use opaque pointers (`typedef struct Foo Foo;`) for types whose layout callers should not depend on.
60
+ - Version-check shared libraries at load time when ABI stability is critical.