libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_export.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * @stability stable
4 * Use of this source code is governed by the ISC License,
5 * a copy of which is in the file LICENSE in the top-level directory
6 * of this distribution.
7 *
8 * src/inc/xtc_export.h
9 * Cross-platform shared-library symbol export/import macro.
10 *
11 * MSVC does not export ANY symbol from a DLL by default (unlike
12 * gcc/clang, which export everything from a .so unless told
13 * otherwise); every function meant to be callable from outside
14 * the DLL needs an explicit __declspec(dllexport) on the
15 * declaration seen while COMPILING the library, and
16 * __declspec(dllimport) on the declaration seen while COMPILING
17 * a CONSUMER that links against the DLL. XTC_API expands to the
18 * right one of those, or to nothing at all everywhere else:
19 *
20 * - XTC_BUILDING_DLL defined (set by the library's own build
21 * when compiling a Windows shared/DLL target): dllexport.
22 * - XTC_DLL defined, XTC_BUILDING_DLL NOT defined (a consumer
23 * that has opted into "I am linking against xtc as a DLL"):
24 * dllimport.
25 * - Anywhere else -- non-Windows (gcc/clang .so, static libs on
26 * every platform, or a Windows consumer of the static
27 * xtc.lib that never defines XTC_DLL): nothing. This is the
28 * common case and MUST be a complete no-op there.
29 *
30 * A consumer building against the shared xtc.dll on Windows adds
31 * -DXTC_DLL to its own compile flags; everyone else needs no
32 * flag at all.
33 */
34
35#ifndef XTC_EXPORT_H
36#define XTC_EXPORT_H
37
38#if defined(_WIN32) && defined(XTC_BUILDING_DLL)
39# define XTC_API __declspec(dllexport)
40#elif defined(_WIN32) && defined(XTC_DLL)
41# define XTC_API __declspec(dllimport)
42#else
43# define XTC_API
44#endif
45
46/*
47 * XTC_DEPRECATED(msg) -- mark a public declaration deprecated. A use
48 * compiles, with a warning carrying `msg` (say what to use instead):
49 *
50 * XTC_DEPRECATED("use xtc_foo_ex") XTC_API int xtc_foo(int);
51 *
52 * Policy (docs/abi-stability.md "Deprecation"): a symbol is deprecated in
53 * some minor N, keeps working for the rest of that major, and is removed
54 * no earlier than the next MAJOR. Define XTC_NO_DEPRECATION_WARNINGS to
55 * silence the warnings (for example while migrating a large codebase).
56 */
57#if defined(XTC_NO_DEPRECATION_WARNINGS)
58# define XTC_DEPRECATED(msg)
59#elif defined(__cplusplus) && __cplusplus >= 201402L
60# define XTC_DEPRECATED(msg) [[deprecated(msg)]]
61#elif defined(__GNUC__) || defined(__clang__)
62# define XTC_DEPRECATED(msg) __attribute__((deprecated(msg)))
63#elif defined(_MSC_VER)
64# define XTC_DEPRECATED(msg) __declspec(deprecated(msg))
65#else
66# define XTC_DEPRECATED(msg)
67#endif
68
69#endif /* XTC_EXPORT_H */