Skip to content

Commit

Permalink
Windows compilation support using clang from mingw64 package + cuda m…
Browse files Browse the repository at this point in the history
…odule using Visual C++.
  • Loading branch information
bogdanadnan committed Jan 13, 2019
1 parent e919ea0 commit a6bfd78
Show file tree
Hide file tree
Showing 45 changed files with 1,848 additions and 2,492 deletions.
61 changes: 28 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,24 @@ SET(CMAKE_INSTALL_RPATH "./")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

set(SOURCE
hash/hasher.h
http/http.cpp http/http.h
http/client.cpp http/client.h
http/server.cpp http/server.h
http/simplejson/json.h
miner/miner.cpp miner/miner.h
proxy/proxy.cpp proxy/proxy.h
app/main.cpp
app/arguments.cpp app/arguments.h common/common.h
crypt/sha512.cpp crypt/sha512.h
http/http_parser/http_parser.c http/http_parser/http_parser.h
miner/mini-gmp/mini-gmp.h miner/mini-gmp/mini-gmp.c
common/common.cpp
hash/argon2/argon2.cpp hash/argon2/argon2.h
hash/argon2/defs.h
hash/argon2/argon2profile_4_4_16384.c hash/argon2/argon2profile_1_1_524288.c
hash/argon2/blake2/blake2b.c hash/argon2/blake2/blake2.h
crypt/base64.cpp crypt/base64.h crypt/random_generator.cpp crypt/random_generator.h
autotune/autotune.cpp autotune/autotune.h
app/runner.h
hash/argon2/blake2/blake2b-round.h
hash/argon2/blake2/blake2b-load-sse41.h
hash/argon2/blake2/blake2b-load-sse2.h
hash/argon2/blake2/blake2-config.h
)
set(SOURCE_HASHER hash/hasher.cpp hash/hasher.h)
set(SOURCE_COMMON app/arguments.cpp app/arguments.h common/common.h common/common.cpp common/dllimport.h common/dllexport.h
crypt/sha512.cpp crypt/sha512.h crypt/base64.cpp crypt/base64.h crypt/random_generator.cpp crypt/random_generator.h)
set(SOURCE_HASHER hash/hasher.cpp hash/hasher.h hash/argon2/argon2.cpp hash/argon2/argon2.h
hash/argon2/defs.h hash/argon2/blake2/blake2b.c hash/argon2/blake2/blake2.h hash/argon2/blake2/blake2b-round.h
hash/argon2/blake2/blake2b-load-sse41.h hash/argon2/blake2/blake2b-load-sse2.h hash/argon2/blake2/blake2-config.h
hash/argon2/argon2profile_4_4_16384.c hash/argon2/argon2profile_1_1_524288.c)
set(SOURCE_CPU_HASHER hash/cpu/cpu_hasher.cpp hash/cpu/cpu_hasher.h)
set(SOURCE_OPENCL_HASHER hash/gpu/opencl/opencl_hasher.cpp hash/gpu/opencl/opencl_hasher.h
hash/gpu/opencl/opencl_kernel.cpp hash/gpu/opencl/opencl_kernel.h)
Expand Down Expand Up @@ -66,25 +58,30 @@ configure_file (

include_directories("${PROJECT_BINARY_DIR}")
include_directories(hash/cpu/cpu_features/include)
if(WIN32)
include_directories(win64/include)
list(APPEND SOURCE_COMMON win64/src/dlfcn.c win64/src/win64.c)
endif()

find_package(Threads)

add_subdirectory(hash/cpu/cpu_features)
set_property(TARGET cpu_features PROPERTY POSITION_INDEPENDENT_CODE ON)

add_executable(ariominer ${SOURCE})
add_library(common SHARED ${SOURCE_COMMON})
add_library(hasher SHARED ${SOURCE_HASHER})
target_compile_definitions(hasher PRIVATE EXPORT_SYMBOLS=1)
target_link_libraries(hasher ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})

