Skip to content
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ else(NOT CHAKRACORE_BUILD_SH)
endif(NOT CHAKRACORE_BUILD_SH)

if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
set(CC_TARGETS_AMD64_SH 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(CC_TARGETS_ARM_SH 1)
Expand Down Expand Up @@ -136,6 +137,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CC_TARGET_OS_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CC_TARGET_OS_OSX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(CC_TARGET_OS_FREEBSD 1)
endif()

if (ENABLE_CC_XPLAT_TRACE_SH)
Expand Down Expand Up @@ -193,6 +196,12 @@ if(EMBED_ICU)
# Keep consistent with what ICU download script used to print
message("Note: ICU installation and use is subject to it's publisher's licensing terms")

if (CC_TARGET_OS_FREEBSD)
# FreeBSD calls GNU make 'gmake'
find_program(MAKE_PROGRAM "gmake" REQUIRED)
else()
set(MAKE_PROGRAM "make")
endif()
set(ICU_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/deps/thirdparty/icu)
set(ICU_DOWNLOAD_DIR ${ICU_PREFIX}/download)
set(ICU_SOURCE_DIR ${ICU_PREFIX}/stage)
Expand All @@ -216,8 +225,8 @@ if(EMBED_ICU)
URL https://github.com/unicode-org/icu/releases/download/release-63-2/icu4c-63_2-src.tgz
URL_HASH SHA512=5fa9092efd8d6da6dfc8d498e4026167fda43423eaafc754d1789cf8fd4f6e76377878ebcaa32e14f314836136b764873511a93bfbcc5419b758841cc6df8f32
CONFIGURE_COMMAND ${ICU_SOURCE_DIR}/source/configure --prefix=${ICU_PREFIX} --with-data-packaging=static --enable-static --disable-shared --with-library-bits=64 --disable-icuio --disable-layout --disable-tests --disable-samples
BUILD_COMMAND make STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC"
INSTALL_COMMAND make install
BUILD_COMMAND ${MAKE_PROGRAM} STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC"
INSTALL_COMMAND ${MAKE_PROGRAM} install
BYPRODUCTS ${ICU_LIBRARIES}
)
elseif(ICU_INCLUDE_PATH)
Expand Down Expand Up @@ -354,6 +363,11 @@ elseif(CC_TARGET_OS_OSX)
message(WARNING "-- !! macOS Deployment Target was set to $ENV{MACOSX_DEPLOYMENT_TARGET}. Using it as is.")
endif()
endif()
elseif(CC_TARGET_OS_FREEBSD)
add_definitions(
-DPLATFORM_UNIX
)
# TODO?
else()
message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
endif()
Expand Down
12 changes: 12 additions & 0 deletions bin/GCStress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ elseif(NOT CC_TARGET_OS_ANDROID)
)
endif()

if(CC_TARGET_OS_FREEBSD)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(lib_target "${lib_target}"
"-lexecinfo"
)
endif()
set(lib_target "${lib_target}"
"-L/usr/local/lib"
"-lintl"
)
endif()

target_link_libraries (GCStress ${lib_target})
8 changes: 8 additions & 0 deletions bin/ch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ elseif(CC_TARGET_OS_OSX)
endif()
endif()

if(CC_TARGET_OS_FREEBSD)
set(lib_target "${lib_target}"
"-L/usr/local/lib"
"-lintl"
"-lsysinfo"
)
endif()

