diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c54ddeef6b..d97a53b5920 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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) @@ -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) @@ -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() diff --git a/bin/GCStress/CMakeLists.txt b/bin/GCStress/CMakeLists.txt index 8a6d31ffe3d..1be6a0560ad 100644 --- a/bin/GCStress/CMakeLists.txt +++ b/bin/GCStress/CMakeLists.txt @@ -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}) diff --git a/bin/ch/CMakeLists.txt b/bin/ch/CMakeLists.txt index 012978877ff..1bb17dca9f1 100644 --- a/bin/ch/CMakeLists.txt +++ b/bin/ch/CMakeLists.txt @@ -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} diff --git a/bin/ch/ch.cpp b/bin/ch/ch.cpp index 8c5b4a4e20a..76058cd6c60 100644 --- a/bin/ch/ch.cpp +++ b/bin/ch/ch.cpp @@ -13,7 +13,7 @@ #include #endif -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #include #elif defined(__APPLE__) #include @@ -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 }; diff --git a/lib/Common/Common/ByteSwap.h b/lib/Common/Common/ByteSwap.h index b9b1894f7e2..70d6650f62e 100644 --- a/lib/Common/Common/ByteSwap.h +++ b/lib/Common/Common/ByteSwap.h @@ -68,7 +68,14 @@ RtlUlonglongByteSwap( #define RtlUlongByteSwap(_x) __bswap_32((_x)) #define RtlUlonglongByteSwap(_x) __bswap_64((_x)) +#elif defined(__FreeBSD__) +#include +/* 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 diff --git a/lib/Common/Core/SysInfo.cpp b/lib/Common/Core/SysInfo.cpp index 9786e6201b6..dc1893a2eb7 100644 --- a/lib/Common/Core/SysInfo.cpp +++ b/lib/Common/Core/SysInfo.cpp @@ -11,7 +11,7 @@ #include #ifdef __APPLE__ #include // sysctl* -#elif defined(__linux__) +#elif defined(__linux__) || defined(__FreeBSD__) #include // sysconf #endif // Initialization order @@ -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. diff --git a/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt b/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt index 400d775c0b4..84199be87c5 100644 --- a/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt +++ b/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt @@ -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 diff --git a/lib/Runtime/PlatformAgnostic/Platform/Unix/SystemInfo.cpp b/lib/Runtime/PlatformAgnostic/Platform/Unix/SystemInfo.cpp index 419a4a8395c..415cfb29ad3 100644 --- a/lib/Runtime/PlatformAgnostic/Platform/Unix/SystemInfo.cpp +++ b/lib/Runtime/PlatformAgnostic/Platform/Unix/SystemInfo.cpp @@ -5,7 +5,7 @@ #include "Common.h" #include "ChakraPlatform.h" -#include +#include namespace PlatformAgnostic { diff --git a/pal/inc/pal.h b/pal/inc/pal.h index 2f3e16b4bd2..f13d475da75 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -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 diff --git a/pal/src/config.h.in b/pal/src/config.h.in index 15e4a4c0deb..eb14ad1bf19 100644 --- a/pal/src/config.h.in +++ b/pal/src/config.h.in @@ -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@" diff --git a/pal/src/configure.cmake b/pal/src/configure.cmake index b0c128e0a1f..596b8b6ce81 100644 --- a/pal/src/configure.cmake +++ b/pal/src/configure.cmake @@ -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") diff --git a/pal/src/include/pal/context.h b/pal/src/include/pal/context.h index 8f6e0eac067..d81c14cb7f6 100644 --- a/pal/src/include/pal/context.h +++ b/pal/src/include/pal/context.h @@ -28,6 +28,9 @@ extern "C" * platforms and another type elsewhere. */ #if HAVE_UCONTEXT_T #include +#ifdef __FreeBSD__ +#include +#endif typedef ucontext_t native_context_t; #else // HAVE_UCONTEXT_T