diff --git a/.gitignore b/.gitignore index efaf7ccdc862..81bf4df95c09 100644 --- a/.gitignore +++ b/.gitignore @@ -92,6 +92,10 @@ qrc_*.cpp # Mac specific .DS_Store build +db4/ +background.tiff +background.tiff.png +background.tiff@2x.png #lcov *.gcno diff --git a/contrib/install_db4.sh b/contrib/install_db4.sh old mode 100644 new mode 100755 index d315a7d3b725..a0c1b52b889b --- a/contrib/install_db4.sh +++ b/contrib/install_db4.sh @@ -30,6 +30,8 @@ sha256_check() { # if check_exists sha256sum; then echo "${1} ${2}" | sha256sum -c + elif check_exists shasum; then + echo "${1} ${2}" | shasum -a 256 -c elif check_exists sha256; then if [ "$(uname)" = "FreeBSD" ]; then sha256 -c "${1}" "${2}" diff --git a/contrib/macdeploy/macdeployqtplus b/contrib/macdeploy/macdeployqtplus index a50f4baad31a..d7a964ba46c7 100755 --- a/contrib/macdeploy/macdeployqtplus +++ b/contrib/macdeploy/macdeployqtplus @@ -146,7 +146,7 @@ class FrameworkInfo(object): info.sourceResourcesDirectory = os.path.join(info.frameworkPath, "Resources") info.sourceContentsDirectory = os.path.join(info.frameworkPath, "Contents") info.sourceVersionContentsDirectory = os.path.join(info.frameworkPath, "Versions", info.version, "Contents") - info.destinationResourcesDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Resources") + info.destinationResourcesDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Versions", info.version, "Resources") info.destinationContentsDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Contents") info.destinationVersionContentsDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Versions", info.version, "Contents") @@ -289,6 +289,18 @@ def copyFramework(framework, path, verbose): os.symlink(linkto, linkfrom) if verbose >= 2: print("Linked:", linkfrom, "->", linkto) + + frameworkPath = os.path.join(path, "Contents", "Frameworks", framework.frameworkName) + frameworkLinks = ( + (framework.binaryName, os.path.join("Versions", "Current", framework.binaryName)), + ("Resources", os.path.join("Versions", "Current", "Resources")), + ) + for linkName, linkTarget in frameworkLinks: + linkPath = os.path.join(frameworkPath, linkName) + if not os.path.lexists(linkPath): + os.symlink(linkTarget, linkPath) + if verbose >= 2: + print("Linked:", linkPath, "->", linkTarget) fromResourcesDir = framework.sourceResourcesDirectory if os.path.exists(fromResourcesDir): toResourcesDir = os.path.join(path, framework.destinationResourcesDirectory) @@ -322,6 +334,10 @@ def deployFrameworks(frameworks, bundlePath, binaryPath, strip, verbose, deploym while len(frameworks) > 0: framework = frameworks.pop(0) + if framework.frameworkName in deploymentInfo.deployedFrameworks: + if verbose >= 2: + print(framework.frameworkName, "already deployed, skipping.") + continue deploymentInfo.deployedFrameworks.append(framework.frameworkName) if verbose >= 2: @@ -352,6 +368,16 @@ def deployFrameworks(frameworks, bundlePath, binaryPath, strip, verbose, deploym changeIdentification(framework.deployedInstallName, deployedBinaryPath, verbose) # Check for framework dependencies dependencies = getFrameworks(deployedBinaryPath, verbose) + + # Homebrew libraries commonly refer to sibling dylibs via @rpath. + # Resolve those references from the original library directory when + # copying dependencies into the application bundle. + sourceDirectory = os.path.dirname(framework.sourceFilePath) + for dependency in dependencies: + if dependency.sourceFilePath.startswith("@rpath/"): + sourceFilePath = os.path.join(sourceDirectory, os.path.basename(dependency.sourceFilePath)) + if os.path.exists(sourceFilePath): + dependency.sourceFilePath = sourceFilePath for dependency in dependencies: changeInstallName(dependency.installName, dependency.deployedInstallName, deployedBinaryPath, verbose) @@ -551,7 +577,8 @@ if len(config.fancy) == 1: sys.exit(1) try: - fancy = plistlib.readPlist(p) + with open(p, "rb") as plist_file: + fancy = plistlib.load(plist_file) except: if verbose >= 1: sys.stderr.write("Error: Could not parse fancy disk image plist at \"%s\"\n" % (p)) diff --git a/doc/build-osx.md b/doc/build-osx.md index 5bd1cabc2ffe..1e648f5cce47 100644 --- a/doc/build-osx.md +++ b/doc/build-osx.md @@ -1,5 +1,5 @@ -Mac OS X Build Instructions and Notes -==================================== +macOS Build Instructions and Notes +================================== The commands in this guide should be executed in a Terminal application. The built-in one is located in `/Applications/Utilities/Terminal.app`. @@ -14,12 +14,18 @@ When the popup appears, click `Install`. Then install [Homebrew](https://brew.sh). Dependencies ----------------------- +------------ - brew install automake berkeley-db4 libtool boost miniupnpc openssl pkg-config protobuf python3 qt libevent + brew install automake libtool boost@1.85 openssl@3 pkg-config protobuf python3 qt@5 libevent See [dependencies.md](dependencies.md) for a complete overview. +Berkeley DB 4.8 is required for wallet compatibility. Build the pinned version +with the repository helper instead of installing the current Homebrew Berkeley +DB release: + + ./contrib/install_db4.sh "$(pwd)" + If you want to build the disk image with `make deploy` (.dmg / optional), you need RSVG brew install librsvg @@ -28,7 +34,8 @@ If you want to build with ZeroMQ support brew install zeromq -NOTE: Building with Qt4 is still supported, however, could result in a broken UI. Building with Qt5 is recommended. +Current MiniUPnPc releases are not compatible with this older codebase. The +Apple Silicon configuration below disables UPnP. Qt 5 is recommended. Build Garlicoin Core ------------------------ @@ -38,32 +45,67 @@ Build Garlicoin Core git clone https://github.com/GarlicoinOrg/Garlicoin cd garlicoin -2. Build garlicoin-core: +2. Generate the configure script: + + ./autogen.sh + +3. Build Garlicoin Core: Configure and build the headless garlicoin binaries as well as the GUI (if Qt is found). You can disable the GUI build by passing `--without-gui` to configure. - ./autogen.sh ./configure make -3. It is recommended to build and run the unit tests: + On Apple Silicon with current Homebrew packages, use the following + configuration. C++17 is needed by current Protobuf/Abseil headers, while + Berkeley DB remains pinned to 4.8 for wallet compatibility. + + BDB_PREFIX="$PWD/db4" + BOOST_PREFIX="$(brew --prefix boost@1.85)" + OPENSSL_PREFIX="$(brew --prefix openssl@3)" + LIBEVENT_PREFIX="$(brew --prefix libevent)" + QT_PREFIX="$(brew --prefix qt@5)" + + ./configure \ + BDB_LIBS="-L$BDB_PREFIX/lib -ldb_cxx-4.8" \ + BDB_CFLAGS="-I$BDB_PREFIX/include" \ + CXXFLAGS="-std=c++17 -g -O2" \ + CFLAGS="-Wno-error=implicit-function-declaration" \ + CPPFLAGS="-I$BDB_PREFIX/include -I$BOOST_PREFIX/include -I$OPENSSL_PREFIX/include -I$LIBEVENT_PREFIX/include" \ + LDFLAGS="-L$BDB_PREFIX/lib -L$BOOST_PREFIX/lib -L$OPENSSL_PREFIX/lib -L$LIBEVENT_PREFIX/lib" \ + PKG_CONFIG_PATH="$QT_PREFIX/lib/pkgconfig:$OPENSSL_PREFIX/lib/pkgconfig" \ + --with-boost="$BOOST_PREFIX" \ + --with-miniupnpc=no \ + --with-gui=qt5 + + make -j"$(sysctl -n hw.logicalcpu)" + +4. It is recommended to build and run the unit tests: make check -4. You can also create a .dmg that contains the .app bundle (optional): +5. You can also create a `.dmg` containing a self-contained `.app` bundle + (optional): make deploy -5. Installation into user directories (optional): + The results are `dist/Garlicoin-Qt.app` and `Garlicoin-Qt.dmg`. For local + testing, apply an ad-hoc signature after deployment: + + codesign --force --deep --sign - dist/Garlicoin-Qt.app + + Public releases should use a Developer ID signature and notarization. + +6. Installation into user directories (optional): make install or cd ~/garlicoin/src - cp litecoind /usr/local/bin/ + cp garlicoind /usr/local/bin/ cp garlicoin-cli /usr/local/bin/ Running @@ -103,13 +145,15 @@ Uncheck everything except Qt Creator during the installation process. 5. Leave the file selection as it is 6. Confirm the "summary page" 7. In the "Projects" tab select "Manage Kits..." -8. Select the default "Desktop" kit and select "Clang (x86 64bit in /usr/bin)" as compiler +8. Select the default "Desktop" kit and the Apple Clang compiler for your architecture 9. Select LLDB as debugger (you might need to set the path to your installation) 10. Start debugging with Qt Creator Notes ----- -* Tested on OS X 10.8 through 10.13 on 64-bit Intel processors only. +* The Apple Silicon instructions were tested on macOS 27 with Homebrew arm64 + packages. The legacy build was previously tested on OS X 10.8 through 10.13 + on 64-bit Intel processors. * Building with downloaded Qt binaries is not officially supported. See the notes in [#7714](https://github.com/bitcoin/bitcoin/issues/7714) diff --git a/share/qt/Info.plist.in b/share/qt/Info.plist.in index 7597e4797600..f10fe5241a5e 100644 --- a/share/qt/Info.plist.in +++ b/share/qt/Info.plist.in @@ -7,7 +7,7 @@ LSArchitecturePriority - x86_64 + arm64 CFBundleIconFile diff --git a/src/crypto/scrypt-sse2.cpp b/src/crypto/scrypt-sse2.cpp index 0f993cd7868d..7a854d49c83d 100644 --- a/src/crypto/scrypt-sse2.cpp +++ b/src/crypto/scrypt-sse2.cpp @@ -110,7 +110,7 @@ void scrypt_N_1_1_256_sp_sse2(const char *input, char *output, char *scratchpad, for (k = 0; k < 2; k++) { for (i = 0; i < 16; i++) { - X.u32[k * 16 + i] = le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]); + X.u32[k * 16 + i] = scrypt_le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]); } } @@ -132,7 +132,7 @@ void scrypt_N_1_1_256_sp_sse2(const char *input, char *output, char *scratchpad, for (k = 0; k < 2; k++) { for (i = 0; i < 16; i++) { - le32enc(&B[(k * 16 + (i * 5 % 16)) * 4], X.u32[k * 16 + i]); + scrypt_le32enc(&B[(k * 16 + (i * 5 % 16)) * 4], X.u32[k * 16 + i]); } } diff --git a/src/crypto/scrypt.cpp b/src/crypto/scrypt.cpp index 4c2d46c9dafe..bb8e492b47f4 100644 --- a/src/crypto/scrypt.cpp +++ b/src/crypto/scrypt.cpp @@ -43,14 +43,14 @@ #include #endif #endif -static inline uint32_t be32dec(const void *pp) +static inline uint32_t scrypt_be32dec(const void *pp) { const uint8_t *p = (uint8_t const *)pp; return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); } -static inline void be32enc(void *pp, uint32_t x) +static inline void scrypt_be32enc(void *pp, uint32_t x) { uint8_t *p = (uint8_t *)pp; p[3] = x & 0xff; @@ -152,7 +152,7 @@ PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen, const uint8_t *salt, /* Iterate through the blocks. */ for (i = 0; i * 32 < dkLen; i++) { /* Generate INT(i + 1). */ - be32enc(ivec, (uint32_t)(i + 1)); + scrypt_be32enc(ivec, (uint32_t)(i + 1)); /* Compute U_1 = PRF(P, S || INT(i)). */ memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX)); @@ -264,7 +264,7 @@ void scrypt_N_1_1_256_sp_generic(const char *input, char *output, char *scratchp PBKDF2_SHA256((const uint8_t *)input, 80, (const uint8_t *)input, 80, 1, B, 128); for (k = 0; k < 32; k++) - X[k] = le32dec(&B[4 * k]); + X[k] = scrypt_le32dec(&B[4 * k]); N = (1 << (Nfactor + 1)); @@ -283,7 +283,7 @@ void scrypt_N_1_1_256_sp_generic(const char *input, char *output, char *scratchp } for (k = 0; k < 32; k++) - le32enc(&B[4 * k], X[k]); + scrypt_le32enc(&B[4 * k], X[k]); PBKDF2_SHA256((const uint8_t *)input, 80, B, 128, 1, (uint8_t *)output, 32); } diff --git a/src/crypto/scrypt.h b/src/crypto/scrypt.h index 403aa9739c29..baee699acd40 100644 --- a/src/crypto/scrypt.h +++ b/src/crypto/scrypt.h @@ -26,14 +26,14 @@ void PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen, const uint8_t *salt, size_t saltlen, uint64_t c, uint8_t *buf, size_t dkLen); -static inline uint32_t le32dec(const void *pp) +static inline uint32_t scrypt_le32dec(const void *pp) { const uint8_t *p = (uint8_t const *)pp; return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); } -static inline void le32enc(void *pp, uint32_t x) +static inline void scrypt_le32enc(void *pp, uint32_t x) { uint8_t *p = (uint8_t *)pp; p[0] = x & 0xff; @@ -41,4 +41,4 @@ static inline void le32enc(void *pp, uint32_t x) p[2] = (x >> 16) & 0xff; p[3] = (x >> 24) & 0xff; } -#endif \ No newline at end of file +#endif diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp index ddc1bb6232fa..29682725957d 100644 --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -73,7 +73,7 @@ static fs::path GetAuthCookieFile(bool temp=false) arg += ".tmp"; } fs::path path(arg); - if (!path.is_complete()) path = GetDataDir() / path; + if (!path.is_absolute()) path = GetDataDir() / path; return path; } diff --git a/src/util.cpp b/src/util.cpp index 5149cf307004..31744ceb3727 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -648,7 +648,7 @@ void ClearDatadirCache() fs::path GetConfigFile(const std::string& confPath) { fs::path pathConfigFile(confPath); - if (!pathConfigFile.is_complete()) + if (!pathConfigFile.is_absolute()) pathConfigFile = GetDataDir(false) / pathConfigFile; return pathConfigFile; @@ -687,7 +687,7 @@ void ArgsManager::ReadConfigFile(const std::string& confPath) fs::path GetPidFile() { fs::path pathPidFile(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)); - if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile; + if (!pathPidFile.is_absolute()) pathPidFile = GetDataDir() / pathPidFile; return pathPidFile; } diff --git a/src/validation.h b/src/validation.h index abf4fb5c011c..04f8f17b8f39 100644 --- a/src/validation.h +++ b/src/validation.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 4ff9c046e08e..f236b9be8185 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -285,7 +285,7 @@ bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& walle LogPrintf("Using wallet %s\n", walletFile); // Wallet file must be a plain filename without a directory - if (walletFile != fs::basename(walletFile) + fs::extension(walletFile)) + if (fs::path(walletFile).filename().string() != walletFile) { errorStr = strprintf(_("Wallet %s resides outside wallet directory %s"), walletFile, walletDir.string()); return false; @@ -714,7 +714,7 @@ bool CWalletDBWrapper::Backup(const std::string& strDest) return false; } - fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists); + fs::copy_file(pathSrc, pathDest, fs::copy_options::overwrite_existing); LogPrintf("copied %s to %s\n", strFile, pathDest.string()); return true; } catch (const fs::filesystem_error& e) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 2b8019395c9f..9cb5ca734792 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2427,7 +2427,9 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin std::vector vValue; CAmount nTotalLower = 0; - random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); + for (size_t i = vCoins.size(); i > 1; --i) { + std::swap(vCoins[i - 1], vCoins[GetRandInt(static_cast(i))]); + } for (const COutput &output : vCoins) { diff --git a/test/util/bitcoin-util-test.py b/test/util/bitcoin-util-test.py index 64e826ad0b3d..f58799e84d8b 100755 --- a/test/util/bitcoin-util-test.py +++ b/test/util/bitcoin-util-test.py @@ -28,7 +28,7 @@ def main(): config = configparser.ConfigParser() config.optionxform = str - config.readfp(open(os.path.join(os.path.dirname(__file__), "../config.ini"))) + config.read(os.path.join(os.path.dirname(__file__), "../config.ini")) env_conf = dict(config.items('environment')) parser = argparse.ArgumentParser(description=__doc__)