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

Fix build on Apple Silicon Mac #219

Merged
merged 8 commits into from
Feb 6, 2021
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
37 changes: 11 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
dist: focal
language: cpp
os:
- linux
- osx
compiler:
- clang
- gcc
osx_image: xcode12
os: linux
compiler: gcc
cache:
- ccache
- apt
Expand Down Expand Up @@ -38,25 +33,15 @@ env:
- JOB_NAME=encrypted_env # 16-18 minutes

matrix:
exclude:
- os: osx
env: TEST_GROUP=1
- os: osx
env: TEST_GROUP=2
- os: osx
env: TEST_GROUP=3
- os: osx
env: TEST_GROUP=4
- os: osx
env: JOB_NAME=lite_build
- os: osx
env: JOB_NAME=examples
- os: osx
env: JOB_NAME=encrypted_env
- os : linux
compiler: clang
- os: osx
compiler: gcc
include:
- os: linux
arch: arm64-graviton2
virt: vm
env: TEST_GROUP=platform_dependent
- os: osx
os_image: xcode12.2
compailer: clang
env: TEST_GROUP=platform_dependent


# https://docs.travis-ci.com/user/caching/#ccache-cache
Expand Down
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
endif(HAS_ALTIVEC)
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64|arm64")
Copy link
Member

Choose a reason for hiding this comment

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

why the original PR of rocksdb doesn't have this problem?

Copy link
Author

Choose a reason for hiding this comment

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

The developer of that PR uses an early DTK. The CPU of the DTK is different from an M1.

I don't know if it's due to system or CPU updates, however.

CHECK_C_COMPILER_FLAG("-march=armv8-a+crc" HAS_ARMV8_CRC)
if(HAS_ARMV8_CRC)
message(STATUS " HAS_ARMV8_CRC yes")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crc -Wno-unused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc -Wno-unused-function")
endif(HAS_ARMV8_CRC)
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64|arm64")

option(PORTABLE "build a portable binary" OFF)
option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
Expand Down Expand Up @@ -408,11 +408,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Cygwin")
add_definitions(-fno-builtin-memcmp -DCYGWIN)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions(-DOS_MACOSX)
if(CMAKE_SYSTEM_PROCESSOR MATCHES arm)
add_definitions(-DIOS_CROSS_COMPILE -DROCKSDB_LITE)
# no debug info for IOS, that will make our library big
add_definitions(-DNDEBUG)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DOS_LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
Expand Down Expand Up @@ -485,6 +480,11 @@ if(HAVE_SCHED_GETCPU)
add_definitions(-DROCKSDB_SCHED_GETCPU_PRESENT)
endif()

check_cxx_symbol_exists(getauxval auvx.h HAVE_AUXV_GETAUXVAL)
if(HAVE_AUXV_GETAUXVAL)
add_definitions(-DROCKSDB_AUXV_GETAUXVAL_PRESENT)
endif()

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.7.0/fused-src)
Expand Down
2 changes: 1 addition & 1 deletion util/bloom_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ TEST_F(FullBloomTest, FullVaryingLengths) {
}
Build();

ASSERT_LE(FilterSize(), (size_t)((length * 10 / 8) + 128 + 5)) << length;
ASSERT_LE(FilterSize(), (size_t)((length * 10 / 8) + CACHE_LINE_SIZE * 2 + 5)) << length;

// All added keys must match
for (int i = 0; i < length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static bool isAltiVec() {
}
#endif

#if defined(__linux__) && defined(HAVE_ARM64_CRC)
#if defined(HAVE_ARM64_CRC)
uint32_t ExtendARMImpl(uint32_t crc, const char *buf, size_t size) {
return crc32c_arm64(crc, (const unsigned char *)buf, size);
}
Expand All @@ -488,7 +488,7 @@ std::string IsFastCrc32Supported() {
has_fast_crc = false;
arch = "PPC";
#endif
#elif defined(__linux__) && defined(HAVE_ARM64_CRC)
#elif defined(HAVE_ARM64_CRC)
if (crc32c_runtime_check()) {
has_fast_crc = true;
arch = "Arm64";
Expand Down Expand Up @@ -1220,7 +1220,7 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) {
static inline Function Choose_Extend() {
#ifdef HAVE_POWER8
return isAltiVec() ? ExtendPPCImpl : ExtendImpl<Slow_CRC32>;
#elif defined(__linux__) && defined(HAVE_ARM64_CRC)
#elif defined(HAVE_ARM64_CRC)
if(crc32c_runtime_check()) {
return ExtendARMImpl;
} else {
Expand Down
12 changes: 10 additions & 2 deletions util/crc32c_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@

#include "util/crc32c_arm64.h"

#if defined(__linux__) && defined(HAVE_ARM64_CRC)
#if defined(HAVE_ARM64_CRC)

#if defined(__linux__)
#include <asm/hwcap.h>
#endif
#ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT
#include <sys/auxv.h>
#endif
#ifndef HWCAP_CRC32
#define HWCAP_CRC32 (1 << 7)
#endif
uint32_t crc32c_runtime_check(void) {
#ifdef ROCKSDB_AUXV_GETAUXVAL_PRESENT
uint64_t auxv = getauxval(AT_HWCAP);
return (auxv & HWCAP_CRC32) != 0;
#else
return 0;
#endif
}

uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data,
unsigned len) {
size_t len) {
const uint8_t *buf8;
const uint64_t *buf64 = (uint64_t *)data;
int length = (int)len;
Expand Down
3 changes: 2 additions & 1 deletion util/crc32c_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define UTIL_CRC32C_ARM64_H

#include <cinttypes>
#include <cstddef>

#if defined(__aarch64__) || defined(__AARCH64__)

Expand All @@ -18,7 +19,7 @@
#define crc32c_u32(crc, v) __crc32cw(crc, v)
#define crc32c_u64(crc, v) __crc32cd(crc, v)

extern uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, unsigned len);
extern uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, size_t len);
extern uint32_t crc32c_runtime_check(void);

#ifdef __ARM_FEATURE_CRYPTO
Expand Down