Skip to content

Commit

Permalink
refactor: move from Just to Task
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Jun 6, 2022
1 parent 390795b commit fc5a160
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.env
.idea/
.task/
sdk/c/lib/*/
sdk/swift/CHedera.xcframework/*/
35 changes: 35 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3"

silent: true

includes:
rust:
taskfile: ./sdk/rust/Taskfile.yml
dir: ./sdk/rust

swift:
taskfile: ./sdk/swift/Taskfile.yml
dir: ./sdk/swift

tasks:
build:
deps:
- rust:build
- swift:build

format:
deps:
- rust:format
- swift:format

lint:
cmds:
- task: rust:lint
- task: swift:lint

package:
deps:
- rust:package
- swift:package

# TODO: publish
90 changes: 0 additions & 90 deletions justfile

This file was deleted.

1 change: 0 additions & 1 deletion sdk/c/.gitignore

This file was deleted.

139 changes: 139 additions & 0 deletions sdk/rust/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
version: "3"

silent: false

tasks:
build:
run: once
generates:
- target/debug/libhedera.a
sources:
- src/**/*.rs
cmds:
# Build the Hedera Rust SDK (in debug mode)
- cargo build --message-format=short --features=ffi

# Package for Swift
- rm -rf ../swift/CHedera.xcframework/macos-*/
- mkdir -p ../swift/CHedera.xcframework/macos-{x86_64,arm64}/Headers/
- cp target/debug/libhedera.a ../swift/CHedera.xcframework/macos-x86_64/
- cp target/debug/libhedera.a ../swift/CHedera.xcframework/macos-arm64/
- cp ../c/include/hedera.h ../swift/CHedera.xcframework/macos-x86_64/Headers/
- cp ../c/include/hedera.h ../swift/CHedera.xcframework/macos-arm64/Headers/
- cp ../swift/CHedera.xcframework/module.modulemap ../swift/CHedera.xcframework/macos-x86_64/Headers/
- cp ../swift/CHedera.xcframework/module.modulemap ../swift/CHedera.xcframework/macos-arm64/Headers/

format:
cmds:
- cargo fmt

lint:
cmds:
- cargo clippy --features=ffi --message-format=short

package:
run: once
sources:
- src/**/*.rs
generates:
- ../c/lib/macos-x86_64/libhedera.a
- ../c/lib/ios-x86_64/libhedera.a
- ../c/lib/macos-arm64/libhedera.a
- ../c/lib/ios-arm64/libhedera.a
- ../c/lib/linux-x86_64/libhedera.a
- ../c/lib/windows-x86_64/libhedera.a
- ../c/lib/macos-x86_64/libhedera.dylib
- ../c/lib/macos-arm64/libhedera.dylib
- ../c/lib/linux-x86_64/libhedera.so
- ../c/lib/windows-x86_64/hedera.dll
cmds:
#
# Build the Hedera Rust SDK (in release mode)
#

# Ensure we have rust-src
- rustup component add rust-src 2> /dev/null

# Build for target: x86_64-apple-darwin
- rustup target add x86_64-apple-darwin 2> /dev/null
- cargo build --features ffi --release -p hedera -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-apple-darwin
- strip -X -S -N -x ./target/x86_64-apple-darwin/release/libhedera.a 2> /dev/null
- strip -X -S -N -x ./target/x86_64-apple-darwin/release/libhedera.dylib 2> /dev/null

# Build for target: x86_64-apple-ios
- rustup target add x86_64-apple-ios 2> /dev/null
- cargo build --features ffi --release -p hedera -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-apple-ios
- strip -X -S -N -x ./target/x86_64-apple-ios/release/libhedera.a 2> /dev/null

# Build for target: aarch64-apple-darwin
- rustup target add aarch64-apple-darwin 2> /dev/null
- cargo build --features ffi --release -p hedera -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target aarch64-apple-darwin
- strip -X -S -N -x ./target/aarch64-apple-darwin/release/libhedera.a 2> /dev/null
- strip -X -S -N -x ./target/aarch64-apple-darwin/release/libhedera.dylib 2> /dev/null

# Build for target: aarch64-apple-ios
- rustup target add aarch64-apple-ios 2> /dev/null
- cargo build --features ffi --release -p hedera -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target aarch64-apple-ios
- strip -X -S -N -x ./target/aarch64-apple-ios/release/libhedera.a 2> /dev/null

# Build for target: x86_64-unknown-linux-gnu
- rustup target add x86_64-unknown-linux-gnu 2> /dev/null

- env
CC_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-gcc
CXX_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-g++
AR_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-ar
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
cargo build --features ffi --release -p hedera -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu

- x86_64-unknown-linux-gnu-strip --strip-unneeded target/x86_64-unknown-linux-gnu/release/libhedera.a 2> /dev/null
- x86_64-unknown-linux-gnu-strip --strip-unneeded target/x86_64-unknown-linux-gnu/release/libhedera.so 2> /dev/null

# Build for target: x86_64-pc-windows-gnu
- rustup target add x86_64-pc-windows-gnu 2> /dev/null
- cargo build --features ffi --release -p hedera -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-pc-windows-gnu
- x86_64-w64-mingw32-strip --strip-unneeded target/x86_64-pc-windows-gnu/release/libhedera.a 2> /dev/null
- x86_64-w64-mingw32-strip --strip-unneeded target/x86_64-pc-windows-gnu/release/hedera.dll 2> /dev/null

#
# Package for C
#

- mkdir -p ../c/lib/{macos,ios}-{x86_64,arm64}/
- mkdir -p ../c/lib/{linux,windows}-x86_64/

