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

feat:Supports compilation on FreeBSD14 #2711

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "-pthread")
add_definitions(-DOS_MACOSX)
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(CMAKE_CXX_FLAGS "-pthread")
add_definitions(-DOS_FREEBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_EXE_LINKER_FLAGS "-stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi ${CMAKE_EXE_LINKER_FLAGS}")
Expand All @@ -66,7 +69,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
endif()
add_definitions(-DOS_LINUX)
else()
message(FATAL_ERROR "only support linux or macOs")
message(FATAL_ERROR "only support linux or macOs or FreeBSD")
endif()

if(HOST_ARCH MATCHES "x86_64" OR HOST_ARCH MATCHES "i386")
Expand Down
4 changes: 3 additions & 1 deletion include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#define PIKA_SERVER_H_

#include <shared_mutex>
#if defined(__APPLE__)

#if defined(__APPLE__) || defined(__FreeBSD__)
# include <sys/mount.h>
# include <sys/param.h>
#else
# include <sys/statfs.h>
#endif

#include <memory>
#include <set>

Expand Down
2 changes: 1 addition & 1 deletion src/net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ add_subdirectory(examples)

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(FILTER DIR_SRCS EXCLUDE REGEX ".net_kqueue.*")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
list(FILTER DIR_SRCS EXCLUDE REGEX ".net_epoll.*")
endif()

Expand Down
8 changes: 6 additions & 2 deletions src/net/src/net_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
#include <arpa/inet.h>
#include <ifaddrs.h>

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__FreeBSD__)
# include <arpa/inet.h>
# include <ifaddrs.h>
# include <net/if.h>
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <unistd.h>

# include "pstd/include/pstd_defer.h"
Expand All @@ -31,7 +35,7 @@
#include "pstd/include/xdebug.h"

std::string GetDefaultInterface() {
#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__FreeBSD__)
std::string name("lo0");

int fd = socket(AF_INET, SOCK_DGRAM, 0);
Expand Down
15 changes: 13 additions & 2 deletions src/pika_monotonic_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.

#ifdef __APPLE__ // Mac
#if defined(__APPLE__) // Mac
#include <mach/mach_time.h>

#include "include/pika_monotonic_time.h"
Expand All @@ -17,7 +17,18 @@ monotime getMonotonicUs() {
return nanos / 1000;
}

#elif __linux__ // Linux
#elif defined(__FreeBSD__) // FreeBSD
#include <time.h>

#include "include/pika_monotonic_time.h"

monotime getMonotonicUs() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
}

#elif defined(__linux__) // Linux

#ifdef __x86_64__ // x86_64

Expand Down
4 changes: 4 additions & 0 deletions src/pika_rsync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "include/pika_conf.h"
#include "include/pika_define.h"

#ifdef __FreeBSD__
# include <sys/wait.h>
#endif

extern std::unique_ptr<PikaConf> g_pika_conf;

PikaRsyncService::PikaRsyncService(const std::string& raw_path, const int port) : raw_path_(raw_path), port_(port) {
Expand Down
5 changes: 5 additions & 0 deletions src/pstd/src/rsync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include "pstd/include/rsync.h"
#include "pstd/include/xdebug.h"

#ifdef __FreeBSD__
# include <sys/types.h>
# include <sys/wait.h>
#endif

namespace pstd {
// Clean files for rsync info, such as the lock, log, pid, conf file
static bool CleanRsyncInfo(const std::string& path) { return pstd::DeleteDirIfExist(path + kRsyncSubDir); }
Expand Down
7 changes: 5 additions & 2 deletions src/storage/src/coding.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
#ifndef SRC_CODING_H_
#define SRC_CODING_H_

#undef STORAGE_PLATFORM_IS_LITTLE_ENDIAN

#if defined(__APPLE__)
# include <machine/endian.h> // __BYTE_ORDER
# define __BYTE_ORDER __DARWIN_BYTE_ORDER
# define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
#elif defined(__FreeBSD__)
# include <sys/endian.h> // __BYTE_ORDER
# include <sys/endian.h>
# include <sys/types.h>
# define STORAGE_PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
#else
# include <endian.h> // __BYTE_ORDER
#endif

#undef STORAGE_PLATFORM_IS_LITTLE_ENDIAN
#ifndef STORAGE_PLATFORM_IS_LITTLE_ENDIAN
# define STORAGE_PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
#endif
Expand Down
Loading