Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BSD Support (FreeBSD, OpenBSD and NetBSD) #1221

Merged
merged 36 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2fb6b23
BSD Support in Build Scripts
dgreatwood Jul 12, 2024
66239a7
Updating Version
dgreatwood Jul 12, 2024
246b549
Add BSD Support in Meson Build Files
dgreatwood Jul 12, 2024
777dbb9
Move USE_LIBEVENT Detection from eventmeth.h to a New File
dgreatwood Jul 12, 2024
9386ae9
Replace use of strcpy and strcat
dgreatwood Jul 12, 2024
78045da
Remove Use of CLOCK_MONOTONIC_RAW in BSD case.
dgreatwood Jul 12, 2024
12f9434
Add a Fallback Method of Counting In-Use Filehandles
dgreatwood Jul 12, 2024
c6b7a9f
Include the wait.h Header File in BSD Cases
dgreatwood Jul 12, 2024
35739ab
Support pthread_set_name_np Spelling For BSD
dgreatwood Jul 12, 2024
83a8425
Support TCP_NOPUSH and sendfile in BSD Case
dgreatwood Jul 12, 2024
8e816a6
Build For FreeBSD and Fix Client Connect on Success Problem
dgreatwood Jul 20, 2024
4b97894
Allow UTC Suffix in Header Date String
dgreatwood Jul 20, 2024
d167aa3
Remove constexpr from actualFdU64Value in libevent Case
dgreatwood Jul 23, 2024
dd5c195
Include execinfo library for NetBSD Builds
dgreatwood Jul 23, 2024
c7de16b
Remove Unneeded Trailing Semicolon
dgreatwood Jul 23, 2024
e10ac7a
Add Workaround for Apparent NetBSD std::put_time Bug
dgreatwood Jul 23, 2024
f9ec968
Support for pthread_setname_np As Defined in NetBSD
dgreatwood Jul 23, 2024
350483a
Address Lack of TCP_NOPUSH/TCP_CORK in NetBSD
dgreatwood Jul 23, 2024
ec07cf1
Add Debug Logging for ReuseAddr Case
dgreatwood Jul 23, 2024
ac3ce3f
When Binding a Free Port Use an IPv4 Address By Default
dgreatwood Jul 23, 2024
0884fb7
Increase Test Timeouts
dgreatwood Jul 23, 2024
078170d
Check for Hostname as Synonym for localhost
dgreatwood Jul 23, 2024
46d3be1
Include Execinfo Library For OpenBSD
dgreatwood Jul 24, 2024
c62e46d
Protect dispatchPeer and toWrite Queue If Opening Connection Closes
dgreatwood Jul 24, 2024
7f5e338
Adding Basic Build Instructions for *BSD
dgreatwood Jul 25, 2024
c5c4150
Remove Some Spurious Newlines from BSD Build Instructions
dgreatwood Jul 25, 2024
91ca524
Merge branch 'pistacheio:master' into bsdsupport
dgreatwood Jul 25, 2024
353e385
Updating Fork's Master Branch
dgreatwood Jul 26, 2024
4f691f0
Merge remote-tracking branch 'origin/master' into bsdsupport
dgreatwood Jul 26, 2024
b6793d5
Fix Debug-output Compile Issue in non-SSL Case
dgreatwood Jul 27, 2024
5bdd374
Updates in Reponse to Tachi107's Comments of July-27-2024
dgreatwood Jul 29, 2024
6dbadec
Merge branch 'bsdsupport' of https://github.com/dgreatwood/pistachefo…
dgreatwood Jul 29, 2024
c3e855b
Merge remote-tracking branch 'origin/master' into bsdsupport
dgreatwood Jul 29, 2024
977f6df
Merge remote-tracking branch 'origin/master' into bsdsupport
dgreatwood Aug 5, 2024
879ad61
Merge With Upstream
dgreatwood Aug 5, 2024
c11365f
Reverted examples/meson.build to the version in master
dgreatwood Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
118 changes: 118 additions & 0 deletions Building on BSD - FreeBSD, OpenBSD and NetBSD.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# 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 cofigure as needed)
dgreatwood marked this conversation as resolved.
Show resolved Hide resolved
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.

There is no howard-hinnant-date package for FreeBSD, but it is
straightforward to install manually:
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/.
dgreatwood marked this conversation as resolved.
Show resolved Hide resolved


OpenBSD
=======

Typically, required packages are installed using:
sudo pkg_add <package-name>
For instance:
sudo pkg_add meson
dgreatwood marked this conversation as resolved.
Show resolved Hide resolved
Do this for each Pistache dependency.

There is no googletest package for OpenBSD, so please install it
manually:
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

There is no rapidjson package on OpenBSD, so please install it
manually:
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
dgreatwood marked this conversation as resolved.
Show resolved Hide resolved


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.

There is no howard-hinnant-date package for FreeBSD, but it is
straightforward to install manually:
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/.

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.


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

8 changes: 7 additions & 1 deletion examples/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pistache_example_files = [

threads_dep = dependency('threads')

# In OpenBSD, rapidjson header fles are installed in
# /usr/local/include, not in /usr/include. Consequently, we need
# deps_libpistache in our dependencies, not just pistache_dep
#
# In particular, for rapidjson/prettywriter.h in rest_description.cc
dgreatwood marked this conversation as resolved.
Show resolved Hide resolved

foreach example_name : pistache_example_files
executable('run'+example_name, example_name+'.cc', dependencies: [pistache_dep, threads_dep])
executable('run'+example_name, example_name+'.cc', dependencies: [pistache_dep, threads_dep, deps_libpistache])
endforeach
74 changes: 74 additions & 0 deletions include/pistache/emosandlibevdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* SPDX-FileCopyrightText: 2024 Duncan Greatwood
*
* SPDX-License-Identifier: Apache-2.0
*/

// Defines, or does not define, _USE_LIBEVENT, _USE_LIBEVENT_LIKE_APPLE and
// _IS_BSD
//
// emosandlibevdefs.h
dgreatwood marked this conversation as resolved.
Show resolved Hide resolved

#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
Loading