Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Cleanup build script, use XCFramework #61

Closed
wants to merge 14 commits into from
2 changes: 1 addition & 1 deletion CLibWally/libwally-core
21 changes: 6 additions & 15 deletions LibWally.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Pod::Spec.new do |spec|

spec.name = "LibWally"
spec.version = "0.0.1"
spec.version = "0.0.7"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

188794c: no need to bump the version when you're trying this. You can point to a branch, see e.g. Sjors/nthkey-ios@ecf2513

I'll try to remember to bump this version next time I tag a release though.

spec.summary = "Swift wrapper for LibWally."
spec.description = "Swift wrapper for LibWally, a collection of useful primitives for cryptocurrency wallets."
spec.homepage = "https://github.com/Sjors/libwally-swift"
Expand All @@ -17,21 +17,12 @@ Pod::Spec.new do |spec|
spec.platform = :ios, "10"
spec.swift_version = '5.0'

spec.source = { :git => "https://github.com/Sjors/libwally-swift.git", :tag => "v#{spec.version}", :submodules => true }
spec.source = { :git => "https://github.com/jurvis/libwally-swift.git", :tag => "v#{spec.version}", :submodules => true }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

60ed50a: don't forget to drop this. Also, I wonder if you really need that in order to test a fork.

Copy link
Contributor Author

@jurvis jurvis Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to test pod spec lint LibWally.podspec since it'll use the information defined at spec.source and do its work.


spec.source_files = "LibWally"

spec.vendored_libraries = "CLibWally/libwally-core/src/.libs/libwallycore.a"

spec.pod_target_xcconfig = {
'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de7ecc9 Why the removal? Is it deprecated? Useless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, ignore all the diffs in podspec for now. This has turned into kind of a working branch for me to test Cocoapods like a monkey and figuring out how it all comes together 😅

'SWIFT_INCLUDE_PATHS' => '$(PODS_TARGET_SRCROOT)/CLibWally',
'LIBRARY_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/CLibWally/libwally-core/src/.libs'
}
spec.preserve_paths = 'LibWally/LibWally.modulemap', 'CLibWally'

spec.module_map = 'LibWally/LibWally.modulemap'
spec.vendored_frameworks = "build/LibwallySwift.xcframework"

spec.preserve_paths = "build/LibwallySwift.xcframework"
spec.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' }
spec.prepare_command = './build-libwally.sh -sdc'

spec.cocoapods_version = '>= 1.10.0'
end
6 changes: 6 additions & 0 deletions LibWally.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
759B2C4D2801473C00606FC8 /* libsecp256k1.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 759B2C4C2801472D00606FC8 /* libsecp256k1.a */; };
A20C942522C6BC3900B0D206 /* libwallycore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A20C942422C6BC3900B0D206 /* libwallycore.a */; };
A232260122B94A6B00C3B79C /* Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A232260022B94A6B00C3B79C /* Transaction.swift */; };
A232260322B94A8400C3B79C /* TransactionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A232260222B94A8400C3B79C /* TransactionTests.swift */; };
Expand Down Expand Up @@ -37,6 +38,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
759B2C4C2801472D00606FC8 /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsecp256k1.a; path = "CLibWally/libwally-core/src/secp256k1/.libs/libsecp256k1.a"; sourceTree = "<group>"; };
A20557A522C6CDBE007221AA /* LibWally.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = LibWally.modulemap; sourceTree = "<group>"; };
A20C942422C6BC3900B0D206 /* libwallycore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libwallycore.a; path = "CLibWally/libwally-core/src/.libs/libwallycore.a"; sourceTree = "<group>"; };
A20C942622C6BDB000B0D206 /* CLibWally */ = {isa = PBXFileReference; lastKnownFileType = folder; path = CLibWally; sourceTree = "<group>"; };
Expand Down Expand Up @@ -67,6 +69,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
759B2C4D2801473C00606FC8 /* libsecp256k1.a in Frameworks */,
A20C942522C6BC3900B0D206 /* libwallycore.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -138,6 +141,7 @@
FEB0B466229C6B6C00459518 /* Frameworks */ = {
isa = PBXGroup;
children = (
759B2C4C2801472D00606FC8 /* libsecp256k1.a */,
A20C942422C6BC3900B0D206 /* libwallycore.a */,
);
name = Frameworks;
Expand Down Expand Up @@ -438,6 +442,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/CLibWally/libwally-core/src/.libs",
"$(PROJECT_DIR)/CLibWally/libwally-core/src/secp256k1/.libs",
);
MARKETING_VERSION = 0.0.6;
MODULEMAP_FILE = "$(SRCROOT)/LibWally/LibWally.modulemap";
Expand Down Expand Up @@ -475,6 +480,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/CLibWally/libwally-core/src/.libs",
"$(PROJECT_DIR)/CLibWally/libwally-core/src/secp256k1/.libs",
);
MARKETING_VERSION = 0.0.6;
MODULEMAP_FILE = "$(SRCROOT)/LibWally/LibWally.modulemap";
Expand Down
2 changes: 1 addition & 1 deletion LibWally/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let WALLY_ADDRESS_TYPE_P2TR: Int32 = 0x08 // P2TR taproot address ("bc1p..)"

