Skip to content

Commit f928daf

Browse files
authored
Buildable under Android (monkins1010#6)
* Include missing pthreads barrier functions, if Android version is less than 24; Also barrier functions renamed for skip naming collisions * Updated Makefile.am, configure.sh and utils.cpp to support Android * Skip pthread_setcanceltype if under Android < 24 * Updated config.guess to the latest version * Android < 23 doesn't support thread affinity * Include sys/endian.h if Android * Added build instructions on Android * Android readme updated: added command to patch gcc before build * Beautify the readme * Fixed README-ANDROID.md * Fixed README-ANDROID * Updated android readme * Fixed builds on Android 24+ * Readme updated * Fixed warnings and undefined behavior (possible overflow bug) in haraka logic
1 parent 85e4ee0 commit f928daf

12 files changed

+664
-444
lines changed

Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ ccminer_LDFLAGS += -L/usr/local/llvm/lib
4040
ccminer_LDADD += -lomp
4141
endif
4242

43-
43+
if HAVE_ANDROID
44+
ccminer_LDADD += -llog
45+
endif
4446

4547

README-ANDROID.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
**How to compile on Android**
2+
3+
*NOTE: Tested on rooted Android 6*
4+
5+
There are two methods (or more?), to compile `ccminer` on Android:
6+
7+
1. By installing a Linux distribution with help of `Termux` + `proot-distro`: https://medium.com/veruscoin/mining-veruscoin-on-smartphone-208dbb06905f
8+
2. By compiling without the any Linux distribution, purely on the system.
9+
10+
This document explains the second way.
11+
12+
# Step 1 - Install the Termux
13+
14+
Download and install the [Termux](https://play.google.com/store/apps/details?id=com.termux) application.
15+
Open the Termux after install. Next steps we need to do inside it.
16+
17+
# Step 2 - Install the dependency packages
18+
19+
Run following command, to install the development dependencies:
20+
21+
`pkg install automake build-essential curl git gnupg openssl nano`
22+
23+
# Step 3 - Install a GCC
24+
25+
I can't build the `ccminer` with `clang` that default compiler which comes with `Termux` (and Termux makes `clang` as alias for `gcc`).
26+
Also, Termux deprecated a _real_ gcc compiler tools, so we need to use [Its-Pointless Termux repo](https://github.com/its-pointless/gcc_termux), to install gcc from it.
27+
28+
Run the following command, to set-up _Its-Pointless Termux Repo_:
29+
30+
`curl -s https://its-pointless.github.io/setup-pointless-repo.sh | bash`
31+
32+
Then we need to install `gcc-6` (or `gcc-7`, `gcc-8`, `gcc-9`, `gcc-10`) package:
33+
34+
`pkg install gcc-6`
35+
36+
(or `pkg install gcc-7`, `pkg install gcc-8`, `pkg install gcc-9`, `pkg install gcc-10`, it depends on the Android version you are running)
37+
38+
# Step 4 - Build
39+
40+
Clone the `ccminer` git repo (`ARM` branch):
41+
42+
`git clone --single-branch -b ARM https://github.com/shmutalov/ccminer.git`
43+
44+
Then change the current directory:
45+
46+
`cd ccminer`
47+
48+
To build `ccminer` from sources we need to switch the default `clang` compiler to the `gcc` we installed on step 3 by executing following commands:
49+
50+
`setupgcc-6`
51+
52+
(or `setupgcc-7`, `setupgcc-8`, `setupgcc-9`, `setupgcc-10`)
53+
54+
and then (to make `configure` process happy)
55+
56+
`setup-patchforgcc`
57+
58+
Then start the build:
59+
60+
`./build.sh`
61+
62+
After successful build you can run built `ccminer` binary file to start the mining

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ Compile on Linux
3434
----------------
3535

3636
Please see [INSTALL](https://github.com/tpruvot/ccminer/blob/linux/INSTALL) file or [project Wiki](https://github.com/tpruvot/ccminer/wiki/Compatibility)
37+
38+
Compile on Android
39+
------------------
40+
41+
Please see [README-ANDROID](./README-ANDROID.md) file

api.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,10 @@ static void *mcast_thread(void *userdata)
10771077
struct thr_info *mythr = (struct thr_info *)userdata;
10781078

10791079
pthread_detach(pthread_self());
1080+
1081+
#if !(defined(__ANDROID__) || (__ANDROID_API__ > 23))
10801082
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
1083+
#endif
10811084

10821085
mcast();
10831086

bench.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
#include "miner.h"
1010
#include "algos.h"
1111

12-
#ifdef __APPLE__
12+
#if defined(__APPLE__) || (defined(__ANDROID__) && (__ANDROID_API__ < 24))
1313
#include "compat/pthreads/pthread_barrier.hpp"
14+
#else
15+
#define pthread_barrier_init_ pthread_barrier_init
16+
#define pthread_barrier_destroy_ pthread_barrier_destroy
17+
#define pthread_barrier_wait_ pthread_barrier_wait
1418
#endif
1519

1620
int bench_algo = -1;
@@ -30,16 +34,16 @@ void bench_init(int threads)
3034
{
3135
bench_algo = opt_algo = (enum sha_algos) 0; /* first */
3236
applog(LOG_BLUE, "Starting benchmark mode with %s", algo_names[opt_algo]);
33-
pthread_barrier_init(&miner_barr, NULL, threads);
34-
pthread_barrier_init(&algo_barr, NULL, threads);
37+
pthread_barrier_init_(&miner_barr, NULL, threads);
38+
pthread_barrier_init_(&algo_barr, NULL, threads);
3539
// required for usage of first algo.
3640

3741
}
3842

3943
void bench_free()
4044
{
41-
pthread_barrier_destroy(&miner_barr);
42-
pthread_barrier_destroy(&algo_barr);
45+
pthread_barrier_destroy_(&miner_barr);
46+
pthread_barrier_destroy_(&algo_barr);
4347
}
4448

4549
// required to switch algos
@@ -104,7 +108,7 @@ bool bench_algo_switch_next(int thr_id)
104108

105109
// we need to wait completion on all cards before the switch
106110
if (opt_n_threads > 1) {
107-
pthread_barrier_wait(&miner_barr);
111+
pthread_barrier_wait_(&miner_barr);
108112
}
109113

110114
char rate[32] = { 0 };
@@ -126,7 +130,7 @@ bool bench_algo_switch_next(int thr_id)
126130

127131
// wait the other threads to display logs correctly
128132
if (opt_n_threads > 1) {
129-
pthread_barrier_wait(&algo_barr);
133+
pthread_barrier_wait_(&algo_barr);
130134
}
131135

132136
if (algo == ALGO_AUTO)

ccminer.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,11 @@ static void affine_to_cpu_mask(int id, unsigned long mask) {
547547
sched_setaffinity(0, sizeof(&set), &set);
548548
} else {
549549
// thread only
550+
#if !(defined(__ANDROID__) || (__ANDROID_API__ > 23))
550551
pthread_setaffinity_np(thr_info[id].pth, sizeof(&set), &set);
552+
#else
553+
sched_setaffinity(0, sizeof(&set), &set);
554+
#endif
551555
}
552556
}
553557
#elif defined(__FreeBSD__) /* FreeBSD specific policy and affinity management */

compat/pthreads/pthread_barrier.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct
1818
} pthread_barrier_t;
1919

2020

21-
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
21+
int pthread_barrier_init_(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
2222
{
2323
if(count == 0)
2424
{
@@ -40,14 +40,14 @@ int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t
4040
return 0;
4141
}
4242

43-
int pthread_barrier_destroy(pthread_barrier_t *barrier)
43+
int pthread_barrier_destroy_(pthread_barrier_t *barrier)
4444
{
4545
pthread_cond_destroy(&barrier->cond);
4646
pthread_mutex_destroy(&barrier->mutex);
4747
return 0;
4848
}
4949

50-
int pthread_barrier_wait(pthread_barrier_t *barrier)
50+
int pthread_barrier_wait_(pthread_barrier_t *barrier)
5151
{
5252
pthread_mutex_lock(&barrier->mutex);
5353
++(barrier->count);

0 commit comments

Comments
 (0)