forked from pistacheio/pistache
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pistacheio#1221 from dgreatwood/bsdsupport
BSD Support (FreeBSD, OpenBSD and NetBSD)
- Loading branch information
Showing
29 changed files
with
801 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# SPDX-FileCopyrightText: 2024 Duncan Greatwood | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
Making Pistache on *BSD | ||
======================= | ||
|
||
Pistache has been built and tested on FreeBSD, OpenBSD and NetBSD. As | ||
of July-2024, the versions used for testing were FreeBSD 13.3, | ||
OpenBSD 7.3 and NetBSD 10.0. | ||
|
||
You will need to configure BSD with a working compiler. | ||
|
||
We would recommend that you also have python installed, including pip | ||
(use "python -m ensure-pip" if needed, and add the directory where pip | ||
is installed to your path). Plus, we recommend installing sudo, if not | ||
preinstalled. | ||
|
||
You will need the following Pistache-dependencies installed: | ||
git (and configure as needed) | ||
llvm | ||
meson | ||
doxygen | ||
googletest (*) | ||
openssl | ||
rapidjson (*) | ||
howard-hinnant-date (*) | ||
libevent | ||
See BSD-type-specific notes below regarding installing these | ||
dependencies. | ||
|
||
Convenience shell scripts are provided to make the build. Once | ||
dependencies are installed, at the terminal, to build do: | ||
bldscripts/mesbuild.sh | ||
To test: | ||
bldscripts/mestest.sh | ||
To install: | ||
bldscripts/mesinstall.sh | ||
|
||
|
||
FreeBSD | ||
======= | ||
|
||
Typically, required packages are installed using: | ||
sudo pkg install <package-name> | ||
For instance: | ||
sudo pkg install meson | ||
Do this for each Pistache dependency, excluding howard-hinnant-date. | ||
|
||
|
||
OpenBSD | ||
======= | ||
|
||
Typically, required packages are installed using: | ||
doas pkg_add <package-name> | ||
For instance: | ||
doas pkg_add meson | ||
Do this for each Pistache dependency, excluding googletest and | ||
rapidjson. | ||
(Note: You may use sudo instead of doas if you have installed the sudo | ||
package and configured sudo; however, doas is often preferred on | ||
OpenBSD.) | ||
|
||
|
||
NetBSD | ||
====== | ||
Typically, required packages are installed using: | ||
sudo pkg_in install <package-name> | ||
For instance: | ||
sudo pkg_in install meson | ||
Do this for each Pistache dependency, excluding howard-hinnant-date. | ||
|
||
Regarding NetBSD 9.4. NetBSD 9.4 uses gcc 7.5.0, while Pistache's | ||
build files require C++17 support, and Pistache's code uses | ||
std::filesystem. However, gcc 7.5.0 does not work correctly with | ||
std::filesystem when C++17 is specified. Accordingly, we have tested | ||
with NetBSD 10.0, not 9.4. Nonetheless, it is possible that Pistache | ||
could be made to work on NetBSD 9.* with a different compiler or | ||
different compiler version. | ||
|
||
Regarding the test net_test.invalid_address, it may be slow to execute | ||
(about 2 minutes) in NetBSD. The cause is a long time out for the | ||
system function getaddrinfo; it doesn't appear to an issue in | ||
Pistache. | ||
|
||
|
||
(*) Googletest, Rapidjson and Howard-hinnant-date Packages | ||
========================================================== | ||
|
||
These packages are provided as Pistache subprojects, and so do not | ||
have to be installed seperately on the BSD system. Also, note that | ||
there is no howard-hinnant-date package supplied as part of the OS by | ||
FreeBSD 13 nor by NetBSD 10; and no googletest or rapidjson packages | ||
supplied by OpenBSD 7. Nonetheless, if you would like to install | ||
googletest, rapidjson and/or howard-hinnant-date manually on the BSD | ||
system, please proceed as follows: | ||
|
||
Googletest: | ||
git clone https://github.com/google/googletest.git | ||
cd googletest | ||
mkdir build | ||
cd build | ||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .. | ||
make | ||
sudo make install | ||
|
||
Rapidjson: | ||
git clone https://github.com/Tencent/rapidjson/ | ||
cd rapidjson/ | ||
mkdir build | ||
cd build | ||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .. | ||
make | ||
sudo make install | ||
|
||
Howard-hinnant-date: | ||
git clone https://github.com/HowardHinnant/date.git | ||
sudo mkdir /usr/local/include/date | ||
sudo cp -p date/include/date/date.h /usr/local/include/date/. | ||
|
||
(Note: Typically, use doas instead of sudo on OpenBSD). | ||
|
||
|
||
How It Works | ||
============ | ||
Pistache on BSD works very much as it does on macOS, i.e. by using the | ||
libevent library to provide the core event loop. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# SPDX-FileCopyrightText: 2024 Duncan Greatwood | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Sets MESON_BUILD_DIR and MESON_PREFIX_DIR | ||
# | ||
# NOT to be invoked directly by user. Ivoked by other set scripts once | ||
# ... has been set | ||
# | ||
# Use by: | ||
# source bldscripts/messetdirvarsfinish.sh | ||
|
||
MY_ARCH_NM=x86 | ||
if [ "$(uname -m)" == "arm64" ]; then | ||
MY_ARCH_NM=a64 | ||
else | ||
if [ "$(uname -m)" == "aarch64" ]; then | ||
MY_ARCH_NM=a64 | ||
fi | ||
fi | ||
|
||
|
||
if [ "$(uname)" == "Darwin" ]; then | ||
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.mac${PST_DIR_SUFFIX} | ||
MESON_PREFIX_DIR=/usr/local | ||
else | ||
if [[ "$OSTYPE" == "freebsd"* ]]; then | ||
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.fbd${PST_DIR_SUFFIX} | ||
MESON_PREFIX_DIR=/usr/local | ||
else | ||
if [[ "$OSTYPE" == "openbsd"* ]]; then | ||
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.obd${PST_DIR_SUFFIX} | ||
MESON_PREFIX_DIR=/usr/local | ||
else | ||
if [[ "$OSTYPE" == "netbsd"* ]]; then | ||
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.nbd${PST_DIR_SUFFIX} | ||
MESON_PREFIX_DIR=/usr/local | ||
else | ||
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes${PST_DIR_SUFFIX} | ||
MESON_PREFIX_DIR=/usr/local | ||
fi | ||
fi | ||
fi | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Duncan Greatwood | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// EventMeth Operating System and libevent defines | ||
|
||
// Defines, or does not define, _USE_LIBEVENT, _USE_LIBEVENT_LIKE_APPLE and | ||
// _IS_BSD | ||
// | ||
// emosandlibevdefs.h | ||
|
||
#ifndef _EMOSANDLIBEVDEFS_H_ | ||
#define _EMOSANDLIBEVDEFS_H_ | ||
|
||
/* ------------------------------------------------------------------------- */ | ||
|
||
#ifdef PISTACHE_FORCE_LIBEVENT | ||
|
||
// Force libevent even for Linux | ||
#define _USE_LIBEVENT 1 | ||
|
||
// _USE_LIBEVENT_LIKE_APPLE not only forces libevent, but even in Linux causes | ||
// the code to be as similar as possible to the way it is for __APPLE__ | ||
// (e.g. wherever possible, even on Linux it uses solely OS calls that are | ||
// also available on macOS) | ||
// | ||
// Can comment out if not wanted | ||
#define _USE_LIBEVENT_LIKE_APPLE 1 | ||
|
||
#endif // ifdef PISTACHE_FORCE_LIBEVENT | ||
|
||
#ifdef _USE_LIBEVENT_LIKE_APPLE | ||
#ifndef _USE_LIBEVENT | ||
#define _USE_LIBEVENT 1 | ||
#endif | ||
#endif | ||
|
||
#ifdef __APPLE__ | ||
#ifndef _USE_LIBEVENT | ||
#define _USE_LIBEVENT 1 | ||
#endif | ||
#ifndef _USE_LIBEVENT_LIKE_APPLE | ||
#define _USE_LIBEVENT_LIKE_APPLE 1 | ||
#endif | ||
#elif defined(_WIN32) // Defined for both 32-bit and 64-bit environments | ||
#define _USE_LIBEVENT 1 | ||
#elif defined(__unix__) || !defined(__APPLE__) && defined(__MACH__) | ||
#include <sys/param.h> | ||
#if defined(BSD) | ||
// FreeBSD, NetBSD, OpenBSD, DragonFly BSD | ||
// | ||
// Note - FreeBSD may support epoll via FreeBSD's Linux emulation layer | ||
// (see https://wiki.freebsd.org/Linuxulator). We can check for FreeBSD | ||
// using "ifdef __FreeBSD__" and also check __FreeBSD_version (see | ||
// https://docs.freebsd.org/en/books/porters-handbook/versions/). | ||
// However, since FreeBSD's Linuxulator supports Linux binaries, a user | ||
// might perhaps just as well run the Linux version of Pistache if | ||
// using the Linuxulator. So we use libevent (which will likely use | ||
// kqueue on FreeBSD) even in the FreeBSD case. | ||
#ifndef _USE_LIBEVENT | ||
#define _USE_LIBEVENT 1 | ||
#endif | ||
#ifndef _USE_LIBEVENT_LIKE_APPLE | ||
#define _USE_LIBEVENT_LIKE_APPLE 1 | ||
#endif | ||
#ifndef _IS_BSD | ||
#define _IS_BSD 1 | ||
#endif | ||
#endif | ||
#endif | ||
|
||
/* ------------------------------------------------------------------------- */ | ||
|
||
#endif // ifndef _EMOSANDLIBEVDEFS_H_ |
Oops, something went wrong.