target_link_libraries(hasher common ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
if(WIN32)
target_link_libraries(common Psapi.lib)
endif()
add_library(cpu_hasher MODULE ${SOURCE_CPU_HASHER})
set_target_properties(cpu_hasher
PROPERTIES
PREFIX ""
SUFFIX ".hsh"
LIBRARY_OUTPUT_DIRECTORY modules
)
target_compile_definitions(cpu_hasher PRIVATE EXPORT_SYMBOLS=1)
target_link_libraries(cpu_hasher hasher cpu_features)
add_dependencies(ariominer cpu_hasher)

Expand All @@ -103,7 +100,6 @@ if(NOT WITHOUT_CUDA)
SUFFIX ".hsh"
LIBRARY_OUTPUT_DIRECTORY modules
)
target_compile_definitions(cuda_hasher PRIVATE EXPORT_SYMBOLS=1)
target_link_libraries(cuda_hasher hasher)
add_dependencies(ariominer cuda_hasher)
endif()
Expand All @@ -119,7 +115,6 @@ if(NOT WITHOUT_OPENCL)
SUFFIX ".hsh"
LIBRARY_OUTPUT_DIRECTORY modules
)
target_compile_definitions(opencl_hasher PRIVATE EXPORT_SYMBOLS=1)
target_link_libraries(opencl_hasher hasher ${OpenCL_LIBRARY})
add_dependencies(ariominer opencl_hasher)

