Skip to content

Commit

Permalink
Merge pull request pistacheio#1221 from dgreatwood/bsdsupport
Browse files Browse the repository at this point in the history
BSD Support (FreeBSD, OpenBSD and NetBSD)
  • Loading branch information
kiplingw authored Aug 16, 2024
2 parents 20b3e98 + c11365f commit 975b0a2
Show file tree
Hide file tree
Showing 29 changed files with 801 additions and 187 deletions.
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
subprojects/**
src/common/eventmeth.cc
include/pistache/eventmeth.h
include/pistache/emosandlibevdefs.h
src/common/pist_timelog.cc
include/pistache/pist_timelog.h
src/common/pist_check.cc
Expand Down
127 changes: 127 additions & 0 deletions Building on BSD - FreeBSD, OpenBSD and NetBSD.txt
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.
19 changes: 9 additions & 10 deletions bldscripts/mesdebugflibevsetdirvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ if [ "$(uname)" == "Darwin" ]; then
exit 1
fi

MY_ARCH_NM=x86
if [ "$(uname -m)" == "arm64" ]; then
MY_ARCH_NM=a64
else
if [ "$(uname -m)" == "aarch64" ]; then
MY_ARCH_NM=a64
fi
if [ "$(uname)" == "OpenBSD" ]; then
echo "Error: Don't force libevent on OpenBSD, libevent is on by default"
exit 1
fi

MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.flibev.debug
MESON_PREFIX_DIR=/usr/local

if [ "$(uname)" == "NetBSD" ]; then
echo "Error: Don't force libevent on NetBSD, libevent is on by default"
exit 1
fi

PST_DIR_SUFFIX=".flibev.debug"
source bldscripts/messetdirvarsfinish.sh
20 changes: 2 additions & 18 deletions bldscripts/mesdebugsetdirvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@
# Use by:
# source bldscripts/mesdebugsetdirvars.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.debug
MESON_PREFIX_DIR=/usr/local
else
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.debug
MESON_PREFIX_DIR=/usr/local
fi
PST_DIR_SUFFIX=".debug"
source bldscripts/messetdirvarsfinish.sh

19 changes: 9 additions & 10 deletions bldscripts/mesflibevsetdirvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ if [ "$(uname)" == "Darwin" ]; then
exit 1
fi

MY_ARCH_NM=x86
if [ "$(uname -m)" == "arm64" ]; then
MY_ARCH_NM=a64
else
if [ "$(uname -m)" == "aarch64" ]; then
MY_ARCH_NM=a64
fi
if [ "$(uname)" == "OpenBSD" ]; then
echo "Error: Don't force libevent on OpenBSD, libevent is on by default"
exit 1
fi

MESON_BUILD_DIR=build${MY_ARCH_NM}.mes.flibev
MESON_PREFIX_DIR=/usr/local

if [ "$(uname)" == "NetBSD" ]; then
echo "Error: Don't force libevent on NetBSD, libevent is on by default"
exit 1
fi

PST_DIR_SUFFIX=".flibev"
source bldscripts/messetdirvarsfinish.sh
21 changes: 2 additions & 19 deletions bldscripts/messetdirvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,5 @@
# Use by:
# source bldscripts/messetdirvars.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
MESON_PREFIX_DIR=/usr/local
else
MESON_BUILD_DIR=build${MY_ARCH_NM}.mes
MESON_PREFIX_DIR=/usr/local
fi

PST_DIR_SUFFIX=
source bldscripts/messetdirvarsfinish.sh
48 changes: 48 additions & 0 deletions bldscripts/messetdirvarsfinish.sh
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

76 changes: 76 additions & 0 deletions include/pistache/emosandlibevdefs.h
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_
Loading

0 comments on commit 975b0a2

Please sign in to comment.