- cp target/x86_64-apple-darwin/release/libhedera.a ../c/lib/macos-x86_64/
- cp target/x86_64-apple-ios/release/libhedera.a ../c/lib/ios-x86_64/
- cp target/aarch64-apple-darwin/release/libhedera.a ../c/lib/macos-arm64/
- cp target/aarch64-apple-ios/release/libhedera.a ../c/lib/ios-arm64/
- cp target/x86_64-unknown-linux-gnu/release/libhedera.a ../c/lib/linux-x86_64/
- cp target/x86_64-pc-windows-gnu/release/libhedera.a ../c/lib/windows-x86_64/

- cp target/x86_64-apple-darwin/release/libhedera.dylib ../c/lib/macos-x86_64/
- cp target/aarch64-apple-darwin/release/libhedera.dylib ../c/lib/macos-arm64/
- cp target/x86_64-unknown-linux-gnu/release/libhedera.so ../c/lib/linux-x86_64/
- cp target/x86_64-pc-windows-gnu/release/hedera.dll ../c/lib/windows-x86_64/

#
# Package for Swift
#

- rm -rf ../swift/CHedera.xcframework/{ios,macos}-*/

- mkdir -p ../swift/CHedera.xcframework/macos-{x86_64,arm64}/Headers/
- mkdir -p ../swift/CHedera.xcframework/ios-{x86_64-simulator,arm64}/Headers/

- cp ../c/lib/macos-x86_64/libhedera.a ../swift/CHedera.xcframework/macos-x86_64/
- cp ../c/lib/macos-arm64/libhedera.a ../swift/CHedera.xcframework/macos-arm64/
- cp ../c/lib/ios-x86_64/libhedera.a ../swift/CHedera.xcframework/ios-x86_64-simulator/
- cp ../c/lib/ios-arm64/libhedera.a ../swift/CHedera.xcframework/ios-arm64/

- cp ../c/include/hedera.h ../swift/CHedera.xcframework/macos-x86_64/Headers/
- cp ../c/include/hedera.h ../swift/CHedera.xcframework/macos-arm64/Headers/
- cp ../c/include/hedera.h ../swift/CHedera.xcframework/ios-x86_64-simulator/Headers/
- cp ../c/include/hedera.h ../swift/CHedera.xcframework/ios-arm64/Headers/

- cp ../swift/CHedera.xcframework/module.modulemap ../swift/CHedera.xcframework/macos-x86_64/Headers/
- cp ../swift/CHedera.xcframework/module.modulemap ../swift/CHedera.xcframework/macos-arm64/Headers/
- cp ../swift/CHedera.xcframework/module.modulemap ../swift/CHedera.xcframework/ios-x86_64-simulator/Headers/
- cp ../swift/CHedera.xcframework/module.modulemap ../swift/CHedera.xcframework/ios-arm64/Headers/
10 changes: 0 additions & 10 deletions sdk/rust/justfile

This file was deleted.

1 change: 0 additions & 1 deletion sdk/swift/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.build/
CHedera.xcframework/*/
.vscode/launch.json
4 changes: 2 additions & 2 deletions sdk/swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ for name in [
let package = Package(
name: "Hedera",
platforms: [
.macOS(.v10_15),
.iOS(.v12),
.macOS(.v10_15)
// .iOS(.v12),
],
products: [
.library(name: "Hedera", targets: ["Hedera"])
Expand Down
20 changes: 18 additions & 2 deletions sdk/swift/Sources/Hedera/AccountBalanceQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,31 @@ public class AccountBalanceQuery: Query<AccountBalanceResponse> {
return self
}

private enum CodingKeys: String, CodingKey {
case accountId
case contractId
}

public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: AnyQueryCodingKeys.self)
var data = container.nestedContainer(keyedBy: CodingKeys.self, forKey: .accountBalance)

switch (balanceSource) {
case .accountId(let accountId):
try data.encode(accountId, forKey: .accountId)

case .contractId(let contractId):
try data.encode(contractId, forKey: .contractId)

case nil:
break
}

try container.encodeIfPresent(balanceSource, forKey: .accountBalance)
try super.encode(to: encoder)
}
}

private enum AccountBalanceSource: Encodable {
private enum AccountBalanceSource {
case accountId(AccountIdOrAlias)
// TODO: Use ContractIdOrEvmAddress
case contractId(AccountIdOrAlias)
Expand Down
4 changes: 0 additions & 4 deletions sdk/swift/Sources/Hedera/HError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public struct HError: Error, CustomStringConvertible {
case basicParse
case keyParse
case noPayerAccountOrTransactionId
case maxAttemptsExceeded
case maxQueryPaymentExceeded
case nodeAccountUnknown
case responseStatusUnrecognized
Expand Down Expand Up @@ -72,9 +71,6 @@ public struct HError: Error, CustomStringConvertible {
case HEDERA_ERROR_NO_PAYER_ACCOUNT_OR_TRANSACTION_ID:
kind = .noPayerAccountOrTransactionId

case HEDERA_ERROR_MAX_ATTEMPTS_EXCEEDED:
kind = .maxAttemptsExceeded

case HEDERA_ERROR_MAX_QUERY_PAYMENT_EXCEEDED:
kind = .maxQueryPaymentExceeded

Expand Down
27 changes: 27 additions & 0 deletions sdk/swift/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"

silent: true

includes:
":rust":
taskfile: ../rust/Taskfile.yml
dir: ../rust

tasks:
build:
deps: [":rust:build"]
cmds:
- swift build

format:
cmds:
- swift format -i -p -r Sources Examples Package.swift

lint:
cmds:
- swiftlint --strict --quiet

package:
deps: [":rust:package"]
cmds:
- swift build -c release
10 changes: 0 additions & 10 deletions sdk/swift/justfile

This file was deleted.

0 comments on commit fc5a160

Please sign in to comment.