Skip to content

Commit 446e14e

Browse files
committed
Improve: Build & test reproducibility
1 parent 930b1f0 commit 446e14e

File tree

7 files changed

+103
-75
lines changed

7 files changed

+103
-75
lines changed

.github/workflows/prerelease.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ jobs:
308308
309309
- name: Build C/C++ with CUDA
310310
run: |
311+
# Note: Using Release build type instead of RelWithDebInfo
312+
# Optimized debugging not supported in CUDA and results in PTXAS fatal errors
311313
cmake -B build_artifacts \
312-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
314+
-DCMAKE_BUILD_TYPE=Release \
313315
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
314316
-DSTRINGZILLA_BUILD_BENCHMARK=1 \
315317
-DSTRINGZILLA_BUILD_TEST=1
316318
317-
cmake --build build_artifacts --config RelWithDebInfo > build_artifacts/logs.txt 2>&1 || {
319+
cmake --build build_artifacts --config Release > build_artifacts/logs.txt 2>&1 || {
318320
echo "Compilation failed. Here are the logs:"
319321
cat build_artifacts/logs.txt
320322
echo "The original compilation commands:"

CMakeLists.txt

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ include(GNUInstallDirs)
153153
set(STRINGZILLA_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
154154
set(STRINGZILLA_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
155155

156-
if (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13)
156+
if (CMAKE_VERSION VERSION_EQUAL 3.13 OR CMAKE_VERSION VERSION_GREATER 3.13)
157157
include(CTest)
158158
enable_testing()
159159
endif ()
@@ -182,53 +182,52 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
182182
endforeach ()
183183

184184
# Set the C++ standard
185-
if (NOT ${cpp_standard} STREQUAL "")
186-
if (${compiler_id} STREQUAL "NVIDIA")
185+
if (NOT cpp_standard STREQUAL "")
186+
if (compiler_id STREQUAL "NVIDIA")
187187
set_target_properties(${target} PROPERTIES CUDA_STANDARD ${cpp_standard})
188-
elseif (${compiler_id} MATCHES "MSVC")
189-
# For MSVC, explicitly set the /std: flag
188+
elseif (compiler_id MATCHES "MSVC")
189+
# For MSVC, explicitly set the /std: flag - don't set CXX_STANDARD property to avoid conflicts
190190
target_compile_options(${target} PRIVATE "/std:c++${cpp_standard}")
191191
else ()
192192
set_target_properties(${target} PROPERTIES CXX_STANDARD ${cpp_standard})
193193
endif ()
194194
endif ()
195195

196196
# Use the `/Zc:__cplusplus` flag to correctly define the `__cplusplus` macro in MSVC
197-
if (${compiler_id} MATCHES "MSVC")
197+
if (compiler_id MATCHES "MSVC")
198198
target_compile_options(${target} PRIVATE "/Zc:__cplusplus")
199199
endif ()
200200

201201
# Make sure CUDA C++ allows calling `constexpr` from device code
202-
if (${compiler_id} STREQUAL "NVIDIA")
202+
if (compiler_id STREQUAL "NVIDIA")
203203
target_compile_options(${target} PRIVATE "--expt-relaxed-constexpr")
204204
endif ()
205205

206206
# Maximum warnings level & warnings as error.
207207
#
208208
# MSVC uses numeric values: > 4068 for "unknown pragmas". > 4146 for "unary minus operator applied to unsigned type,
209209
# result still unsigned". We also specify `/utf-8` to properly UTF-8 symbols in tests.
210-
if (${compiler_id} STREQUAL "GNU")
210+
if (compiler_id STREQUAL "GNU")
211211
target_compile_options(
212212
${target}
213213
PRIVATE
214214
"-Wall;-Wextra;-pedantic;-Werror;-Wfatal-errors;-Wno-unknown-pragmas;-Wno-cast-function-type;-Wno-unused-function"
215215
)
216216
target_compile_options(${target} PRIVATE "-Wno-cast-function-type;-Wno-unused-function") # ? Unique to GCC
217-
elseif (${compiler_id} STREQUAL "Clang" OR ${compiler_id} STREQUAL "AppleClang")
217+
elseif (compiler_id STREQUAL "Clang" OR compiler_id STREQUAL "AppleClang")
218218
target_compile_options(${target} PRIVATE "-Wall;-Wextra;-pedantic;-Werror;-Wfatal-errors;-Wno-unknown-pragmas")
219-
elseif (${compiler_id} MATCHES "MSVC")
219+
elseif (compiler_id MATCHES "MSVC")
220220
target_compile_options(
221221
${target}
222-
PRIVATE
223-
"/Bt" # Display build timings
224-
"/wd4068" # Disable warning: unknown pragma
225-
"/wd4146" # Disable warning: unary minus operator applied to unsigned type
226-
"/wd4996" # Disable warning: 'unsafe' functions like getenv, fopen (use _s variants)
227-
"/wd4244" # Disable warning: conversion with possible loss of data (e.g., size_t to double)
228-
"/utf-8" # Set source and execution character sets to UTF-8
229-
"/WX" # Treat warnings as errors
222+
PRIVATE "/Bt" # Display build timings
223+
"/wd4068" # Disable warning: unknown pragma
224+
"/wd4146" # Disable warning: unary minus operator applied to unsigned type
225+
"/wd4996" # Disable warning: 'unsafe' functions like getenv, fopen (use _s variants)
226+
"/wd4244" # Disable warning: conversion with possible loss of data (e.g., size_t to double)
227+
"/utf-8" # Set source and execution character sets to UTF-8
228+
"/WX" # Treat warnings as errors
230229
)
231-
elseif (${compiler_id} STREQUAL "NVIDIA")
230+
elseif (compiler_id STREQUAL "NVIDIA")
232231
target_compile_options(
233232
${target}
234233
PRIVATE
@@ -237,46 +236,44 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
237236
endif ()
238237

239238
# Set optimization options for different compilers differently
240-
if (${compiler_id} MATCHES "MSVC")
241-
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
239+
if (compiler_id MATCHES "MSVC")
240+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
242241
target_compile_options(${target} PRIVATE "/Od;/Zi")
243242
if (NOT target_type STREQUAL "SHARED_LIBRARY")
244243
target_compile_options(${target} PRIVATE "/RTC1")
245244
endif ()
246-
endif ()
247-
if (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
245+
elseif (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
248246
target_compile_options(${target} PRIVATE "/O2;/Zi")
249247
endif ()
250248
elseif (
251-
${compiler_id} STREQUAL "GNU"
252-
OR ${compiler_id} STREQUAL "Clang"
253-
OR ${compiler_id} STREQUAL "AppleClang"
249+
compiler_id STREQUAL "GNU"
250+
OR compiler_id STREQUAL "Clang"
251+
OR compiler_id STREQUAL "AppleClang"
254252
)
255-
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
253+
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
256254
target_compile_options(${target} PRIVATE "-O0;-g")
257255
endif ()
258-
if (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
256+
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
259257
target_compile_options(${target} PRIVATE "-O2")
260258
endif ()
261-
elseif (${compiler_id} STREQUAL "NVIDIA")
259+
elseif (compiler_id STREQUAL "NVIDIA")
262260
target_compile_options(
263261
${target} PRIVATE "-Xcompiler=-Wall" # All warnings (host)
264262
"-Xcompiler=-Wextra" # Extra warnings (host)
265263
)
266264

267-
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
265+
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
268266
target_compile_options(
269267
${target}
270-
PRIVATE "-G" # Device debug symbols
271-
"-lineinfo" # Include source line info in PTX
268+
PRIVATE "-G" # Device debug symbols, which will add `-lineinfo` symbols to PTX
272269
"-no-compress" # No compression of debug info
273270
"-Xcompiler=-g" # Host debugging symbols explicitly
274271
"-Xcompiler=-fno-omit-frame-pointer" # Stack trace clarity
275272
"-Xcompiler=-fno-inline" # Prevent host inlining
276273
"-maxrregcount=0" # No register count limits
277274
)
278275
endif ()
279-
if (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
276+
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
280277
target_compile_options(
281278
${target}
282279
PRIVATE "-O2" # Disable NVCC optimizations explicitly
@@ -293,7 +290,7 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
293290
endif ()
294291

295292
# Avoid builtin functions where we know what we are doing.
296-
if (${compiler_id} MATCHES "MSVC")
293+
if (compiler_id MATCHES "MSVC")
297294
target_compile_options(${target} PRIVATE "/Oi-")
298295
else ()
299296
target_compile_options(${target} PRIVATE "-fno-builtin-memcmp")
@@ -306,14 +303,14 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
306303
if ("${target_arch}" STREQUAL "")
307304
# Only use the current system if we are not cross compiling
308305
if ((NOT CMAKE_CROSSCOMPILING) OR (CMAKE_SYSTEM_PROCESSOR MATCHES CMAKE_HOST_SYSTEM_PROCESSOR))
309-
if (${compiler_id} STREQUAL "NVIDIA")
306+
if (compiler_id STREQUAL "NVIDIA")
310307
# For NVCC, pass native flag to host compiler
311308
include(CheckCXXCompilerFlag)
312309
check_cxx_compiler_flag("-march=native" supports_march_native)
313310
if (supports_march_native)
314311
target_compile_options(${target} PRIVATE "-Xcompiler=-march=native")
315312
endif ()
316-
elseif (NOT (${compiler_id} MATCHES "MSVC"))
313+
elseif (NOT (compiler_id MATCHES "MSVC"))
317314
include(CheckCXXCompilerFlag)
318315
check_cxx_compiler_flag("-march=native" supports_march_native)
319316
if (supports_march_native)
@@ -325,9 +322,9 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
325322
endif ()
326323
endif ()
327324
else ()
328-
if (${compiler_id} MATCHES "MSVC")
325+
if (compiler_id MATCHES "MSVC")
329326
target_compile_options(${target} PRIVATE "/arch:${target_arch}")
330-
elseif (${compiler_id} STREQUAL "NVIDIA")
327+
elseif (compiler_id STREQUAL "NVIDIA")
331328
# NVCC handles CPU architecture through host compiler flags
332329
target_compile_options(${target} PRIVATE "-Xcompiler=-march=${target_arch}")
333330
else ()
@@ -348,10 +345,10 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
348345
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
349346
target_compile_definitions(${target} PRIVATE "SZ_DEBUG=1")
350347
if (NOT target_type STREQUAL "SHARED_LIBRARY")
351-
if (${compiler_id} MATCHES "MSVC")
348+
if (compiler_id MATCHES "MSVC")
352349
target_compile_options(${target} PRIVATE "/fsanitize=address;/fsanitize=leak")
353350
target_link_options(${target} PRIVATE "/fsanitize=address;/fsanitize=leak")
354-
elseif (${compiler_id} STREQUAL "NVIDIA")
351+
elseif (compiler_id STREQUAL "NVIDIA")
355352
# ! NVCC can't handle sanitizers?!
356353
# https://stackoverflow.com/questions/75590579/cuda-fails-to-initialise-when-address-sanitizer-is-enabled
357354
else ()
@@ -367,8 +364,9 @@ endfunction ()
367364
function (define_launcher exec_name source cpp_standard target_arch)
368365
add_executable(${exec_name})
369366
target_sources(${exec_name} PRIVATE ${source})
370-
# TODO: How do we constrain this scope?! set_source_files_properties(${source} TARGET_DIRECTORY ${exec_name}
371-
# PROPERTIES LANGUAGE CXX)
367+
# TODO: How do we constrain this scope?!
368+
#
369+
# set_source_files_properties(${source} TARGET_DIRECTORY ${exec_name} PROPERTIES LANGUAGE CXX)
372370
set_compiler_flags(${exec_name} ${cpp_standard} "${target_arch}" "${CMAKE_CXX_COMPILER_ID}")
373371
target_link_libraries(${exec_name} PRIVATE stringzilla_header)
374372
add_test(NAME ${exec_name} COMMAND ${exec_name})
@@ -389,7 +387,7 @@ function (define_gpu_launcher exec_name source cuda_standard target_arch)
389387
add_test(NAME ${exec_name} COMMAND ${exec_name})
390388
endfunction ()
391389

392-
if (${STRINGZILLA_BUILD_BENCHMARK})
390+
if (STRINGZILLA_BUILD_BENCHMARK)
393391
define_launcher(stringzilla_bench_find_cpp20 scripts/bench_find.cpp 20 "${STRINGZILLA_TARGET_ARCH}")
394392
define_launcher(stringzilla_bench_sequence_cpp20 scripts/bench_sequence.cpp 20 "${STRINGZILLA_TARGET_ARCH}")
395393
define_launcher(stringzilla_bench_token_cpp20 scripts/bench_token.cpp 20 "${STRINGZILLA_TARGET_ARCH}")
@@ -413,7 +411,7 @@ if (${STRINGZILLA_BUILD_BENCHMARK})
413411
endif ()
414412
endif ()
415413

416-
if (${STRINGZILLA_BUILD_TEST})
414+
if (STRINGZILLA_BUILD_TEST)
417415
# Make sure that the compilation passes for different C++ standards!
418416
#
419417
# Keep in mind, MSVC only supports C++11 and newer.
@@ -462,14 +460,14 @@ if (${STRINGZILLA_BUILD_TEST})
462460
define_launcher(stringzilla_test_cpp20_serial scripts/test_stringzilla.cpp 20 "armv8-a")
463461
define_launcher(stringzilla_test_cpp20_neon scripts/test_stringzilla.cpp 20 "armv8-a+simd")
464462
# SVE is not supported on Apple Silicon, only compile on non-Darwin ARM platforms
465-
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
463+
if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
466464
define_launcher(stringzilla_test_cpp20_sve scripts/test_stringzilla.cpp 20 "armv8.2-a+sve")
467465
endif ()
468466
if (STRINGZILLA_BUILD_CUDA)
469467
define_gpu_launcher(stringzillas_test_cu20_serial scripts/test_stringzillas.cu 20 "armv8-a")
470468
define_gpu_launcher(stringzillas_test_cu20_neon scripts/test_stringzillas.cu 20 "armv8-a+simd")
471469
# SVE is not supported on Apple Silicon, only compile on non-Darwin ARM platforms
472-
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
470+
if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
473471
define_gpu_launcher(stringzillas_test_cu20_sve scripts/test_stringzillas.cu 20 "armv8.2-a+sve")
474472
endif ()
475473
endif ()
@@ -483,7 +481,7 @@ target_include_directories(
483481
stringzilla_header INTERFACE $<BUILD_INTERFACE:${STRINGZILLA_INCLUDE_BUILD_DIR}> $<INSTALL_INTERFACE:include>
484482
)
485483

486-
if (${STRINGZILLA_BUILD_SHARED})
484+
if (STRINGZILLA_BUILD_SHARED)
487485

488486
function (define_shared target)
489487
add_library(${target} SHARED c/stringzilla.c)
@@ -536,7 +534,7 @@ if (${STRINGZILLA_BUILD_SHARED})
536534
# Try compiling a version without linking the LibC ! This is only for Linux, as on modern Arm-based MacOS machines !
537535
# We can't legally access Arm's "feature registers" without `sysctl` or `sysctlbyname`. Also exclude MSVC builds as
538536
# they have linker issues with bare builds.
539-
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
537+
if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
540538
define_shared(stringzilla_bare)
541539
target_compile_definitions(stringzilla_bare PRIVATE "SZ_AVOID_LIBC=1")
542540
target_compile_definitions(stringzilla_bare PRIVATE "SZ_OVERRIDE_LIBC=1")
@@ -548,7 +546,7 @@ if (${STRINGZILLA_BUILD_SHARED})
548546
endif ()
549547
endif ()
550548

551-
if (${STRINGZILLAS_BUILD_SHARED})
549+
if (STRINGZILLAS_BUILD_SHARED)
552550
# StringZillas shared library targets for parallel string operations
553551
function (define_stringzillas_shared target source_file backend_flags)
554552
add_library(${target} SHARED ${source_file})

include/stringzilla/sort.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ SZ_INTERNAL void sz_sequence_argsort_serial_export_next_pgrams_(
375375
sz_ptr_t target_str = (sz_ptr_t)target_pgram;
376376
*target_pgram = 0;
377377
for (sz_size_t j = 0; j < exported_length; ++j) target_str[j] = source_str[j + start_character];
378-
target_str[pgram_capacity] = exported_length;
378+
target_str[pgram_capacity] = (char)exported_length;
379379
#if defined(SZ_IS_64BIT_)
380380
*target_pgram = sz_u64_bytes_reverse(*target_pgram);
381381
#else

include/stringzilla/types.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,15 @@ SZ_PUBLIC void sz_sequence_from_null_terminated_strings(sz_cptr_t *start, sz_siz
979979
#define sz_unused_(x) ((void)(x))
980980

981981
/** @brief Helper-macro casting a variable to another type of the same size. */
982-
#if defined(__has_builtin) && __has_builtin(__builtin_bit_cast)
982+
#if !defined(_MSC_VER) && defined(__has_builtin)
983+
#if __has_builtin(__builtin_bit_cast)
983984
#define sz_bitcast_(type, value) __builtin_bit_cast(type, (value))
984985
#else
985986
#define sz_bitcast_(type, value) (*((type *)&(value)))
986987
#endif
988+
#else
989+
#define sz_bitcast_(type, value) (*((type *)&(value)))
990+
#endif
987991

988992
/**
989993
* @brief Defines `SZ_NULL`, analogous to `NULL`.

scripts/test_stringzilla.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <iterator> // `std::distance`
5555
#include <map> // `std::map`
5656
#include <memory> // `std::allocator`
57+
#include <numeric> // `std::accumulate`
5758
#include <random> // `std::random_device`
5859
#include <sstream> // `std::ostringstream`
5960
#include <unordered_map> // `std::unordered_map`
@@ -235,17 +236,17 @@ void test_memory_allocator_struct() {
235236
void test_byteset_struct() {
236237
sz_byteset_t s;
237238
sz_byteset_init(&s);
238-
assert(sz_byteset_contains(&s, 'a') == false);
239+
assert(sz_byteset_contains(&s, 'a') == sz_false_k);
239240
sz_byteset_add(&s, 'a');
240-
assert(sz_byteset_contains(&s, 'a') == true);
241+
assert(sz_byteset_contains(&s, 'a') == sz_true_k);
241242
sz_byteset_add(&s, 'z');
242-
assert(sz_byteset_contains(&s, 'z') == true);
243+
assert(sz_byteset_contains(&s, 'z') == sz_true_k);
243244
sz_byteset_invert(&s);
244-
assert(sz_byteset_contains(&s, 'a') == false);
245-
assert(sz_byteset_contains(&s, 'z') == false);
246-
assert(sz_byteset_contains(&s, 'b') == true);
245+
assert(sz_byteset_contains(&s, 'a') == sz_false_k);
246+
assert(sz_byteset_contains(&s, 'z') == sz_false_k);
247+
assert(sz_byteset_contains(&s, 'b') == sz_true_k);
247248
sz_byteset_init_ascii(&s);
248-
assert(sz_byteset_contains(&s, 'A') == true);
249+
assert(sz_byteset_contains(&s, 'A') == sz_true_k);
249250
}
250251

251252
/**

scripts/test_stringzilla.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct uniform_u8_distribution_t {
8181
};
8282

8383
inline void randomize_string(char *string, std::size_t length, char const *alphabet, std::size_t cardinality) noexcept {
84-
uniform_u8_distribution_t distribution(0, cardinality - 1);
84+
uniform_u8_distribution_t distribution(0, static_cast<char>(cardinality - 1));
8585
std::generate(string, string + length, [&]() -> char { return alphabet[distribution(global_random_generator())]; });
8686
}
8787

0 commit comments

Comments
 (0)