diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index 5ba583b28..68f5d0862 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index c1e7bcf2c..e504c60e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/GNUmakefile b/GNUmakefile index e8299b14c..eac55f32a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 @@ -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: diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index e45bfe0fe..29f844879 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -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"); @@ -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; } diff --git a/examples/unix/c99/z_info.c b/examples/unix/c99/z_info.c index 901587bd8..60606c73a 100644 --- a/examples/unix/c99/z_info.c +++ b/examples/unix/c99/z_info.c @@ -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"); diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index a03b0cc2c..f617c7741 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -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"); diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index f62a1bd78..1bbaef106 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -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"); diff --git a/examples/unix/c99/z_pull.c b/examples/unix/c99/z_pull.c index b809dadff..10c16d462 100644 --- a/examples/unix/c99/z_pull.c +++ b/examples/unix/c99/z_pull.c @@ -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; } diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index 528db3785..82c259426 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -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"); diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index d7d543789..a7c2d28af 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -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"); @@ -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)); diff --git a/examples/unix/c99/z_scout.c b/examples/unix/c99/z_scout.c index 5b40a408e..e9453bf96 100644 --- a/examples/unix/c99/z_scout.c +++ b/examples/unix/c99/z_scout.c @@ -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) { diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index cc738e908..88c144889 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -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"); @@ -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)); diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index ceda1495f..326f5fcbc 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -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");