Permalink
Browse files

Initial libuv support build.

  • Loading branch information...
xmrig committed Jun 4, 2017
1 parent 7741c34 commit 668b23c5b00e3e6de1e263693222c3af6addd976
Showing with 1,821 additions and 386 deletions.
  1. +1 −0 .gitignore
  2. +38 −115 CMakeLists.txt
  3. +8 −0 cmake/FindUV.cmake
  4. BIN {win → res}/app.ico
  5. +1 −1 {win → res}/app.rc
  6. +2 −0 {compat → src/3rdparty}/jansson/CMakeLists.txt
  7. 0 {compat → src/3rdparty}/jansson/LICENSE
  8. +57 −7 {compat → src/3rdparty}/jansson/dump.c
  9. 0 {compat → src/3rdparty}/jansson/error.c
  10. 0 {compat → src/3rdparty}/jansson/hashtable.c
  11. 0 {compat → src/3rdparty}/jansson/hashtable.h
  12. +2 −2 {compat → src/3rdparty}/jansson/hashtable_seed.c
  13. +6 −2 {compat → src/3rdparty}/jansson/jansson.h
  14. 0 {compat → src/3rdparty}/jansson/jansson_config.h
  15. +1 −0 {compat → src/3rdparty}/jansson/jansson_private.h
  16. 0 {compat → src/3rdparty}/jansson/jansson_private_config.h
  17. +46 −3 {compat → src/3rdparty}/jansson/load.c
  18. 0 {compat → src/3rdparty}/jansson/lookup3.h
  19. 0 {compat → src/3rdparty}/jansson/memory.c
  20. 0 {compat → src/3rdparty}/jansson/pack_unpack.c
  21. 0 {compat → src/3rdparty}/jansson/strbuffer.c
  22. 0 {compat → src/3rdparty}/jansson/strbuffer.h
  23. 0 {compat → src/3rdparty}/jansson/strconv.c
  24. 0 {compat → src/3rdparty}/jansson/utf.c
  25. 0 {compat → src/3rdparty}/jansson/utf.h
  26. 0 {compat → src/3rdparty}/jansson/value.c
  27. +4 −4 compat/winansi.c → src/3rdparty/winansi.cpp
  28. +1 −4 {compat → src/3rdparty}/winansi.h
  29. +84 −0 src/App.cpp
  30. +23 −18 utils/threads.h → src/App.h
  31. +139 −0 src/Console.cpp
  32. +81 −0 src/Console.h
  33. +433 −0 src/Options.cpp
  34. +94 −0 src/Options.h
  35. 0 { → src}/donate.h
  36. +40 −0 src/interfaces/IClientListener.h
  37. +311 −0 src/net/Client.cpp
  38. +87 −0 src/net/Client.h
  39. +65 −0 src/net/Network.cpp
  40. +56 −0 src/net/Network.h
  41. +64 −0 src/net/Network_win.cpp
  42. +93 −0 src/net/Url.cpp
  43. +49 −0 src/net/Url.h
  44. +4 −4 { → src}/version.h
  45. +31 −0 src/xmrig.cpp
  46. +0 −151 utils/applog.c
  47. +0 −75 utils/applog.h