Expand All @@ -137,18 +132,16 @@ if(NOT WITHOUT_OPENCL)
SUFFIX ".hsh"
LIBRARY_OUTPUT_DIRECTORY modules
)
target_compile_definitions(amdgcn_hasher PRIVATE EXPORT_SYMBOLS=1)
set_property(TARGET CLRXCLHelperStatic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET CLRXAmdAsmStatic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET CLRXAmdBinStatic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET CLRXUtilsStatic PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(amdgcn_hasher hasher CLRXCLHelperStatic CLRXAmdAsmStatic
CLRXAmdBinStatic CLRXUtilsStatic ${OpenCL_LIBRARY})
add_dependencies(ariominer amdgcn_hasher)
endif()
endif()

target_link_libraries(ariominer hasher)
target_link_libraries(ariominer common hasher)
if(WIN32)
target_link_libraries(ariominer ws2_32.lib)
endif()

add_library(argon2_fill_blocks_REF MODULE ${ARGON2_FILL_BLOCKS_SRC})
set_target_properties(argon2_fill_blocks_REF
Expand All @@ -157,7 +150,7 @@ set_target_properties(argon2_fill_blocks_REF
SUFFIX ".opt"
LIBRARY_OUTPUT_DIRECTORY modules
)
target_compile_definitions(argon2_fill_blocks_REF PRIVATE EXPORT_SYMBOLS=1 BUILD_REF=1)
target_compile_definitions(argon2_fill_blocks_REF PRIVATE BUILD_REF=1)
add_dependencies(ariominer argon2_fill_blocks_REF)

if(ARCH STREQUAL "x86_64")
Expand All @@ -177,11 +170,6 @@ if(ARCH STREQUAL "x86_64")
target_compile_options(argon2_fill_blocks_AVX PRIVATE -mavx)
target_compile_options(argon2_fill_blocks_AVX2 PRIVATE -mavx2)
target_compile_options(argon2_fill_blocks_AVX512F PRIVATE -mavx512f)
target_compile_definitions(argon2_fill_blocks_SSE2 PRIVATE EXPORT_SYMBOLS=1)
target_compile_definitions(argon2_fill_blocks_SSSE3 PRIVATE EXPORT_SYMBOLS=1)
target_compile_definitions(argon2_fill_blocks_AVX PRIVATE EXPORT_SYMBOLS=1)
target_compile_definitions(argon2_fill_blocks_AVX2 PRIVATE EXPORT_SYMBOLS=1)
target_compile_definitions(argon2_fill_blocks_AVX512F PRIVATE EXPORT_SYMBOLS=1)
add_dependencies(ariominer argon2_fill_blocks_SSE2 argon2_fill_blocks_SSSE3 argon2_fill_blocks_AVX argon2_fill_blocks_AVX2 argon2_fill_blocks_AVX512F)
endif(ARCH STREQUAL "x86_64")

Expand All @@ -194,6 +182,13 @@ if(ARCH STREQUAL "arm")
LIBRARY_OUTPUT_DIRECTORY modules
)
target_compile_options(argon2_fill_blocks_NEON PRIVATE -D__NEON__ -mfpu=neon -funsafe-math-optimizations)
target_compile_definitions(argon2_fill_blocks_NEON PRIVATE EXPORT_SYMBOLS=1)
add_dependencies(ariominer argon2_fill_blocks_NEON)
endif(ARCH STREQUAL "arm")

if(WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /D_CRT_SECURE_NO_WARNINGS=1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_CRT_SECURE_NO_WARNINGS=1")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /D_CRT_SECURE_NO_WARNINGS=1")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /D_CRT_SECURE_NO_WARNINGS=1")
endif()

3 changes: 1 addition & 2 deletions app/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Created by Haifa Bogdan Adnan on 04/08/2018.
//

#include "../common/dllexport.h"
#include "../common/common.h"

#include <getopt.h>

#include "arguments.h"

arguments::arguments(int argc, char **argv) {
Expand Down
2 changes: 1 addition & 1 deletion app/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ARIOMINER_ARGUMENTS_H
#define ARIOMINER_ARGUMENTS_H

class arguments {
class DLLEXPORT arguments {
public:
arguments(int argc, char *argv[]);

Expand Down
3 changes: 2 additions & 1 deletion common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by Haifa Bogdan Adnan on 05/08/2018.
//

#include "dllexport.h"
#include "common.h"
#include <dirent.h>

Expand All @@ -18,7 +19,7 @@ vector<string> get_files(string folder) {
if ((dir = opendir (folder.c_str())) != NULL) {
while ((ent = readdir (dir)) != NULL) {
if(ent->d_type == DT_REG)
result.push_back(ent->d_name);
result.push_back(ent->d_name);
}
closedir (dir);
}
Expand Down
13 changes: 4 additions & 9 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <signal.h>

#include <dlfcn.h>
#include "dllexport.h"
#include "dllimport.h"

#ifndef _WIN64
#include <unistd.h>
Expand All @@ -38,11 +38,7 @@
#include<arpa/inet.h>
#include <fcntl.h>
#else
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <win64_compatibility_layer.h>

#define close closesocket
#include <win64.h>
#endif

#include <config.h>
Expand All @@ -51,8 +47,7 @@ using namespace std;

#define LOG(msg) cout<<msg<<endl

uint64_t microseconds();
vector<string> get_files(string folder);

DLLEXPORT uint64_t microseconds();
DLLEXPORT vector<string> get_files(string folder);

#endif //ARIOMINER_COMMON_H
8 changes: 3 additions & 5 deletions common/dllexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
#ifndef ARIOMINER_DLLEXPORT_H
#define ARIOMINER_DLLEXPORT_H

#undef DLLEXPORT

#ifndef _WIN64
#define DLLEXPORT
#else
#ifdef EXPORT_SYMBOLS
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#define DLLEXPORT __declspec(dllexport)
#endif

#endif //ARIOMINER_DLLEXPORT_H
16 changes: 16 additions & 0 deletions common/dllimport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by Haifa Bogdan Adnan on 04.11.2018.
//

#ifndef ARIOMINER_DLLIMPORT_H
#define ARIOMINER_DLLIMPORT_H

#ifndef DLLEXPORT
#ifndef _WIN64
#define DLLEXPORT
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#endif

#endif //ARIOMINER_DLLIMPORT_H
1 change: 1 addition & 0 deletions crypt/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by Haifa Bogdan Adnan on 17/08/2018.
//

#include "../common/dllexport.h"
#include "../common/common.h"
#include "base64.h"

Expand Down
4 changes: 1 addition & 3 deletions crypt/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
#ifndef ARIOMINER_BASE64_H
#define ARIOMINER_BASE64_H


class base64 {
class DLLEXPORT base64 {
public:
static void encode(const char *input, int input_size, char *output);
};


#endif //ARIOMINER_BASE64_H
1 change: 1 addition & 0 deletions crypt/random_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by Haifa Bogdan Adnan on 17/08/2018.
//

#include "../common/dllexport.h"
#include "../common/common.h"

#include "random_generator.h"
Expand Down
4 changes: 1 addition & 3 deletions crypt/random_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#ifndef ARIOMINER_RANDOM_GENERATOR_H
#define ARIOMINER_RANDOM_GENERATOR_H


class random_generator {
class DLLEXPORT random_generator {
public:
random_generator();
static random_generator &instance();
Expand All @@ -22,5 +21,4 @@ class random_generator {
static random_generator __instance;
};


#endif //ARIOMINER_RANDOM_GENERATOR_H
2 changes: 2 additions & 0 deletions crypt/sha512.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "../common/dllexport.h"

#include <cstring>
#include <fstream>
#include "sha512.h"
Expand Down
3 changes: 2 additions & 1 deletion crypt/sha512.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef SHA512_H
#define SHA512_H

#include <string>

class SHA512
class DLLEXPORT SHA512
{
protected:
typedef unsigned char uint8;
Expand Down
1 change: 1 addition & 0 deletions hash/argon2/argon2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../../crypt/random_generator.h"

#include "blake2/blake2.h"
#include "../../common/dllexport.h"
#include "argon2.h"
#include "defs.h"

Expand Down
2 changes: 1 addition & 1 deletion hash/argon2/argon2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

typedef void *(*argon2_blocks_filler_ptr)(void *, int, argon2profile *, void *);

class argon2 {
class DLLEXPORT argon2 {
public:
argon2(argon2_blocks_filler_ptr filler, void *seed_memory, void *user_data);

Expand Down
5 changes: 3 additions & 2 deletions hash/argon2/argon2profile_1_1_524288.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdint.h>
#include <stddef.h>
#include "../../common/dllexport.h"
#include "defs.h"

int32_t blocks_refs_1_1_524288[] = {
Expand Down Expand Up @@ -524298,7 +524299,7 @@ int32_t segments_1_1_524288[] = {
0, 524286, 0
};

argon2profile argon2profile_1_1_524288 = {
DLLEXPORT argon2profile argon2profile_1_1_524288 = {
524288,
1,
1,
Expand All @@ -524309,4 +524310,4 @@ argon2profile argon2profile_1_1_524288 = {
segments_1_1_524288
};

argon2profile *argon2profile_default = &argon2profile_1_1_524288;
DLLEXPORT argon2profile *argon2profile_default = &argon2profile_1_1_524288;
3 changes: 2 additions & 1 deletion hash/argon2/argon2profile_4_4_16384.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdint.h>
#include <stddef.h>
#include "../../common/dllexport.h"
#include "defs.h"

int32_t blocks_refs_4_4_16384[] = {
Expand Down Expand Up @@ -65606,7 +65607,7 @@ int32_t segments_4_4_16384[] = {
64504, 65528, 1
};

argon2profile argon2profile_4_4_16384 = {
DLLEXPORT argon2profile argon2profile_4_4_16384 = {
16384,
4,
4,
Expand Down
6 changes: 3 additions & 3 deletions hash/argon2/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ typedef struct Argon2Profile {
int32_t *segments; // { start, stop (excluding), with_xor }
} argon2profile;

extern argon2profile argon2profile_4_4_16384;
extern argon2profile argon2profile_1_1_524288;
extern argon2profile *argon2profile_default;
extern DLLEXPORT argon2profile argon2profile_4_4_16384;
extern DLLEXPORT argon2profile argon2profile_1_1_524288;
extern DLLEXPORT argon2profile *argon2profile_default;

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions hash/cpu/argon2_opt/implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string.h>
#include <stdlib.h>

#include "../../../common/dllimport.h"
#include "../../argon2/defs.h"
#include "../../../common/dllexport.h"

Expand Down
Loading

0 comments on commit a6bfd78

Please sign in to comment.