target_link_libraries (ch
${lib_target}
${CC_LTO_ENABLED}
Expand Down
4 changes: 2 additions & 2 deletions bin/ch/ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <pthread.h>
#endif

#ifdef __linux__
#if defined(__linux__) || defined(__FreeBSD__)
#include <sys/sysinfo.h>
#elif defined(__APPLE__)
#include <sys/sysctl.h>
Expand Down Expand Up @@ -543,7 +543,7 @@ static HRESULT CreateRuntime(JsRuntimeHandle *runtime)
// Additionally, we can probably do better than just limit to the physical memory
// size

#if defined(__APPLE__) || defined(__linux__)
#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)
size_t memoryLimit;
#ifdef __APPLE__
int totalRamHW[] = { CTL_HW, HW_MEMSIZE };
Expand Down
9 changes: 8 additions & 1 deletion lib/Common/Common/ByteSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ RtlUlonglongByteSwap(
#define RtlUlongByteSwap(_x) __bswap_32((_x))
#define RtlUlonglongByteSwap(_x) __bswap_64((_x))

#elif defined(__FreeBSD__)
#include <byteswap.h>
/* FreeBSD 13+, also above definitions would work
* TODO replace with "has byteswap.h" check? */
#define RtlUshortByteSwap(_x) bswap_16((_x))
#define RtlUlongByteSwap(_x) bswap_32((_x))
#define RtlUlonglongByteSwap(_x) bswap_64((_x))

#else
// TODO: include endian.h for BSD?
#error "ByteSwap.h: Not implemented for this platform"
#endif
4 changes: 2 additions & 2 deletions lib/Common/Core/SysInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <VersionHelpers.h>
#ifdef __APPLE__
#include <sys/sysctl.h> // sysctl*
#elif defined(__linux__)
#elif defined(__linux__) || defined(__FreeBSD__)
#include <unistd.h> // sysconf
#endif
// Initialization order
Expand Down Expand Up @@ -195,7 +195,7 @@ AutoSystemInfo::InitPhysicalProcessorCount()
countPhysicalProcessor = 1;
}
}
#elif defined(__linux__)
#elif defined(__linux__) || defined(__FreeBSD__)
countPhysicalProcessor = sysconf(_SC_NPROCESSORS_ONLN);
#else
// implementation for __linux__ should work for some others.
Expand Down
4 changes: 4 additions & 0 deletions lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ elseif(CC_TARGET_OS_OSX)
Unix/SystemInfo.cpp
# Linux/PerfTrace.cpp # TODO : implement for OSX?
)
elseif(CC_TARGET_OS_FREEBSD)
set(PL_SOURCE_FILES ${PL_SOURCE_FILES}
Unix/SystemInfo.cpp
)
endif()

add_library (Chakra.Runtime.PlatformAgnostic OBJECT
Expand Down
2 changes: 1 addition & 1 deletion lib/Runtime/PlatformAgnostic/Platform/Unix/SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "Common.h"
#include "ChakraPlatform.h"
#include <sys/sysctl.h>
#include <sys/resource.h>

namespace PlatformAgnostic
{
Expand Down
5 changes: 5 additions & 0 deletions pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ extern "C" {
#endif
#endif

#ifndef __FreeBSD__
#define PAL_GLOBAL __attribute__((init_priority(200)))
#else
/* TODO above macro expansion fails to compile on FreeBSD */
#define PAL_GLOBAL
#endif
/******************* PAL-Specific Entrypoints *****************************/

#define IsDebuggerPresent PAL_IsDebuggerPresent
Expand Down
1 change: 1 addition & 0 deletions pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#cmakedefine01 ERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS
#cmakedefine01 HAS_FTRUNCATE_LENGTH_ISSUE
#cmakedefine FREEBSD_LIBC "@FREEBSD_LIBC@"
#cmakedefine BSD_REGS_STYLE(reg, RR, rr) @BSD_REGS_STYLE@

#cmakedefine JA_JP_LOCALE_NAME "@JA_JP_LOCALE_NAME@"
#cmakedefine KO_KR_LOCALE_NAME "@KO_KR_LOCALE_NAME@"
Expand Down
7 changes: 7 additions & 0 deletions pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(KO_KR_LOCALE_NAME ko_KR_LOCALE_NOT_FOUND)
set(ZH_TW_LOCALE_NAME zh_TW_LOCALE_NOT_FOUND)
set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
set(BSD_REGS_STYLE "((reg).r_##rr)")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(BSD_REGS_STYLE "((reg).rr)")
else()
message(FATAL_ERROR "Unsupported FreeBSD architecture")
endif()

if(EXISTS "/lib/libc.so.7")
set(FREEBSD_LIBC "/lib/libc.so.7")
Expand Down
3 changes: 3 additions & 0 deletions pal/src/include/pal/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ extern "C"
* platforms and another type elsewhere. */
#if HAVE_UCONTEXT_T
#include <ucontext.h>
#ifdef __FreeBSD__
#include <machine/fpu.h>
#endif

typedef ucontext_t native_context_t;
#else // HAVE_UCONTEXT_T
Expand Down
Loading