xref: /aosp_15_r20/external/libwebsockets/READMEs/README.event-libs.md (revision 1c60b9aca93fdbc9b5f19b2d2194c91294b22281)
1*1c60b9acSAndroid Build Coastguard Worker# lws event library support
2*1c60b9acSAndroid Build Coastguard Worker
3*1c60b9acSAndroid Build Coastguard Worker## v4.0 and below
4*1c60b9acSAndroid Build Coastguard Worker
5*1c60b9acSAndroid Build Coastguard WorkerBefore v4.1, lws allowed selecting some event library support for inclusion
6*1c60b9acSAndroid Build Coastguard Workerin the libwebsockets library
7*1c60b9acSAndroid Build Coastguard Worker
8*1c60b9acSAndroid Build Coastguard WorkerOption|Feature
9*1c60b9acSAndroid Build Coastguard Worker---|---
10*1c60b9acSAndroid Build Coastguard Worker`LWS_WITH_GLIB`|glib
11*1c60b9acSAndroid Build Coastguard Worker`LWS_WITH_LIBEVENT`|libevent
12*1c60b9acSAndroid Build Coastguard Worker`LWS_WITH_LIBUV`|libuv
13*1c60b9acSAndroid Build Coastguard Worker`LWS_WITH_LIBEV`|libev
14*1c60b9acSAndroid Build Coastguard Worker
15*1c60b9acSAndroid Build Coastguard WorkerThe user code can select by `info->options` flags at runtime which event loop
16*1c60b9acSAndroid Build Coastguard Workerit wants to use.
17*1c60b9acSAndroid Build Coastguard Worker
18*1c60b9acSAndroid Build Coastguard WorkerThe only restriction is that libev and libevent can't coexist, because their
19*1c60b9acSAndroid Build Coastguard Workerheader namespace conflicts.
20*1c60b9acSAndroid Build Coastguard Worker
21*1c60b9acSAndroid Build Coastguard Worker## v4.1 and above
22*1c60b9acSAndroid Build Coastguard Worker
23*1c60b9acSAndroid Build Coastguard WorkerLws continues to support the old way described above, but there's an additional
24*1c60b9acSAndroid Build Coastguard Workernew cmake option that decides how they are built if any are selected,
25*1c60b9acSAndroid Build Coastguard Worker`LWS_WITH_EVLIB_PLUGINS`.
26*1c60b9acSAndroid Build Coastguard Worker
27*1c60b9acSAndroid Build Coastguard WorkerThe old behaviour is set by `LWS_WITH_EVLIB_PLUGINS=0`, for UNIX platforms, this
28*1c60b9acSAndroid Build Coastguard Workeris set to 1 by default.  This causes the enabled event lib support to each be built into
29*1c60b9acSAndroid Build Coastguard Workerits own dynamically linked plugin, and lws will bring in the requested support alone
30*1c60b9acSAndroid Build Coastguard Workerat runtime after seeing the `info->options` flags requested by the user code.
31*1c60b9acSAndroid Build Coastguard Worker
32*1c60b9acSAndroid Build Coastguard WorkerThis has two main benefits, first the conflict around building libevent and libev
33*1c60b9acSAndroid Build Coastguard Workertogether is removed, they each build isolated in their own plugin; the libwebsockets
34*1c60b9acSAndroid Build Coastguard Workercore library build doesn't import any of their headers (see below for exception).
35*1c60b9acSAndroid Build Coastguard WorkerAnd second, for distro packaging, the event lib support plugins can be separately
36*1c60b9acSAndroid Build Coastguard Workerpackaged, and apps take dependencies on the specific event lib plugin package, which
37*1c60b9acSAndroid Build Coastguard Workeritself depends on the libwebsockets core library.  This allows just the needed
38*1c60b9acSAndroid Build Coastguard Workerdependencies for the packageset without forcing everything to bring everything in.
39*1c60b9acSAndroid Build Coastguard Worker
40*1c60b9acSAndroid Build Coastguard WorkerSeparately, lws itself has some optional dependencies on libuv, if you build lwsws
41*1c60b9acSAndroid Build Coastguard Workeror on Windows you want plugins at all.  CMake will detect these situations and
42*1c60b9acSAndroid Build Coastguard Workerselect to link the lws library itself to libuv if so as well, independent of whatever
43*1c60b9acSAndroid Build Coastguard Workeris happening with the event lib support.
44*1c60b9acSAndroid Build Coastguard Worker
45*1c60b9acSAndroid Build Coastguard Worker## evlib plugin install
46*1c60b9acSAndroid Build Coastguard Worker
47*1c60b9acSAndroid Build Coastguard WorkerThe produced plugins are named
48*1c60b9acSAndroid Build Coastguard Worker
49*1c60b9acSAndroid Build Coastguard Workerevent lib|plugin name
50*1c60b9acSAndroid Build Coastguard Worker---|---
51*1c60b9acSAndroid Build Coastguard Workerglib|`libwebsockets-evlib_glib.so`
52*1c60b9acSAndroid Build Coastguard Workerevent|`libwebsockets-evlib_event.so`
53*1c60b9acSAndroid Build Coastguard Workeruv|`libwebsockets-evlib_uv.so`
54*1c60b9acSAndroid Build Coastguard Workerev|`libwebsockets-evlib_ev.so`
55*1c60b9acSAndroid Build Coastguard Worker
56*1c60b9acSAndroid Build Coastguard WorkerThe evlib plugins are installed alongside libwebsockets.so/.a into the configured
57*1c60b9acSAndroid Build Coastguard Workerlibrary dir, it's often `/usr/local/lib/` by default on linux.
58*1c60b9acSAndroid Build Coastguard Worker
59*1c60b9acSAndroid Build Coastguard WorkerLws looks for them at runtime using the build-time-configured path.
60*1c60b9acSAndroid Build Coastguard Worker
61*1c60b9acSAndroid Build Coastguard Worker## Component packaging
62*1c60b9acSAndroid Build Coastguard Worker
63*1c60b9acSAndroid Build Coastguard WorkerThe canonical package name is `libwebsockets`, the recommended way to split the
64*1c60b9acSAndroid Build Coastguard Workerpackaging is put the expected libs and pkgconfig in `libwebsockets` or `libwebsockets-core`,
65*1c60b9acSAndroid Build Coastguard Workerthe latter is followed by the provided cmake, and produce an additional package per build
66*1c60b9acSAndroid Build Coastguard Workerevent library plugin, named, eg `libwebsockets-evlib_glib`, which has a dependency on
67*1c60b9acSAndroid Build Coastguard Worker`libwebsockets[-core]`.
68*1c60b9acSAndroid Build Coastguard Worker
69*1c60b9acSAndroid Build Coastguard WorkerApplications that use the default event loop can directly require `libwebsockets[-core]`,
70*1c60b9acSAndroid Build Coastguard Workerand application packages that need specific event loop support can just require, eg,
71*1c60b9acSAndroid Build Coastguard Worker`libwebsockets-evlib_glib`, which will bring that in and the core lws pieces in one step.
72*1c60b9acSAndroid Build Coastguard WorkerThere is then no problem with multiple apps requiring different event libs, they will
73*1c60b9acSAndroid Build Coastguard Workerbring in all the necessary pieces which will not conflict either as packages or at
74*1c60b9acSAndroid Build Coastguard Workerruntime.
75*1c60b9acSAndroid Build Coastguard Worker
76*1c60b9acSAndroid Build Coastguard Worker## `LWS_WITH_DISTRO_RECOMMENDED`
77*1c60b9acSAndroid Build Coastguard Worker
78*1c60b9acSAndroid Build Coastguard WorkerThe cmake helper config `LWS_WITH_DISTRO_RECOMMENDED` is adapted to build all the
79*1c60b9acSAndroid Build Coastguard Workerevent libs with the event lib plugin support enabled.
80*1c60b9acSAndroid Build Coastguard Worker
81