Skip to content

feat: support building on FreeBSD#86

Open
Ignition wants to merge 1 commit into
masterfrom
feat/freebsd-support
Open

feat: support building on FreeBSD#86
Ignition wants to merge 1 commit into
masterfrom
feat/freebsd-support

Conversation

@Ignition

Copy link
Copy Markdown

Accept FreeBSD in the CMake OS check and reuse the existing POSIX socket path (src/linux/). Two source portability fixes make that path compile on FreeBSD:

  • endian: FreeBSD provides the byte-order helpers via <sys/endian.h>
    rather than glibc's <endian.h>.
  • SOL_TCP: use the portable POSIX IPPROTO_TCP for TCP-level setsockopt options; SOL_TCP is a Linux-only alias (equal to IPPROTO_TCP there).

Also rename the MGCLIENT_ON_LINUX macro/CMake variable to MGCLIENT_ON_POSIX, since Linux and FreeBSD now share that build path.

Verified: static and shared libraries build with clang on FreeBSD 14.

Accept FreeBSD in the CMake OS check and reuse the existing POSIX socket
path (src/linux/). Two source portability fixes make that path compile
on FreeBSD:

- endian: FreeBSD provides the byte-order helpers via <sys/endian.h>
  rather than glibc's <endian.h>.
- SOL_TCP: use the portable POSIX IPPROTO_TCP for TCP-level setsockopt
  options; SOL_TCP is a Linux-only alias (equal to IPPROTO_TCP there).

Also rename the MGCLIENT_ON_LINUX macro/CMake variable to
MGCLIENT_ON_POSIX, since Linux and FreeBSD now share that build path.

Verified: static and shared libraries build with clang on FreeBSD 14.
@Ignition Ignition self-assigned this Jul 14, 2026
@Ignition
Ignition requested review from gitbuda and mattkjames7 July 14, 2026 21:30
@Ignition Ignition added the Docs - changelog only Docs - changelog only label Jul 14, 2026
Comment thread src/linux/mgcommon.h
#ifndef MGCLIENT_LINUX_MGCOMMON_H
#define MGCLIENT_LINUX_MGCOMMON_H

#if defined(__FreeBSD__)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extend this to support other BSD builds, e.g. this from Boost:

#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)

Comment thread CMakeLists.txt
message(STATUS "ON LINUX WASM BUILD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS "ON LINUX BUILD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above- we could include other BSDs: https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs - changelog only Docs - changelog only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants