-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
270 lines (230 loc) · 7.88 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# List all available commands by default
default:
@just --choose --justfile {{justfile()}}
# Recursively format all Nim files in a specific directory
format directory="src":
#!/usr/bin/env bash
find "{{directory}}" -type f -name "*.nim" -print0 | while IFS= read -r -d '' file; do
echo "Formatting $file..."
nph "$file"
done
# Generate test coverage
coverage:
#!/usr/bin/env bash
set -euo pipefail
FILEINFO="lcov.info"
LCOV_ARGS="--rc branch_coverage=1 --ignore-errors inconsistent --ignore-errors range --ignore-errors unused"
GENERATED_FILE="generated_not_to_break_here"
NIMCACHE_DIR="nimcache"
CURRENT_DIR=$(pwd)
# Create nimcache/tests directory if it doesn't exist
mkdir -p "${NIMCACHE_DIR}/tests"
# Find and process test files
find ./tests -name 'test_*.nim' | head -n 2 | while read -r file; do
echo "Processing file: $file"
filename=$(basename "$file")
filename_no_ext="${filename%.nim}"
# Compile test with coverage
nim c \
--nimcache:"${NIMCACHE_DIR}" \
--hints:off \
--debugger:native \
--passC:--coverage \
--passL:--coverage \
-o:"${NIMCACHE_DIR}/tests/${filename_no_ext}" \
"$file"
# Run the compiled test
"${NIMCACHE_DIR}/tests/${filename_no_ext}"
done
# Generate coverage data
touch "${GENERATED_FILE}"
lcov ${LCOV_ARGS} --capture --directory "${NIMCACHE_DIR}" --output-file "${FILEINFO}"
rm "${GENERATED_FILE}"
# Clean up coverage data
lcov ${LCOV_ARGS} --extract "${FILEINFO}" "${CURRENT_DIR}/src/*" -o "${FILEINFO}"
lcov ${LCOV_ARGS} --remove "${FILEINFO}" "${CURRENT_DIR}/tests/*" -o "${FILEINFO}"
# Generate HTML report
genhtml --branch-coverage --ignore-errors missing,range,corrupt,inconsistent --legend --output-directory coverage/ "${FILEINFO}"
# Generate test coverage
test:
#!/usr/bin/env bash
set -euo pipefail
NIMCACHE_DIR="nimcache"
# Create nimcache/tests directory if it doesn't exist
mkdir -p "${NIMCACHE_DIR}/tests"
# Find and process test files
find ./tests -name 'test_*.nim' | head | while read -r file; do
echo "Processing file: $file"
filename=$(basename "$file")
filename_no_ext="${filename%.nim}"
# Step 1: Compile and run with debug flags
nim c \
-d:debug \
-d:nimDebugDlOpen \
--verbosity:0 \
--hints:off \
--cc:clang \
--opt:none \
--debugger:native \
--passc:-fsanitize=address \
--passl:-fsanitize=address \
--stacktrace:on \
-d:useMalloc \
--mm:orc \
--passC:-O0 \
--passC:-g3 \
--passC:-ggdb3 \
--passC:-gdwarf-4 \
--lineDir:on \
--debuginfo:on \
--excessiveStackTrace:on \
-o:"${NIMCACHE_DIR}/tests/${filename_no_ext}" \
"$file"
# Run the compiled test
"${NIMCACHE_DIR}/tests/${filename_no_ext}"
done
# Debug with rr and connect lldb to the specific target
debug-run nim_file="src/duckdb" name="":
#!/usr/bin/env bash
set -euo pipefail
# Extract the base name without extension
BASENAME=$(basename "{{nim_file}}" .nim)
DIRNAME=$(dirname "{{nim_file}}")
OUTPUT_PATH="${DIRNAME}/${BASENAME}"
# Step 1: Compile and run with debug flags
nim c \
-r \
-d:debug \
-d:nimDebugDlOpen \
--cc:clang \
--opt:none \
--debugger:native \
--passc:-fsanitize=address \
--passl:-fsanitize=address \
--stacktrace:on \
-d:useMalloc \
--mm:orc \
--passC:-O0 \
--passC:-g3 \
--passC:-ggdb3 \
--passC:-gdwarf-4 \
--lineDir:on \
--debuginfo:on \
--threads:off \
--excessiveStackTrace:on \
"{{nim_file}}" \
"{{name}}"
# Debug with rr and connect lldb to the specific target
debug nim_file="tests/results/test_result_type.nim":
#!/usr/bin/env bash
set -euo pipefail
# Extract the base name without extension
BASENAME=$(basename "{{nim_file}}" .nim)
DIRNAME=$(dirname "{{nim_file}}")
OUTPUT_PATH="${DIRNAME}/${BASENAME}"
# Step 1: Compile and run with debug flags
nim c \
-d:debug \
-d:nimDebugDlOpen \
--opt:none \
--debugger:native \
--stacktrace:on \
-d:useMalloc \
--mm:orc \
--passC:-O0 \
--passC:-g3 \
--passC:-gdwarf-4 \
--linedir:on \
--debuginfo:on \
--threads:off \
--excessiveStackTrace:on \
"{{nim_file}}"
# Step 2: Record using rr
rr record -M "${OUTPUT_PATH}"
# Step 3: Start rr replay and connect lldb
# Start rr in the background
# rr replay -s 9999 &
rr replay -s 9999 --debugger=nim-gdb
# RR_PID=$!
# Wait a moment for rr to start
sleep 2
# ddd --debugger "nim-gdb -ex 'target remote localhost:9999'" "${OUTPUT_PATH}" &
# # Create a source map file for lldb
# PROJECT_ROOT=$(pwd)
# LLDB_SETTINGS=$(mktemp)
# echo "settings set target.source-map /proc/self/cwd ${PROJECT_ROOT}" > "$LLDB_SETTINGS"
# echo "command script import nimlldb.py" >> "$LLDB_SETTINGS"
# # Launch lldb with enhanced debug settings
# lldb \
# -s "$LLDB_SETTINGS" \
# -o "platform select remote-gdb-server" \
# -o "target create /home/vlad/.local/share/rr/test_result_type-23/mmap_hardlink_4_test_result_type" \
# -o "gdb-remote 127.0.0.1:9999" \
# -o "settings set target.inline-breakpoint-strategy always" \
# -o "settings set target.skip-prologue false"
# # Cleanup
# rm "$LLDB_SETTINGS"
# kill $RR_PID 2>/dev/null || true
# Run Valgrind on a Nim file to analyze memory usage
valgrind nim_file="tests/results/test_result_type.nim" name="":
#!/usr/bin/env bash
set -euo pipefail
# Extract the base name without extension
BASENAME=$(basename "{{nim_file}}" .nim)
DIRNAME=$(dirname "{{nim_file}}")
OUTPUT_PATH="${DIRNAME}/${BASENAME}"
# Step 1: Compile with debug flags (without optimization)
nim c \
-d:debug \
-d:nimDebugDlOpen \
--opt:none \
--debugger:native \
--stacktrace:on \
-d:useMalloc \
--mm:orc \
--passC:-O0 \
--passC:-g3 \
--passC:-gdwarf-4 \
--linedir:on \
--lineDir:on \
--debuginfo:on \
--threads:off \
--excessiveStackTrace:on \
"{{nim_file}}"
# Step 2: Run Valgrind with memory analysis options
valgrind \
--leak-check=full \
--show-leak-kinds=definite,possible \
--track-origins=yes \
--verbose \
"${OUTPUT_PATH}"
# Run with maximum performance compiler flags for benchmarking
benchmark name="":
#!/usr/bin/env bash
set -euo pipefail
NIMCACHE_DIR="nimcache"
# Create nimcache/tests directory if it doesn't exist
mkdir -p "${NIMCACHE_DIR}/benchmarks"
# Find and process test files
find ./benchmarks -name "benchmark_*{{name}}*.nim" | while read -r file; do
echo "Processing file: $file"
filename=$(basename "$file")
filename_no_ext="${filename%.nim}"
nim c \
-r \
-d:release \
-d:danger \
--verbosity:0 \
--hints:off \
--opt:speed \
--panics:on \
--passC:"-flto -march=native -ffast-math -funroll-loops -fopt-info-vec" \
--passL:"-flto" \
-o:"${NIMCACHE_DIR}/benchmarks/${filename_no_ext}" \
"$file"
# --profiler:on --stacktrace:on --linetrace:on
# --debugger:native \
# Run the compiled test
"${NIMCACHE_DIR}/benchmarks/${filename_no_ext}"
echo "Running file: $file"
done