1
0
mirror of https://github.com/facebook/proxygen.git synced 2025-08-07 07:02:53 +03:00

add freebsd support

Summary: Add some basic support for FreeBSD to getdeps.

Reviewed By: ahornby

Differential Revision: D33989129

fbshipit-source-id: 42ff5f160b7e19c12196bb2e52a726f7815487bd
This commit is contained in:
Chad Austin
2022-02-08 18:06:55 -08:00
committed by Facebook GitHub Bot
parent 6926f90e05
commit 5cd35796ba
10 changed files with 76 additions and 9 deletions

View File

@@ -130,6 +130,32 @@ def _get_available_ram_windows() -> int:
return (ms.ullAvailPhys + ms.ullTotalPhys) // (2 * 1024 * 1024)
def _get_available_ram_freebsd() -> int:
import ctypes.util
libc = ctypes.CDLL(ctypes.util.find_library("libc"), use_errno=True)
sysctlbyname = libc.sysctlbyname
sysctlbyname.restype = ctypes.c_int
sysctlbyname.argtypes = [
ctypes.c_char_p,
ctypes.c_void_p,
ctypes.POINTER(ctypes.c_size_t),
ctypes.c_void_p,
ctypes.c_size_t,
]
# hw.usermem is pretty close to what we want.
memsize = ctypes.c_int64()
memsizesize = ctypes.c_size_t(8)
res = sysctlbyname(
b"hw.usermem", ctypes.byref(memsize), ctypes.byref(memsizesize), None, 0
)
if res != 0:
raise NotImplementedError(
f"failed to retrieve hw.memsize sysctl: {ctypes.get_errno()}"
)
return memsize.value // (1024 * 1024)
def get_available_ram() -> int:
"""
Returns a platform-appropriate available RAM metric in MiB.
@@ -140,6 +166,8 @@ def get_available_ram() -> int:
return _get_available_ram_macos()
elif sys.platform == "win32":
return _get_available_ram_windows()
elif sys.platform.startswith("freebsd"):
return _get_available_ram_freebsd()
else:
raise NotImplementedError(
f"platform {sys.platform} does not have an implementation of get_available_ram"
@@ -158,6 +186,8 @@ class HostType(object):
elif is_windows():
ostype = "windows"
distrovers = str(sys.getwindowsversion().major)
elif sys.platform.startswith("freebsd"):
ostype = "freebsd"
else:
ostype = sys.platform
@@ -185,6 +215,9 @@ class HostType(object):
def is_linux(self):
return self.ostype == "linux"
def is_freebsd(self):
return self.ostype == "freebsd"
def as_tuple_string(self):
return "%s-%s-%s" % (
self.ostype,