Skip to content

Commit

Permalink
flb_lib: allow public-API use without dependencies via fluent-bit-min…
Browse files Browse the repository at this point in the history
…imal.h

Currently, fluent-bit.h and flb_lib.h are un-usable by third-parties
becuase the fluent-bit build process does not install all of the
required header files for fluent-bit's dependencies into the Debian
packages.  Skipping that problem for the moment, I'm proposing that
users of the public API don't actually need or want all the headers
required for the interenals of fluent-bit, and there should just be
a simple header that declares the public API.

This new header sets a preprocessor variable and then includes the
normal flb_lib.h, which defines the public API.  flb_lib.h sees the
preprocessor variable and skips loading any of the dependency
headers, instead just declaring the referenced types without
defining them.

This is an improvement over [an earlier version I proposed][1]
where fluent-bit-minimal.h re-defined all the exported symbols of
the public API.  This new mechanism avoids code duplication and the
need to maintain two headers in tandem.

[1]: #7165

Signed-off-by: Michael Conrad <[email protected]>
  • Loading branch information
nrdvana committed Dec 4, 2023
1 parent 323f343 commit 25f8f5e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/hello_world/hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

#include <fluent-bit.h>
#include <fluent-bit-minimal.h>

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion examples/out_lib/out_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

#include <fluent-bit.h>
#include <fluent-bit-minimal.h>
#include <msgpack.h>

int my_stdout_json(void *record, size_t size, void *data)
Expand Down
2 changes: 1 addition & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Install fluent-bit headers
install(FILES "fluent-bit.h"
install(FILES "fluent-bit.h" "fluent-bit-minimal.h"
DESTINATION ${FLB_INSTALL_INCLUDEDIR}
COMPONENT headers
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
Expand Down
33 changes: 33 additions & 0 deletions include/fluent-bit-minimal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2022 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLUENT_BIT_MINIMAL_H
#define FLUENT_BIT_MINIMAL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <fluent-bit/flb_lib.h>

#ifdef __cplusplus
}
#endif

#endif
28 changes: 26 additions & 2 deletions include/fluent-bit/flb_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,31 @@
#ifndef FLB_LIB_H
#define FLB_LIB_H

#include <fluent-bit/flb_macros.h>
#include <fluent-bit/flb_config.h>
/* Avoid dependencies for library users who just want the public API */
#ifdef FLUENT_BIT_MINIMAL_H
#include <stddef.h>

struct mk_event_loop;
struct mk_event;
struct flb_config;

/* Copied from mk_macros.h */
#ifdef __GNUC__
#if __GNUC__ >= 4
#define FLB_EXPORT __attribute__ ((visibility ("default")))
#else
#define FLB_EXPORT
#endif
#elif defined(_WIN32)
#define FLB_EXPORT __declspec(dllexport)
/* mk_macros doesn't have an 'else'... seems like an oversight */
#else
#define FLB_EXPORT extern
#endif
#else
#include <fluent-bit/flb_macros.h>
#include <fluent-bit/flb_config.h>
#endif

/* Lib engine status */
#define FLB_LIB_ERROR -1
Expand All @@ -35,6 +58,7 @@ struct flb_lib_ctx {
struct mk_event_loop *event_loop;
struct mk_event *event_channel;
struct flb_config *config;
struct flb_cf;
};

/* Used on out_lib to define a callback and further opaque data */
Expand Down

0 comments on commit 25f8f5e

Please sign in to comment.