Skip to content

Commit

Permalink
ci: always set values for command line defines (#5126)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart authored Feb 19, 2025
1 parent c936e91 commit c05f76a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ endif ()
if(BUILD_TESTING AND BUILD_SHARED_LIBS OR S2N_FUZZ_TEST)
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=default)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden -DS2N_EXPORTS)
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden -DS2N_EXPORTS=1)
endif()

if(S2N_LTO)
Expand Down Expand Up @@ -197,7 +197,7 @@ target_compile_options(${PROJECT_NAME} PRIVATE -include "${S2N_PRELUDE}")
# Match on Release, RelWithDebInfo and MinSizeRel
# See: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html#variable:CMAKE_BUILD_TYPE
if(CMAKE_BUILD_TYPE MATCHES Rel)
add_definitions(-DS2N_BUILD_RELEASE)
add_definitions(-DS2N_BUILD_RELEASE=1)
endif()

if(NO_STACK_PROTECTOR)
Expand Down Expand Up @@ -316,7 +316,7 @@ function(feature_probe_result PROBE_NAME IS_AVAILABLE)

# define the probe if available
if(NORMALIZED)
add_definitions(-D${PROBE_NAME})
add_definitions(-D${PROBE_NAME}=1)
endif()
endfunction()

Expand Down Expand Up @@ -426,7 +426,7 @@ if (S2N_INTERN_LIBCRYPTO)
DEPENDS libcrypto.symbols
)
add_dependencies(${PROJECT_NAME} s2n_libcrypto)
add_definitions(-DS2N_INTERN_LIBCRYPTO)
add_definitions(-DS2N_INTERN_LIBCRYPTO=1)

if ((BUILD_SHARED_LIBS AND BUILD_TESTING) OR NOT BUILD_SHARED_LIBS)
# if libcrypto needs to be interned, rewrite libcrypto references so use of internal functions will link correctly
Expand Down
14 changes: 14 additions & 0 deletions codebuild/bin/grep_simple_mistakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@

FAILED=0

#############################################
# Grep for command line defines without values
#############################################
EMPTY_DEFINES=$(grep -Eon "\-D[^=]+=?" CMakeLists.txt | grep -v =)
if [ ! -z "${EMPTY_DEFINES}" ]; then
FAILED=1
printf "\e[1;34mCommand line define is missing value:\e[0m "
printf "Compilers SHOULD set a default value of 1 when no default is given, "
printf "but that behavior is not required by any official spec. Set a value just in case. "
printf "For example: -DS2N_FOO=1 instead of -DS2N_FOO.\n"
printf "Found: \n"
echo "$EMPTY_DEFINES"
fi

#############################################
# Grep for bindings methods without C documentation links.
#############################################
Expand Down
2 changes: 1 addition & 1 deletion s2n.mk
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bindir ?= $(exec_prefix)/bin
libdir ?= $(exec_prefix)/lib64
includedir ?= $(exec_prefix)/include

feature_probe = $(shell $(CC) $(CFLAGS) $(shell cat $(S2N_ROOT)/tests/features/GLOBAL.flags) $(shell cat $(S2N_ROOT)/tests/features/$(1).flags) -c -o tmp.o $(S2N_ROOT)/tests/features/$(1).c > /dev/null 2>&1 && echo "-D$(1)"; rm tmp.o > /dev/null 2>&1)
feature_probe = $(shell $(CC) $(CFLAGS) $(shell cat $(S2N_ROOT)/tests/features/GLOBAL.flags) $(shell cat $(S2N_ROOT)/tests/features/$(1).flags) -c -o tmp.o $(S2N_ROOT)/tests/features/$(1).c > /dev/null 2>&1 && echo "-D$(1)=1"; rm tmp.o > /dev/null 2>&1)

FEATURES := $(notdir $(patsubst %.c,%,$(wildcard $(S2N_ROOT)/tests/features/*.c)))
SUPPORTED_FEATURES := $(foreach feature,$(FEATURES),$(call feature_probe,$(feature)))
Expand Down

0 comments on commit c05f76a

Please sign in to comment.