From 5b0ab9df585fd6c4d72c923883c78a9d6458af6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=85=94?= <12625134+whitehare2023@user.noreply.gitee.com> Date: Tue, 21 May 2024 06:39:46 +0800 Subject: [PATCH 1/6] Fix build script for secp256k1 on iOS --- ._bitcoin_issue_fix.md | Bin 0 -> 4096 bytes bitcoin_issue_fix.md | 54 +++++++++++++++++++++++++++++++++++++++ setup/build_secp256k1.sh | 5 ++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 ._bitcoin_issue_fix.md create mode 100644 bitcoin_issue_fix.md diff --git a/._bitcoin_issue_fix.md b/._bitcoin_issue_fix.md new file mode 100644 index 0000000000000000000000000000000000000000..2afebccec668d19722b361b91d565e5da42f2ce8 GIT binary patch literal 4096 zcmeH~zi-n(6vv-~TIdf-kN^pUibdrN2&azShNhJTNlJf!LMcs~0z%RGa*3_@SACb# z3U#PpM+Cr z3J8lcbK;`7JHkEa;;#zOx4|P{_iX_P{rvksBU>!qYBpa!+I3vyt`GlMI`|&nhm-ul zo|8nrZI^BjcjmMA>o z=S%}ge`$mv?nk5b!uT{JPRS$znFu_Gaz~6;2t93g@&j*~xX8r>6lEkemQD{Dn55EU zd6S#SnEd&AHT+lCg>%Ql2uOCzG8Fl5*y%&6#yF@#Nr-$T-J zTn=yOA}6#M7Q>$9mMuyfq+GRDl1?Q-t(rb}BU@2d&6#<}uMely+Eh-vA5g`$YoxwV zlGI$ry}h{L+oefNXZbP#3LMA7yzi evh7vTCRHXHHgfB{7d{9$+Ux&Q(OKwkHh%;2z|x@r literal 0 HcmV?d00001 diff --git a/bitcoin_issue_fix.md b/bitcoin_issue_fix.md new file mode 100644 index 00000000..5c616895 --- /dev/null +++ b/bitcoin_issue_fix.md @@ -0,0 +1,54 @@ + +# BitcoinKit Issue Fix + +## 问题 / Issue +在运行 `pod install` 时,构建 `secp256k1` 库时出现了以下错误: +While running `pod install`, the following error occurred during the `secp256k1` library build: + +``` +fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /var/folders/jp/86j3w3fx08j54wjdp81ln0n80000gn/T/tmp.SKt6tdknEr/.build/iphoneos/lib/libsecp256k1.a and /var/folders/jp/86j3w3fx08j54wjdp81ln0n80000gn/T/tmp.SKt6tdknEr/.build/iphonesimulator/lib/libsecp256k1.a have the same architectures (x86_64) and can't be in the same fat output file +``` + +## 原因 / Cause +这是因为构建的库在 `iphoneos` 和 `iphonesimulator` 中包含相同的架构(如 x86_64),导致 `lipo` 命令无法合并这些库。 +This is because the built libraries for `iphoneos` and `iphonesimulator` contain the same architecture (e.g., x86_64), causing the `lipo` command to fail to merge these libraries. + +## 解决方法 / Solution +修改 `build_secp256k1.sh` 脚本,确保正确处理架构。具体更改如下: +Modify the `build_secp256k1.sh` script to correctly handle the architectures. The specific changes are as follows: + +```sh +#!/bin/sh +set -ex + +SCRIPT_DIR=`dirname "$0"` + +TDIR=`mktemp -d` +trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT + +cd $TDIR + +git clone https://github.com/bitcoin-core/secp256k1.git src + +CURRENTPATH=`pwd` + +TARGETDIR_IPHONEOS="$CURRENTPATH/.build/iphoneos" +mkdir -p "$TARGETDIR_IPHONEOS" + +TARGETDIR_SIMULATOR="$CURRENTPATH/.build/iphonesimulator" +mkdir -p "$TARGETDIR_SIMULATOR" + +(cd src && ./autogen.sh) +(cd src && ./configure --host=arm-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" --prefix="$TARGETDIR_IPHONEOS" && make install) +(cd src && ./configure --host=x86_64-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" --prefix="$TARGETDIR_SIMULATOR" && make install) + +cd - + +mkdir -p "$SCRIPT_DIR/../Libraries/secp256k1/lib" +xcrun lipo -create "$TARGETDIR_IPHONEOS/lib/libsecp256k1.a" "$TARGETDIR_SIMULATOR/lib/libsecp256k1.a" -o "$SCRIPT_DIR/../Libraries/secp256k1/lib/libsecp256k1.a" +cp -rf $TDIR/src/include "$SCRIPT_DIR/../Libraries/secp256k1" + +rm -rf $TDIR + +exit 0 +``` diff --git a/setup/build_secp256k1.sh b/setup/build_secp256k1.sh index 631dde0f..11955bdf 100644 --- a/setup/build_secp256k1.sh +++ b/setup/build_secp256k1.sh @@ -19,8 +19,9 @@ TARGETDIR_SIMULATOR="$CURRENTPATH/.build/iphonesimulator" mkdir -p "$TARGETDIR_SIMULATOR" (cd src && ./autogen.sh) -(cd src && ./configure --host=x86_64-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch i386 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch i386 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" --prefix="$TARGETDIR_IPHONEOS" && make install) -(cd src && ./configure --host=arm-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" --prefix="$TARGETDIR_SIMULATOR" && make install) +(cd src && ./configure --host=arm-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" --prefix="$TARGETDIR_IPHONEOS" && make install) +(cd src && make clean) +(cd src && ./configure --host=x86_64-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" --prefix="$TARGETDIR_SIMULATOR" && make install) cd - From 14ce6f36507942b0015fb281daacbac340ac50e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=85=94?= <12625134+whitehare2023@user.noreply.gitee.com> Date: Thu, 23 May 2024 21:12:35 +0800 Subject: [PATCH 2/6] Fix: Implement replaceSubrange to conform to RangeReplaceableCollection --- .../BitcoinKit/Core/Mnemonic/BitArray.swift | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Sources/BitcoinKit/Core/Mnemonic/BitArray.swift b/Sources/BitcoinKit/Core/Mnemonic/BitArray.swift index 45916242..861f0449 100644 --- a/Sources/BitcoinKit/Core/Mnemonic/BitArray.swift +++ b/Sources/BitcoinKit/Core/Mnemonic/BitArray.swift @@ -46,6 +46,43 @@ public struct BitArray: Hashable, RangeReplaceableCollection { /// Constructs an empty bit array. public init() {} + public mutating func replaceSubrange(_ subrange: Range, with newElements: C) where C : Collection, Bool == C.Element { + let removeCount = subrange.count + let insertCount = newElements.count + let shift = insertCount - removeCount + + if shift > 0 { + bits.reserveCapacity(bits.count + (shift / Constants.IntSize) + 1) + } + + // Shift existing elements to make space or close the gap + for i in stride(from: count - 1, through: subrange.lowerBound, by: -1) { + let targetIndex = i + shift + if targetIndex < count { + let value = valueAtIndex(i) + setValue(value, atIndex: targetIndex) + } + } + + // Insert new elements + var currentIndex = subrange.lowerBound + for element in newElements { + setValue(element, atIndex: currentIndex) + currentIndex += 1 + } + + // Update count + count += shift + + // Recalculate cardinality + cardinality = 0 + for i in 0..(_ elements: S) where S.Iterator.Element == Bool { for value in elements { From 7ba49fb48434c6e4a338087647edbcebd20c698c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E5=8F=AA=E5=B0=8F=E5=85=94=E5=AD=90?= <124434634+Whitehare2023@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:57:20 +0800 Subject: [PATCH 3/6] Update BitcoinKit.podspec --- BitcoinKit.podspec | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/BitcoinKit.podspec b/BitcoinKit.podspec index ac39d03f..262a38f6 100644 --- a/BitcoinKit.podspec +++ b/BitcoinKit.podspec @@ -3,15 +3,14 @@ Pod::Spec.new do |spec| spec.version = '1.1.0' spec.summary = 'Bitcoin(BCH/BTC) protocol toolkit for Swift' spec.description = <<-DESC - The BitcoinKit library is a Swift implementation of the Bitcoin(BCH/BTC) protocol. This library was originally made by Katsumi Kishikawa, and now is maintained by Yenom Inc. It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node. It comes with a simple wallet app showing how to use it. - ``` - DESC - spec.homepage = 'https://github.com/yenom/BitcoinKit' + The BitcoinKit library is a Swift implementation of the Bitcoin(BCH/BTC) protocol. This library was originally made by Katsumi Kishikawa, and now is maintained by Yenom Inc. It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node. It comes with a simple wallet app showing how to use it. + DESC + spec.homepage = 'https://github.com/Whitehare2023/BitcoinKit' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.author = { 'BitcoinKit developers' => 'usatie@yenom.tech' } spec.requires_arc = true - spec.source = { git: 'https://github.com/yenom/BitcoinKit.git', tag: "v#{spec.version}" } + spec.source = { git: 'https://github.com/Whitehare2023/BitcoinKit.git', branch: 'fix-secp256k1-build' } spec.source_files = 'BitcoinKit/**/*.{h,m,swift}', 'Sources/BitcoinKit/**/*.{h,m,swift}' spec.private_header_files = 'BitcoinKit/**/BitcoinKitPrivate.h' spec.exclude_files = 'Sources/**/LinuxSupport.swift' @@ -19,12 +18,14 @@ Pod::Spec.new do |spec| spec.ios.deployment_target = '8.0' spec.swift_version = '5.0' - spec.pod_target_xcconfig = { 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES', - 'APPLICATION_EXTENSION_API_ONLY' => 'YES', - 'SWIFT_INCLUDE_PATHS' => '${PODS_ROOT}/BitcoinKit/Libraries', - 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/include" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/include"', - 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/lib" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/lib"', - 'OTHER_SWIFT_FLAGS' => '-D BitcoinKitXcode' } + spec.pod_target_xcconfig = { + 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES', + 'APPLICATION_EXTENSION_API_ONLY' => 'YES', + 'SWIFT_INCLUDE_PATHS' => '${PODS_ROOT}/BitcoinKit/Libraries', + 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/include" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/include"', + 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/lib" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/lib"', + 'OTHER_SWIFT_FLAGS' => '-D BitcoinKitXcode' + } spec.preserve_paths = ['setup', 'Libraries'] spec.prepare_command = 'sh setup/build_libraries.sh' end From 956ca72a1515c469da8cbe8ee3357924d14ecd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E5=8F=AA=E5=B0=8F=E5=85=94=E5=AD=90?= <124434634+Whitehare2023@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:59:12 +0800 Subject: [PATCH 4/6] Update BitcoinKit.podspec --- BitcoinKit.podspec | 3 --- 1 file changed, 3 deletions(-) diff --git a/BitcoinKit.podspec b/BitcoinKit.podspec index 262a38f6..9a37a9f1 100644 --- a/BitcoinKit.podspec +++ b/BitcoinKit.podspec @@ -12,16 +12,13 @@ Pod::Spec.new do |spec| spec.requires_arc = true spec.source = { git: 'https://github.com/Whitehare2023/BitcoinKit.git', branch: 'fix-secp256k1-build' } spec.source_files = 'BitcoinKit/**/*.{h,m,swift}', 'Sources/BitcoinKit/**/*.{h,m,swift}' - spec.private_header_files = 'BitcoinKit/**/BitcoinKitPrivate.h' spec.exclude_files = 'Sources/**/LinuxSupport.swift' - spec.module_map = 'BitcoinKit/BitcoinKit.modulemap' spec.ios.deployment_target = '8.0' spec.swift_version = '5.0' spec.pod_target_xcconfig = { 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES', 'APPLICATION_EXTENSION_API_ONLY' => 'YES', - 'SWIFT_INCLUDE_PATHS' => '${PODS_ROOT}/BitcoinKit/Libraries', 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/include" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/include"', 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/lib" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/lib"', 'OTHER_SWIFT_FLAGS' => '-D BitcoinKitXcode' From 43a6efbd2583415dc206fa0cc8e6af4be310dfa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E5=8F=AA=E5=B0=8F=E5=85=94=E5=AD=90?= <124434634+Whitehare2023@users.noreply.github.com> Date: Mon, 3 Jun 2024 23:06:36 +0800 Subject: [PATCH 5/6] Update BitcoinKit.podspec --- BitcoinKit.podspec | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/BitcoinKit.podspec b/BitcoinKit.podspec index 9a37a9f1..a2e5861e 100644 --- a/BitcoinKit.podspec +++ b/BitcoinKit.podspec @@ -11,18 +11,8 @@ Pod::Spec.new do |spec| spec.requires_arc = true spec.source = { git: 'https://github.com/Whitehare2023/BitcoinKit.git', branch: 'fix-secp256k1-build' } - spec.source_files = 'BitcoinKit/**/*.{h,m,swift}', 'Sources/BitcoinKit/**/*.{h,m,swift}' + spec.source_files = 'Sources/BitcoinKit/**/*.{h,m,swift}' spec.exclude_files = 'Sources/**/LinuxSupport.swift' spec.ios.deployment_target = '8.0' spec.swift_version = '5.0' - - spec.pod_target_xcconfig = { - 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES', - 'APPLICATION_EXTENSION_API_ONLY' => 'YES', - 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/include" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/include"', - 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/lib" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/lib"', - 'OTHER_SWIFT_FLAGS' => '-D BitcoinKitXcode' - } - spec.preserve_paths = ['setup', 'Libraries'] - spec.prepare_command = 'sh setup/build_libraries.sh' end From e32c687c3cdea66fa991427bc28d9145febfaf2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E5=8F=AA=E5=B0=8F=E5=85=94=E5=AD=90?= <124434634+Whitehare2023@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:04:15 +0800 Subject: [PATCH 6/6] Update BitcoinKit.podspec --- BitcoinKit.podspec | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/BitcoinKit.podspec b/BitcoinKit.podspec index a2e5861e..262a38f6 100644 --- a/BitcoinKit.podspec +++ b/BitcoinKit.podspec @@ -11,8 +11,21 @@ Pod::Spec.new do |spec| spec.requires_arc = true spec.source = { git: 'https://github.com/Whitehare2023/BitcoinKit.git', branch: 'fix-secp256k1-build' } - spec.source_files = 'Sources/BitcoinKit/**/*.{h,m,swift}' + spec.source_files = 'BitcoinKit/**/*.{h,m,swift}', 'Sources/BitcoinKit/**/*.{h,m,swift}' + spec.private_header_files = 'BitcoinKit/**/BitcoinKitPrivate.h' spec.exclude_files = 'Sources/**/LinuxSupport.swift' + spec.module_map = 'BitcoinKit/BitcoinKit.modulemap' spec.ios.deployment_target = '8.0' spec.swift_version = '5.0' + + spec.pod_target_xcconfig = { + 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES', + 'APPLICATION_EXTENSION_API_ONLY' => 'YES', + 'SWIFT_INCLUDE_PATHS' => '${PODS_ROOT}/BitcoinKit/Libraries', + 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/include" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/include"', + 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/BitcoinKit/Libraries/openssl/lib" "${PODS_ROOT}/BitcoinKit/Libraries/secp256k1/lib"', + 'OTHER_SWIFT_FLAGS' => '-D BitcoinKitXcode' + } + spec.preserve_paths = ['setup', 'Libraries'] + spec.prepare_command = 'sh setup/build_libraries.sh' end