import Foundation
import CLibWally
@_implementationOnly import CLibWally

public enum AddressType {
case payToPubKeyHash // P2PKH (legacy)
Expand Down
2 changes: 1 addition & 1 deletion LibWally/BIP32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// license, see the accompanying file LICENSE.md

import Foundation
import CLibWally
@_implementationOnly import CLibWally

public enum Network : Equatable {
case mainnet
Expand Down
2 changes: 1 addition & 1 deletion LibWally/BIP39.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//

import Foundation
import CLibWally
@_implementationOnly import CLibWally

let MAX_BYTES = 32 // Arbitrary, used only to determine array size in bip39_mnemonic_to_bytes

Expand Down
2 changes: 1 addition & 1 deletion LibWally/DataExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// license, see the accompanying file LICENSE.md

import Foundation
import CLibWally
@_implementationOnly import CLibWally

public extension Data {

Expand Down
2 changes: 1 addition & 1 deletion LibWally/PSBT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// license, see the accompanying file LICENSE.md

import Foundation
import CLibWally
@_implementationOnly import CLibWally

public struct KeyOrigin : Equatable {
let fingerprint: Data
Expand Down
2 changes: 1 addition & 1 deletion LibWally/Script.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Distributed under the MIT software license, see the accompanying file LICENSE.md

import Foundation
import CLibWally
@_implementationOnly import CLibWally

let a = WALLY_SCRIPT_TYPE_OP_RETURN

Expand Down
4 changes: 2 additions & 2 deletions LibWally/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// license, see the accompanying file LICENSE.md

import Foundation
import CLibWally
@_implementationOnly import CLibWally

public typealias Satoshi = UInt64

Expand Down Expand Up @@ -45,7 +45,7 @@ public struct TxOutput {
self.wally_tx_output = output!.pointee
}

public init (tx_output: wally_tx_output, scriptPubKey: ScriptPubKey, network: Network) {
internal init (tx_output: wally_tx_output, scriptPubKey: ScriptPubKey, network: Network) {
self.network = network
self.wally_tx_output = tx_output
self.scriptPubKey = scriptPubKey
Expand Down
48 changes: 30 additions & 18 deletions build-libwally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e # abort if any command fails
device=0
simulator=0
clean=0
PROJ_DIRECTORY=`pwd`
BIN_OUTPUT_DIRECTORY="`pwd`/build"

while getopts "h?dsc" opt; do
case "$opt" in
Expand Down Expand Up @@ -33,6 +35,8 @@ if [ $device == 1 ] && [ $simulator == 1 ]; then
echo "Build libwally-core for device and simulator and combine into a single library..."
fi

rm -rf build

cd CLibWally/libwally-core

if [ $clean == 1 ]; then
Expand All @@ -50,56 +54,64 @@ if [ $simulator == 1 ]; then
if [ ! -d "build" ]; then
echo "Configure and compile for the simulator..."
set -v
export CFLAGS="-O3 -arch x86_64 -arch i386 -fembed-bitcode-marker -mios-simulator-version-min=10.0 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path`"
export CXXFLAGS="-O3 -arch x86_64 -arch i386 -fembed-bitcode-marker -mios-simulator-version-min=10.0 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path`"
export CFLAGS="-O3 -arch arm64 -arch x86_64 -fembed-bitcode-marker -mios-simulator-version-min=11.0 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path`"
export CXXFLAGS="-O3 -arch arm64 -arch x86_64 -fembed-bitcode-marker -mios-simulator-version-min=11.0 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path`"
mkdir -p build

architecture=$(uname -m)
arch_target="x86_64-apple-darwin"

if [ "$architecture" = "arm64" ]; then
arch_target="aarch64-apple-darwin"
fi

./configure --disable-shared --host=$arch_target --enable-static --disable-elements
./configure --disable-shared --host=aarch64-apple-darwin --enable-static --disable-elements
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7d6ef31: why would this work on an intel mac?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, it probably won't. I just hard-coded it for now and can fix it later 😄


if [ $clean == 1 ]; then
set -v # display commands
make clean
fi
fi
make
if [ $device == 1 ]; then
cp src/.libs/libwallycore.a build/libwallycore-simulator.a
cd $PROJ_DIRECTORY
xcodebuild archive -scheme LibWally -destination "generic/platform=iOS Simulator" -archivePath ${BIN_OUTPUT_DIRECTORY}/LibwallySwift-Sim ONLY_ACTIVE_ARCH=NO SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dde977c: please squash when you find the right ones :-)

if [ $device != 1 ]; then
xcodebuild -create-xcframework \
-framework ${BIN_OUTPUT_DIRECTORY}/LibwallySwift-Sim.xcarchive/Products/Library/Frameworks/LibWally.framework \
-output ${BIN_OUTPUT_DIRECTORY}/LibwallySwift.xcframework
fi
fi

if [ $device == 1 ]; then
cd CLibWally/libwally-core
set +v
if [ ! -d "build" ] || [ $clean == 1 ]; then
echo "Configure and cross-compile for the device..."
set -v
export CFLAGS="-O3 -arch arm64 -arch arm64e -arch armv7 -arch armv7s -fembed-bitcode -mios-version-min=10.0 -isysroot `xcrun -sdk iphoneos --show-sdk-path`"
export CXXFLAGS="-O3 -arch arm64 -arch arm64e -arch armv7 -arch armv7s -isysroot -fembed-bitcode -mios-version-min=10.0 -isysroot `xcrun -sdk iphoneos --show-sdk-path`"
export CFLAGS="-O3 -arch arm64 -fembed-bitcode -mios-version-min=11.0 -isysroot `xcrun -sdk iphoneos --show-sdk-path`"
export CXXFLAGS="-O3 -arch arm64 -fembed-bitcode -mios-version-min=11.0 -isysroot `xcrun -sdk iphoneos --show-sdk-path`"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a3976b0: If you bump the minimum version, don't forget to update the Podspec.

For my own app (nthKey) I'm also fine with a bump to 15.0 if there's any benefit. But I don't know if anyone else is using LibWally-Swift and needs support for older versions of iOs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I bumped to 11.0 because 10.3 was the last supported iOS for >=armv7 (iPhone 5c, iirc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think it will be nice to keep it at a generous minimum version, since developers may want to support them

mkdir -p build
./configure --disable-shared --host=aarch64-apple-darwin14 --enable-static --disable-elements
./configure --disable-shared --host=aarch64-apple-darwin --enable-static --disable-elements
if [ $clean == 1 ]; then
make clean
fi
fi
make
set +v
if [ $simulator == 1 ]; then
cd $PROJ_DIRECTORY
xcodebuild archive -scheme LibWally -destination "generic/platform=iOS" -archivePath ${BIN_OUTPUT_DIRECTORY}/LibwallySwift-iOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
if [ $simulator != 1 ]; then
set -v
cp src/.libs/libwallycore.a build/libwallycore-device.a
xcodebuild -create-xcframework \
-framework ${BIN_OUTPUT_DIRECTORY}/LibwallySwift-iOS.xcarchive/Products/Library/Frameworks/LibWally.framework \
-output ${BIN_OUTPUT_DIRECTORY}/LibwallySwift.xcframework
fi
fi

set +v
if [ $device == 1 ] && [ $simulator == 1 ]; then
echo "Combine simulator and device libraries..."
set -v
lipo -create build/libwallycore-device.a build/libwallycore-simulator.a -o src/.libs/libwallycore.a

rm -rf ${BIN_OUTPUT_DIRECTORY}/LibwallySwift.xcframework

xcodebuild -create-xcframework \
-framework ${BIN_OUTPUT_DIRECTORY}/LibwallySwift-iOS.xcarchive/Products/Library/Frameworks/LibWally.framework \
-framework ${BIN_OUTPUT_DIRECTORY}/LibwallySwift-Sim.xcarchive/Products/Library/Frameworks/LibWally.framework \
-output ${BIN_OUTPUT_DIRECTORY}/LibwallySwift.xcframework
fi

set +v
Expand Down