Skip to content

[WIP] Fix macOS libcachesim installation #183

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

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertNewlineAtEOF: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
Expand Down
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
225b07e41f03d82358171a3d91ab3f210d0ae783 # ignore repository-wide reformat
15 changes: 2 additions & 13 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ jobs:
sudo apt-get install -y clang-format clang-tidy cmake g++ make
bash scripts/install_dependency.sh

- name: Get changed C/C++ files
id: changed-files
uses: tj-actions/[email protected]
with:
files: |
**/*.c
**/*.h
**/*.cpp
**/*.cc
**/*.hpp

- name: Create log directory
run: mkdir -p logs

Expand All @@ -41,7 +30,7 @@ jobs:
echo "Running clang-format checks..."
FORMAT_ERRORS=0

for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
for file in $(find . -iname '*.h' -or -iname '*.c' -or -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.cc'); do
echo "Checking formatting for $file"
if ! clang-format --dry-run --Werror "$file" >> logs/format.log 2>&1; then
echo "::error file=$file::Formatting issues in $file"
Expand Down Expand Up @@ -72,7 +61,7 @@ jobs:
echo "Running clang-tidy checks..."
FILES_WITH_ISSUES=0

for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
for file in $(find . -iname '*.h' -or -iname '*.c' -or -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.cc'); do
echo "Checking $file with clang-tidy"
LOG_FILE="logs/tidy_$(basename "$file").log"

Expand Down
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project(libCacheSim)
set(DESCRIPTION "a high performance cache simulation library")
set(PROJECT_WEB "http://cachesim.com")

find_package(PkgConfig REQUIRED)

set(${PROJECT_NAME}_VERSION_MAJOR 0)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_PATCH 0)
Expand Down Expand Up @@ -39,7 +41,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_definitions(-DOS_DARWIN)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/opt/homebrew/include/")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/homebrew/")

elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions(-DOS_LINUX)
else()
Expand Down Expand Up @@ -116,9 +117,9 @@ message(STATUS "SUPPORT TTL ${SUPPORT_TTL}, USE_HUGEPAGE ${USE_HUGEPAGE}, LOGLEV
# #######################################
# compiler flags #
# #######################################
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wno-gnu-zero-variadic-macro-arguments")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-copy -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-copy -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs -Wno-gnu-zero-variadic-macro-arguments")

# if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# set(CFLAGS "$ENV{CFLAGS} " "-Wl,--export-dynamic ")
Expand All @@ -142,7 +143,7 @@ set(LIBS ${LIBS} ${ARGP_LIBRARY})

if(OPT_SUPPORT_ZSTD_TRACE)
add_compile_definitions(SUPPORT_ZSTD_TRACE=1)
find_package(ZSTD)
pkg_check_modules(ZSTD REQUIRED libzstd)

# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
include_directories(${ZSTD_INCLUDE_DIR})
Expand All @@ -151,6 +152,7 @@ if(OPT_SUPPORT_ZSTD_TRACE)
message(FATAL_ERROR "zstd not found")
endif()

link_directories(${ZSTD_LIBRARY_DIRS})
link_libraries(${ZSTD_LIBRARIES})
message(STATUS "ZSTD_INCLUDE_DIR ${ZSTD_INCLUDE_DIR}, ZSTD_LIBRARIES ${ZSTD_LIBRARIES}")
else()
Expand Down Expand Up @@ -349,7 +351,11 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_library(${PROJECT_NAME} ${LIB_SOURCE})
# target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--export-dynamic)

# Skip unsupported linker option for macOS (export-dynamic)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--export-dynamic)
endif()


# add_library(${PROJECT_NAME} SHARED ${LIB_SOURCE})
Expand Down
3 changes: 1 addition & 2 deletions example/cacheCluster/cacheCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace CDNSimulator {

bool CacheCluster::get(request_t *req) {
// find the server idx
uint64_t idx =
ch_ring_get_server_from_uint64(req->obj_id, this->_ring);
uint64_t idx = ch_ring_get_server_from_uint64(req->obj_id, this->_ring);

// find the server
CacheServer &server = this->_cache_servers_vec.at(idx);
Expand Down
9 changes: 4 additions & 5 deletions example/cacheCluster/consistentHash.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ int ch_ring_get_server(const char *const key, const ring_t *const ring) {
return (ring->vnodes + ch_ring_get_vnode_idx(key, ring))->server_id;
}

int ch_ring_get_server_from_uint64(uint64_t obj_id,
const ring_t *const ring) {
char key[8];
memcpy(key, (char *) &obj_id, 8);
int ch_ring_get_server_from_uint64(uint64_t obj_id, const ring_t *const ring) {
char key[8];
memcpy(key, (char *)&obj_id, 8);
key[7] = 0;
return (ring->vnodes + ch_ring_get_vnode_idx(key, ring))->server_id;
}
Expand Down Expand Up @@ -217,4 +216,4 @@ void ch_ring_destroy_ring(ring_t *ring) {

#ifdef __cplusplus
}
#endif
#endif
3 changes: 2 additions & 1 deletion example/cacheCluster/include/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#ifndef CDNSIMULATOR_CACHE_HPP
#define CDNSIMULATOR_CACHE_HPP

#include <inttypes.h>

#include <algorithm>
#include <iostream>
#include <inttypes.h>

#include "libCacheSim/cache.h"
#include "libCacheSim/evictionAlgo.h"
Expand Down
1 change: 0 additions & 1 deletion example/cacheCluster/include/cacheCluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace CDNSimulator {

class CacheCluster {
private:

// the consistent hash ring
ring_t *_ring = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion example/cacheCluster/include/consistentHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
extern "C" {
#endif

#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#define N_VNODE_PER_SERVER 160

Expand Down
25 changes: 12 additions & 13 deletions example/cacheCluster/include/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
Expand All @@ -38,17 +38,17 @@
that follows (in reverse chronological order):

2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <[email protected]>.
added conditionalization for C++ compilation from Martin
Purschke <[email protected]>.
1999-05-03 lpd Original version.
*/

#ifndef md5_INCLUDED
# define md5_INCLUDED
#define md5_INCLUDED

/*
* This package supports both compile-time and run-time determination of CPU
Expand All @@ -61,18 +61,17 @@
*/

typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */
typedef unsigned int md5_word_t; /* 32-bit word */

/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

/* Initialize the algorithm. */
Expand All @@ -95,7 +94,7 @@ _declspec(dllexport)
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);

#ifdef __cplusplus
} /* end extern "C" */
} /* end extern "C" */
#endif

#endif /* md5_INCLUDED */
Loading
Loading