View
@@ -1 +1,2 @@
/build
/CMakeLists.txt.user
View
@@ -1,99 +1,55 @@
cmake_minimum_required(VERSION 3.0)
project(xmrig C)
option(WITH_LIBCPUID "Use Libcpuid" ON)
option(WITH_AEON "CryptoNight-Lite support" ON)
project(xmrig)
set(HEADERS
compat.h
algo/cryptonight/cryptonight.h
algo/cryptonight/cryptonight_aesni.h
algo/cryptonight/cryptonight_softaes.h
elist.h
xmrig.h
version.h
options.h
cpu.h
persistent_memory.h
stratum.h
stats.h
util.h
donate.h
)
set(HEADERS_CRYPTO
crypto/c_groestl.h
crypto/c_blake256.h
crypto/c_jh.h
crypto/c_skein.h
)
set(HEADERS_COMPAT
compat/winansi.h
)
set(HEADERS_UTILS
utils/applog.h
utils/threads.h
utils/summary.h
src/App.h
src/interfaces/IClientListener.h
src/net/Client.h
src/net/Network.h
src/net/Url.h
src/Options.h
src/Console.h
src/version.h
)
set(SOURCES
xmrig.c
algo/cryptonight/cryptonight.c
algo/cryptonight/cryptonight_av1_aesni.c
algo/cryptonight/cryptonight_av2_aesni_double.c
algo/cryptonight/cryptonight_av3_softaes.c
algo/cryptonight/cryptonight_av4_softaes_double.c
util.c
options.c
stratum.c
stats.c
memory.c
)
set(SOURCES_CRYPTO
crypto/c_keccak.c
crypto/c_groestl.c
crypto/c_blake256.c
crypto/c_jh.c
crypto/c_skein.c
crypto/soft_aes.c
)
set(SOURCES_UTILS
utils/applog.c
utils/summary.c
src/App.cpp
src/net/Client.cpp
src/net/Network.cpp
src/net/Url.cpp
src/Options.cpp
src/Console.cpp
src/xmrig.cpp
)
if (WIN32)
set(SOURCES_OS win/cpu_win.c win/memory_win.c win/xmrig_win.c win/app.rc compat/winansi.c)
set(EXTRA_LIBS ws2_32)
add_definitions(/D_WIN32_WINNT=0x600)
elseif (APPLE)
set(SOURCES_OS mac/cpu_mac.c mac/memory_mac.c mac/xmrig_mac.c)
set(SOURCES_OS
res/app.rc
src/3rdparty/winansi.cpp
src/3rdparty/winansi.h
src/net/Network_win.cpp
)
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv)
else()
set(SOURCES_OS unix/cpu_unix.c unix/memory_unix.c unix/xmrig_unix.c)
set(EXTRA_LIBS pthread)
endif()
include_directories(.)
add_definitions(/DUSE_NATIVE_THREADS)
add_definitions(/D_GNU_SOURCE)
add_definitions(/DUNICODE)
add_definitions(/DAPP_DEBUG)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wno-pointer-to-int-cast")
find_package(UV REQUIRED)
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -fmerge-all-constants")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -gdwarf-2")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate")
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-use -fprofile-correction")
@@ -102,45 +58,12 @@ if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
include_directories(compat/jansson)
add_subdirectory(compat/jansson)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
add_definitions(/DCURL_STATICLIB)
link_directories(${CURL_LIBRARIES})
if (WITH_LIBCPUID)
add_subdirectory(compat/libcpuid)
include_directories(compat/libcpuid)
set(CPUID_LIB cpuid)
set(SOURCES_CPUID cpu.c)
else()
add_definitions(/DXMRIG_NO_LIBCPUID)
set(SOURCES_CPUID cpu_stub.c)
endif()
if (WITH_AEON)
set(SOURCES_AEON
algo/cryptonight-lite/cryptonight_lite_av1_aesni.c
algo/cryptonight-lite/cryptonight_lite_av2_aesni_double.c
algo/cryptonight-lite/cryptonight_lite_av3_softaes.c
algo/cryptonight-lite/cryptonight_lite_av4_softaes_double.c
algo/cryptonight-lite/cryptonight_lite_aesni.h
algo/cryptonight-lite/cryptonight_lite_softaes.h
)
else()
add_definitions(/DXMRIG_NO_AEON)
endif()
include_directories(src)
include_directories(src/3rdparty)
include_directories(src/3rdparty/jansson)
include_directories(${UV_INCLUDE_DIR})
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
add_executable(xmrig ${HEADERS} ${HEADERS_CRYPTO} ${SOURCES} ${SOURCES_CRYPTO} ${HEADERS_UTILS} ${SOURCES_UTILS} ${HEADERS_COMPAT} ${SOURCES_COMPAT} ${SOURCES_OS} ${SOURCES_CPUID} ${SOURCES_AEON})
target_link_libraries(xmrig jansson curl ${CPUID_LIB} ${EXTRA_LIBS})
else()
add_executable(xmrig32 ${HEADERS} ${HEADERS_CRYPTO} ${SOURCES} ${SOURCES_CRYPTO} ${HEADERS_UTILS} ${SOURCES_UTILS} ${HEADERS_COMPAT} ${SOURCES_COMPAT} ${SOURCES_OS} ${SOURCES_CPUID} ${SOURCES_AEON})
target_link_libraries(xmrig32 jansson curl ${CPUID_LIB} ${EXTRA_LIBS})
endif()
add_subdirectory(src/3rdparty/jansson)
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS})
target_link_libraries(xmrig jansson ${UV_LIBRARIES} ${EXTRA_LIBS})
View
@@ -0,0 +1,8 @@
find_path(UV_INCLUDE_DIR NAMES uv.h)
find_library(UV_LIBRARY NAMES libuv)
set(UV_LIBRARIES ${UV_LIBRARY})
set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(UV DEFAULT_MSG UV_LIBRARY UV_INCLUDE_DIR)
File renamed without changes.
@@ -1,5 +1,5 @@
#include <windows.h>
#include "../version.h"
#include "../src/version.h"
IDI_ICON1 ICON DISCARDABLE "app.ico"
@@ -6,6 +6,8 @@ add_definitions(-DHAVE_CONFIG_H)
# Add the lib sources.
file(GLOB JANSSON_SRC *.c)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os")
set(JANSSON_HDR_PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/hashtable.h
${CMAKE_CURRENT_SOURCE_DIR}/jansson_private.h
File renamed without changes.
@@ -9,13 +9,17 @@
#define _GNU_SOURCE
#endif
#include "jansson_private.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "jansson.h"
#include "jansson_private.h"
#include "strbuffer.h"
#include "utf.h"
@@ -25,11 +29,28 @@
#define FLAGS_TO_INDENT(f) ((f) & 0x1F)
#define FLAGS_TO_PRECISION(f) (((f) >> 11) & 0x1F)
struct buffer {
const size_t size;
size_t used;
char *data;
};
static int dump_to_strbuffer(const char *buffer, size_t size, void *data)
{
return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
}
static int dump_to_buffer(const char *buffer, size_t size, void *data)
{
struct buffer *buf = (struct buffer *)data;
if(buf->used + size <= buf->size)
memcpy(&buf->data[buf->used], buffer, size);
buf->used += size;
return 0;
}
static int dump_to_file(const char *buffer, size_t size, void *data)
{
FILE *dest = (FILE *)data;
@@ -38,6 +59,16 @@ static int dump_to_file(const char *buffer, size_t size, void *data)
return 0;
}
static int dump_to_fd(const char *buffer, size_t size, void *data)
{
int *dest = (int *)data;
#ifdef HAVE_UNISTD_H
if(write(*dest, buffer, size) == (ssize_t)size)
return 0;
#endif
return -1;
}
/* 32 spaces (the maximum indentation size) */
static const char whitespace[] = " ";
@@ -168,6 +199,10 @@ static int compare_keys(const void *key1, const void *key2)
static int do_dump(const json_t *json, size_t flags, int depth,
json_dump_callback_t dump, void *data)
{
int embed = flags & JSON_EMBED;
flags &= ~JSON_EMBED;
if(!json)
return -1;
@@ -227,11 +262,11 @@ static int do_dump(const json_t *json, size_t flags, int depth,
n = json_array_size(json);
if(dump("[", 1, data))
if(!embed && dump("[", 1, data))
goto array_error;
if(n == 0) {
array->visited = 0;
return dump("]", 1, data);
return embed ? 0 : dump("]", 1, data);
}
if(dump_indent(flags, depth + 1, 0, dump, data))
goto array_error;
@@ -255,7 +290,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
}
array->visited = 0;
return dump("]", 1, data);
return embed ? 0 : dump("]", 1, data);
array_error:
array->visited = 0;
@@ -286,11 +321,11 @@ static int do_dump(const json_t *json, size_t flags, int depth,
iter = json_object_iter((json_t *)json);
if(dump("{", 1, data))
if(!embed && dump("{", 1, data))
goto object_error;
if(!iter) {
object->visited = 0;
return dump("}", 1, data);
return embed ? 0 : dump("}", 1, data);
}
if(dump_indent(flags, depth + 1, 0, dump, data))
goto object_error;
@@ -386,7 +421,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
}
object->visited = 0;
return dump("}", 1, data);
return embed ? 0 : dump("}", 1, data);
object_error:
object->visited = 0;
@@ -416,11 +451,26 @@ char *json_dumps(const json_t *json, size_t flags)
return result;
}
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
{
struct buffer buf = { size, 0, buffer };
if(json_dump_callback(json, dump_to_buffer, (void *)&buf, flags))
return 0;
return buf.used;
}
int json_dumpf(const json_t *json, FILE *output, size_t flags)
{
return json_dump_callback(json, dump_to_file, (void *)output, flags);
}
int json_dumpfd(const json_t *json, int output, size_t flags)
{
return json_dump_callback(json, dump_to_fd, (void *)&output, flags);
}
int json_dump_file(const json_t *json, const char *path, size_t flags)
{
int result;
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -168,12 +168,12 @@ static uint32_t generate_seed() {
int done = 0;
#if !defined(_WIN32) && defined(USE_URANDOM)
if (!done && seed_from_urandom(&seed) == 0)
if (seed_from_urandom(&seed) == 0)
done = 1;
#endif
#if defined(_WIN32) && defined(USE_WINDOWS_CRYPTOAPI)
if (!done && seed_from_windows_cryptoapi(&seed) == 0)
if (seed_from_windows_cryptoapi(&seed) == 0)
done = 1;
#endif
Oops, something went wrong.

0 comments on commit 668b23c

Please sign in to comment.