Skip to content

Commit 109b0c5

Browse files
authored
capi: fix C99 compilation (#1978)
1 parent 4413580 commit 109b0c5

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

cmd/capi/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
find_package(Boost REQUIRED headers)
1818

19+
# Target 'execute' is used to exercise the Silkworm C API library even if using C++ main
1920
add_executable(execute execute.cpp)
2021

2122
set(PRIVATE_LIBS
@@ -29,3 +30,7 @@ set(PRIVATE_LIBS
2930
)
3031

3132
target_link_libraries(execute PRIVATE ${PRIVATE_LIBS})
33+
34+
# Target 'capi_main' is used to check that Silkworm C API header passes pure C compilation
35+
add_executable(capi_main main.c)
36+
target_link_libraries(capi_main PRIVATE silkworm_capi)

cmd/capi/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2024 The Silkworm Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include <stdio.h>
18+
19+
#include <silkworm/capi/silkworm.h>
20+
21+
int main(int argc, char* argv[]) {
22+
(void)argc, (void)argv;
23+
#if defined(_MSC_VER)
24+
printf("MSVC version: %d\n", _MSC_FULL_VER);
25+
#elif defined(__GNUC__) && !defined(__clang__)
26+
printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
27+
#else
28+
printf("AppleClang version: %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__);
29+
#endif
30+
printf("C API silkworm_libmdbx_version: %s\n", silkworm_libmdbx_version());
31+
return 0;
32+
}

silkworm/capi/silkworm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ struct SilkwormChainSnapshot {
9999
#define SILKWORM_GIT_VERSION_SIZE 32
100100

101101
//! Silkworm library logging level
102-
//! \note using anonymous enum seems the only way to obtain enum type in Cgo generated code
103-
typedef enum : uint8_t {
102+
//! \note using anonymous C99 enum is the most portable way to pass enum in Cgo
103+
typedef enum { // NOLINT(performance-enum-size)
104104
SILKWORM_LOG_NONE,
105105
SILKWORM_LOG_CRITICAL,
106106
SILKWORM_LOG_ERROR,
@@ -153,7 +153,7 @@ SILKWORM_EXPORT int silkworm_add_snapshot(SilkwormHandle handle, struct Silkworm
153153
* \brief Get libmdbx version for compatibility checks.
154154
* \return A string in git describe format.
155155
*/
156-
SILKWORM_EXPORT const char* silkworm_libmdbx_version() SILKWORM_NOEXCEPT;
156+
SILKWORM_EXPORT const char* silkworm_libmdbx_version(void) SILKWORM_NOEXCEPT;
157157

158158
#define SILKWORM_RPC_SETTINGS_HOST_SIZE 128
159159
#define SILKWORM_RPC_SETTINGS_API_NAMESPACE_SPEC_SIZE 256

0 commit comments

Comments
 (0)