Skip to content

Commit

Permalink
Fix c99 compilation (#317)
Browse files Browse the repository at this point in the history
* fix: build tests only in c11

* fix: remove c11 macros from examples

* feat: add a way to force c99 standard

* ci: add a c99 compilation test
  • Loading branch information
jean-roland authored and p-avital committed Jan 17, 2024
1 parent 53c6aa5 commit e0a12e9
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ jobs:
- name: Run clang-format dry-run
run: find include/ src/ tests/ examples/ -iname "*.ino" -o -iname "*.h" -o -iname "*.c" | xargs clang-format -n -Werror

c99_build:
name: Check c99 compilation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build with C99
run: |
sudo apt install -y ninja-build
FORCE_C99=ON CMAKE_GENERATOR=Ninja make
modular_build:
name: Modular build on ubuntu-latest
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ if(UNIX OR MSVC)
target_link_libraries(z_keyexpr_canonizer ${Libname})
endif()

if(BUILD_TESTING)
if(BUILD_TESTING AND CMAKE_C_STANDARD MATCHES "11")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
Expand Down
8 changes: 8 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ BUILD_INTEGRATION?=OFF
# Accepted values: ON, OFF
BUILD_TOOLS?=OFF

# Force the use of c99 standard.
# Accepted values: ON, OFF
FORCE_C99?=OFF

# Debug level. This sets the ZENOH_DEBUG variable.
# Accepted values:
# 0: NONE
Expand Down Expand Up @@ -72,6 +76,10 @@ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAK
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.

ifeq ($(FORCE_C99), ON)
CMAKE_OPT += -DCMAKE_C_STANDARD=99
endif

all: make

$(BUILD_DIR)/Makefile:
Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand All @@ -105,7 +105,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (1) {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
if (c == 'q') {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c99/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (1) {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
if (c == 'q') {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c99/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down Expand Up @@ -108,7 +108,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (c != 'q') {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
}

z_undeclare_queryable(z_queryable_move(&qable));
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void callback(z_owned_hello_t *hello, void *context) {
fprinthello(stdout, z_hello_loan(hello));
fprintf(stdout, "\n");
(*(int *)context)++;
z_drop(hello);
z_hello_drop(hello);
}

void drop(void *context) {
Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c99/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down Expand Up @@ -96,7 +96,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (c != 'q') {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
}

z_undeclare_subscriber(z_subscriber_move(&sub));
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down

0 comments on commit e0a12e9

Please sign in to comment.