Skip to content

Commit

Permalink
Equi-X shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
tevador committed Jun 9, 2020
1 parent 5f21a31 commit 1d3fc13
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

cmake_minimum_required(VERSION 2.8.8)

set(EQUIX_VERSION 1)
set(EQUIX_VERSION_MINOR 0)
set(EQUIX_VERSION_PATCH 0)
set(EQUIX_VERSION_STR "${EQUIX_VERSION}.${EQUIX_VERSION_MINOR}.${EQUIX_VERSION_PATCH}")

project(equix)

add_definitions(-DHASHX_SIZE=8)
Expand All @@ -19,11 +24,25 @@ if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting default build type: ${CMAKE_BUILD_TYPE}")
endif()

add_library(equix SHARED ${equix_sources})
set_property(TARGET equix PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET equix PROPERTY PUBLIC_HEADER include/equix.h)
include_directories(equix
include/
hashx/include/
hashx/src/)
target_compile_definitions(equix PRIVATE HASHX_STATIC)
target_compile_definitions(equix PRIVATE EQUIX_SHARED)
target_link_libraries(equix
PRIVATE hashx_static)
set_target_properties(equix PROPERTIES VERSION ${EQUIX_VERSION_STR}
SOVERSION ${EQUIX_VERSION})

add_library(equix_static STATIC ${equix_sources})
set_property(TARGET equix_static PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET equix_static PROPERTY PUBLIC_HEADER include/equix.h)
set_target_properties(equix_static PROPERTIES OUTPUT_NAME equix)
target_compile_definitions(equix_static PRIVATE HASHX_STATIC)
target_compile_definitions(equix_static PRIVATE EQUIX_STATIC)
include_directories(equix_static
include/
hashx/include/
Expand All @@ -32,7 +51,7 @@ target_link_libraries(equix_static
PRIVATE hashx_static)

include(GNUInstallDirs)
install(TARGETS equix_static
install(TARGETS equix equix_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand All @@ -41,6 +60,7 @@ add_executable(equix-tests
src/tests.c)
include_directories(equix-tests
include/)
target_compile_definitions(equix-tests PRIVATE EQUIX_STATIC)
target_link_libraries(equix-tests
PRIVATE equix_static)

Expand All @@ -55,6 +75,7 @@ add_executable(equix-bench
include_directories(equix-bench
include/
hashx/src/)
target_compile_definitions(equix-bench PRIVATE EQUIX_STATIC)
target_link_libraries(equix-bench
PRIVATE equix_static
PRIVATE ${CMAKE_THREAD_LIBS_INIT})
2 changes: 1 addition & 1 deletion hashx
Submodule hashx updated 1 files
+15 −14 include/hashx.h
31 changes: 27 additions & 4 deletions include/equix.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ typedef enum equix_ctx_flags {
/* Sentinel value used to indicate unsupported type */
#define EQUIX_NOTSUPP ((equix_ctx*)-1)

#if defined(_WIN32) || defined(__CYGWIN__)
#define EQUIX_WIN
#endif

/* Shared/static library definitions */
#ifdef EQUIX_WIN
#ifdef EQUIX_SHARED
#define EQUIX_API __declspec(dllexport)
#elif !defined(EQUIX_STATIC)
#define EQUIX_API __declspec(dllimport)
#else
#define EQUIX_API
#endif
#define EQUIX_PRIVATE
#else
#ifdef EQUIX_SHARED
#define EQUIX_API __attribute__ ((visibility ("default")))
#else
#define EQUIX_API __attribute__ ((visibility ("hidden")))
#endif
#define EQUIX_PRIVATE __attribute__ ((visibility ("hidden")))
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -73,14 +96,14 @@ extern "C" {
* allocation failure and EQUIX_NOTSUPP if the requested type
* is not supported.
*/
equix_ctx* equix_alloc(equix_ctx_flags flags);
EQUIX_API equix_ctx* equix_alloc(equix_ctx_flags flags);

/*
* Free an Equi-X a context.
*
* @param ctx is a pointer to the context
*/
void equix_free(equix_ctx* ctx);
EQUIX_API void equix_free(equix_ctx* ctx);

/*
* Find Equi-X solutions for the given challenge.
Expand All @@ -93,7 +116,7 @@ void equix_free(equix_ctx* ctx);
*
* @return the number of solutions found
*/
int equix_solve(
EQUIX_API int equix_solve(
equix_ctx* ctx,
const void* challenge,
size_t challenge_size,
Expand All @@ -109,7 +132,7 @@ int equix_solve(
*
* @return verification result
*/
equix_result equix_verify(
EQUIX_API equix_result equix_verify(
equix_ctx* ctx,
const void* challenge,
size_t challenge_size,
Expand Down
2 changes: 1 addition & 1 deletion src/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ static inline bool tree_cmp4(const equix_idx* left, const equix_idx* right) {
return load64(left) <= load64(right);
}

int equix_solver_solve(hashx_ctx* hash_func, solver_heap* heap, equix_solution output[EQUIX_MAX_SOLS]);
EQUIX_PRIVATE int equix_solver_solve(hashx_ctx* hash_func, solver_heap* heap, equix_solution output[EQUIX_MAX_SOLS]);

#endif

0 comments on commit 1d3fc13

Please sign in to comment.