Updated Compiling from source (markdown)

JayDDee
2024-12-30 21:33:38 -05:00
parent 8dbbfc9781
commit d1c4da0c77

@@ -1,4 +1,6 @@
Compiling cpuminer-opt from source code requires a different environment depending on the operating system used. Once the environment has been created the actual compile procedure is the same for all supported architectures and operating systems.
Compiling cpuminer-opt from source code requires a different environment depending on the operating system used. Once the environment has been created the actual compile procedure is the same for all supported CPU architectures and operating systems.
Linux & MacOS are supported for both x86_64 & ARM64 CPUs. Windows is supported for x86_64 but ARM64 is a work in progress.
A package is available for Windows on x86_64 with precompiled binaries which can be used instead of compiling from source for those who feel uncomfortable with compiling. There are no such binaries available for ARM64 or MacOS.
@@ -26,7 +28,7 @@ cpuminer-opt can now be compiled on Linux, see compiling section below.
cpuminer-top is compiled on Windows using MSys2 and MinGW64. This installs a Linux-like environment where cpuminer-opt can be compiled and run on a Windows computer. MS Visual Studio is not supported.
CPUs based on the x86_64 architecture (Intel & AMD) require Windows-7 64 bit and newer. ARM64 CPUs require Windows-11 or newer.
Windows on ARM64 is new and evolving quickly, stay up to date for fewer issues. Update Windows & MSys2 frequently.
Windows on ARM64 is unstable when compiled with Clang. GCC is not yet available for MinGW on ARM64.
#### Install MSys2 MinGW64
@@ -39,110 +41,101 @@ Install the following additional packages required for compiling cpuminer-opt
`$ pacman -S autotools libcurl-devel mingw-w64-x86_64-curl gmp-devel jansson-devel openssl-devel zlib-devel`
Other desired packages can also be installed at this time. Some useful ones not installed by default include
git, openssh, wget, vim, zip, unzip ...
git, openssh, wget, vim ...
There will be 3 MSys2 shortcuts installed in the Windows start menu, they have different purposes:
* MSYS2 MSYS: administration, package instalation
* MSYS2 MINGW64: compiling with GCC, used on x86_64
* MSYS2 CLANG: compiling with Clang, used on ARM64
* MSYS2 MINGW64: compiling with GCC
* MSYS2 CLANG: compiling with Clang
Ensure the correct one is used.
Ensure the correct one is used. GCC is recommended but is only avalable for x86_64 at this time. ARM64 only supports Clang which has problems described in errata below.
cpuminer-opt can now be compiled on Windows, see Compiling section below.
#### Windows integration, optional
It's possible to run cpuminer-opt from a Windows command prompt or Powershell by adding MSYS2 to the system Path environment variable otherwise it can only run from an MSYS2 terminal. FYI: https://stackoverflow.com/questions/6951938/libgmp-10-dll-is-missing
It's possible to run cpuminer-opt from a Windows command prompt or Powershell using DOS syntax by adding MSYS2 to the system Path environment variable, otherwise it can only run from an MSYS2 terminal. FYI: https://stackoverflow.com/questions/6951938/libgmp-10-dll-is-missing
If Windows tools are preferred cpuminer-opt can be downloaded to the Windows Documents folder and accessed from MSYS2 terminal using the path `/c/users/[USER]/documents`. The MSYS2 home directory can be accessed from Windows with `C:\msys2\home\[USER]`.
If Windows tools are preferred cpuminer-opt can be downloaded to the Windows Documents folder and accessed from MSYS2 terminal using the path `/c/users/[USER]/documents`.
The MSYS2 home directory can be accessed from Windows with `C:\msys2\home\[USER]`.
Notepad++ and 7zip are useful Windows programs with good support for Linux file formats.
#### Errata
* Windows on ARM64 is new and may have some isues.
* Windows on ARM64 uses Clang compiler produces many warnings that can be ignored.
* Windows on ARM64 may result in cpuminer-opt segfault when starting up. Add `-DARM_WIN_HACK` to CFLAGS to workaround it.
* Windows with CPU groups enabled may produce warning logs about CPU affinity at startup. The warnings can be ignored as affinity still seems to work correctly. CPU groups is disabled in the Windows x86_64 binaries package.
* Windows on ARM does not display CPU features correctly. The SW features are correct.
* CPU temperature and frequency reports are not supported on Windows.
* Windows on ARM64 can only be compiled with Clang at this time resulting in an unstable build that may crash.
* Windows on ARM64 may result in cpuminer-opt segfault when starting up. Add `-DARM_WIN_HACK` to CFLAGS to workaround it. This workaround may or may not work and may or may not be necessary.
* Windows on ARM does not display CPU features correctly.
# Apple MacOS build environment
Apple MacOS is supported on ARM64. Older MACs with Intel x86_64 CPU is untested and not officially supported yet. However, x86_64 is supported on other OSs and and ARM64 is now suported on MacOS so it may just work already, YMMV.
This procedure is only for Apple MAC PCs that use MacOS. iPads & iPhones use IOS which isn't supported and will not work.
Apple MacOS is supported on ARM64 and older MACs with Intel x86_64 CPUs. This procedure is only for Apple MAC PCs that use MacOS. iPads & iPhones use IOS which isn't supported and will not work.
Setting up the build environment on MacOS does not require an AppleID or need anything from the App store. Everything is done from the Terminal.
Setting up the build environment on MacOS does not require an AppleID or need anything from the App store. Everything is done from the Terminal. MacOS uses Clang compiler by default which has caused issues. GCC is strongly recommended.
#### Install developer command line tools
If Xcode is installed this is probably not necessary. Using Xcode to build cpuminer-opt has not been tested. The following installs Clang and other useful tools but not the full Xcode. Open a terminal and enter...
If Xcode is installed this is probably not necessary. Using Xcode to build cpuminer-opt has not been tested. Use xcode-select from the terminal to install the default tools withou the full Xcode.
`% xcode-select --install`
#### Homebrew package manager
Install Homebrew from https://brew.sh/. Use home brew to install missing packages. On x86_64 CPUs replace `aarch64-elf-binutils' with x86_64-elf-binutils
Install Homebrew from https://brew.sh/. Use Homebrew to install missing packages including GCC. On x86_64 CPUs replace `aarch64` with `x86_64` in targetted packages.
`% brew install aarch64-elf-binutils autoconf automake ca-certificates gettext git gmp isl jansson libmpc libunistring lz4 m4 mpfr pcre2 zstd`
`% brew install aarch64-elf-binutils aarch64-elf-gcc gcc autoconf automake ca-certificates gettext git gmp isl jansson libmpc libunistring lz4 m4 mpfr pcre2 zstd`
cpuminer-opt can now be compiled on MacOS, see compiling section below.
Homebrew compiles packages from source which can take a long time. Once install is finished find gcc. gcc is linked to clang so it's necessary to include the version to actually call gcc.
The easiest way is tyo type `gcc-` then hit TAB for command completion. If multiple versions are installed they will all be listed. To use gcc the CC & CXX environment variables must be defined with the version included. At time of writing gcc-14 is the default, change version as required. The variables may be set in the shell profile, in CFLAGS or from the command line at user's preference.
#### MacOS on X86_64
`$ export CC=gcc-14`
`$ export CXX=g++-14`
Setting up for ARM64 selected the Clang compiler which installed by default by Apple. Clang is also aliased as gcc so "gcc" is actually Clang.
GCC is available in Homebrew and can be used by setting the CC & CXX environment variables to point to the real gcc and g++.
On ARM64 GCC did not work so it may not work on x86_64 either and should only be attempted if Clang fails.
For x86_64 replace `aarch64-elf-binutils` with `x86_64-elf-binutils` when installing Homebrew packages.
cpunminer-opt can now be compiled.
#### Errata
* On MacOS m7m algo is not working due to problems linking gmp.
* MacOS on ARM64 Clang compiler is used which produces many warnings that can be ignored.
* MacOS on x86_64 is not yet supported, YMMV.
* MacOS on ARM64 does not display CPU features correctly. The SW features are correct.
* CPU temperature and frequency reports are not supported on MacOS.
* MacOS on ARM64 does not display CPU features correctly.
# Compiling cpuminer-opt
At this point it's assumed the appropriate development environment has been setup for the target operating system and a command shell is open and ready to compile.
At this point it's assumed the appropriate development environment has been setup for the target operating system and a terminal is open and ready to compile.
Download only from the official JayDDee github repository: https://github.com/JayDDee/cpuminer-opt/
Download the source code for latest version of cpuminer-opt. Download the tarball (.tar.gz) source file because zip does not preseve file attibutes which must be preserved to execute shell scripts. There are many ways to download the source code but the simplest that works in all cases is to use wget from the command shell:
Download cpuminer-opt only from the official JayDDee github repository: https://github.com/JayDDee/cpuminer-opt/
Download the source code for latest release or clone the repository. Download the source tarball (.tar.gz) to maintain file attributes.
Download from a browser or use wget (if installed) from the command line terminal.
`$ wget https://github.com/JayDDee/cpuminer-opt/archive/refs/tags/vX.Y.tar.gz`
Copy the link from a browser with X.Y pointing to the latest release.
Replace X & Y with the latest release.
Extract the source code.
`$ tar xvzf cpuminer-opt-X.Y.tar.gz`
Alternatively the latest version can be cloned from git.
Alternatively the latest version can be cloned from git if git is installed (available with Homebrew).
`$ git clone https://github.com/JayDDee/cpuminer-opt.git`
#### Build cpuminer-opt
It is recomended to Build with default options, this will usually
produce the best results. Enter the cpuminer-opt directory and run:
It is recomended to Build with default options, this will usually produce the best results. Enter the cpuminer-opt directory and run:
`$ ./build.sh`
or manually:
`$ ./autogen.sh`
`$ CFLAGS="-O3 -march=native -Wall" ./configure --with-curl`
`$ make -j N`
N is the number of threads for the compiler to use. Use `-j $(nproc)` to use all CPU cores.
Some newer CPU architectures may not be defined for `-march=native` in older versions of the compiler and may not recognize new features using the default build script. It is often possible to compile the missing features to create an optimum build by manually specifying options.
Many compile tips for x86_64 in file build-allarch.sh, and for ARM64 in arbuild-all.sh.
Many examples can be found in file build-allarch.sh for x86_64 CPUs, and for in arbuild-all.sh for ARM64 CPUs..
Windows on ARM64 may crash with a segfault. Adding `-DARM_WIN_HACK` to CFLAGS and recompiling may workaround the crash.
Windows on ARM64 may crash with a segfault. See Windows notes above. YMMV
#### Start mining.