fix(antd-swift): port to Linux + populate cost-estimate fields#87
Merged
Conversation
The Swift SDK is documented as macOS-only in `antd-swift/README.md`, but
in practice the swift.org Linux toolchain (6.0.x) builds and round-trips
against antd end-to-end after a small set of upstream-fixable patches.
This PR collects them and adds a snake-case-decoding fix for the cost
estimate that was hiding behind the "macOS-only" framing.
Verified end-to-end on Ubuntu 24.04 with Swift 6.0.3:
`swift build && swift run AntdExamples 2` → "Public data round-trip OK!"
with real `Estimate: 24 bytes in 3 chunks, storage 43945312500000000
atto, gas 150000000000000 wei, mode single`.
## Changes
### Package.swift — bump grpc-swift to 2.x
`grpc-swift-protobuf 1.x` requires Swift tools 6.0+, which conflicts
with the previous `from: "1.23.0"` pin on `grpc-swift` (which is on the
1.x line, requiring 5.x tooling). Bump `grpc-swift` to `2.0.0` and add
the new `grpc-swift-nio-transport` package — `GRPCNIOTransportHTTP2`
moved out of the main grpc-swift repo in 2.x.
### AntdRestClient.swift — three fixes
1. **`FoundationNetworking` import** — Linux builds split URLSession out
of `Foundation` into a separate `FoundationNetworking` module.
Guarded with `#if canImport(...)` so macOS/iOS are unaffected.
2. **PUT-response cost is optional** — daemon's `POST /v1/data/public`,
`/v1/data/private`, `/v1/chunks` currently return `{address,
chunks_stored, payment_mode_used}` without `cost`, so the previous
`let cost: String` decoder fataled. Mirrors the antd-php / antd-py
fallback to empty-string. Same shape addressed in #77 (kotlin) and
the long-standing PHP/Python pattern.
3. **CostDTO snake_case decoding** — the bug hidden by today's e2e:
`JSONDecoder.snakeCase` (which is `keyDecodingStrategy =
.convertFromSnakeCase`) converts JSON `file_size` → expected Swift
property `fileSize`. CostDTO had snake_case property names, so
decoding silently nilled them out and `dataCost` / `fileCost` always
returned zero for `fileSize`/`chunkCount`/`gas`/`mode`. Rename to
camelCase so the decoder matches.
### Errors.swift — `override` keyword on subclass inits
Swift 6's stricter init resolution flagged the 9 error subclass
initializers as missing `override` against `AntdError.init(_:statusCode:)`.
Add the keyword.
### AntdExamples/Main.swift — Linux-safe minimal example
The previous bundled example used `SecRandomCopyBytes` from Apple's
`Security` framework (macOS-only) and had pre-existing arity bugs in
several of the per-example helper functions. Replace with a minimal
Linux-portable example 02 that exercises the public data round-trip and
exits non-zero on mismatch — enough for cross-SDK e2e validation. The
full example suite would be a separate restoration once
`SecRandomCopyBytes` is replaced and the arity bugs are fixed.
## Test plan
- [x] `cd antd-swift && swift build` clean on Ubuntu 24.04 with Swift
6.0.3 (one cosmetic warning: `dependency 'grpc-swift' is not used
by any target` — only the nio-transport sub-package is used)
- [x] `swift run AntdExamples 2` against a local devnet — round-trip OK,
real estimate fields
- [x] Cross-SDK e2e harness: 15/15 SDKs pass, swift no longer skipped
## Companion PR
PR adding `swift run AntdExamples N` to the `ant dev example`
dispatcher (and removing the `skip_reason` that was auto-skipping
swift) is in #86. Either can land first; without the antd-swift
patches here, the dispatcher's swift adapter will fail at compile.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
Nic-dorman
added a commit
that referenced
this pull request
May 14, 2026
Cuts v0.7.1 atop v0.7.0. Primarily refreshes the upstream `ant-core` pin to the `ant-cli-v0.2.3` release tag (no API change for antd consumers). Bundles a substantial round of cross-SDK example/build fixes, dispatcher improvements, and CI/release workflow hardening. ## antd - chore(antd): bump ant-core to v0.2.3 (#85) ## SDK example/build fixes - fix(antd-php): use cost-estimate fields in example 02 (#74) - fix(antd-elixir): print cost-estimate fields in examples (#75) - fix(antd-lua): add missing discover module to rockspec (#76) - fix(antd-kotlin): make put-response cost optional + ship gradle wrapper (#77) - fix(antd-zig): pass payment_mode to dataPutPublic/dataPutPrivate (#79) - fix(antd-java): make examples runnable via gradle :examples subproject (#80) - fix(antd-zig): align stdlib API to declared 0.14.x minimum (#82) - fix(antd-swift): port to Linux + populate cost-estimate fields (#87) ## ant-dev (developer CLI) - fix(ant-dev): clean up orphan anvil/antnode and stale node identities on stop (#81) - fix(ant-dev): tooling cluster — flag alias, sys.executable, anvil preflight, README (#83) - feat(ant-dev): expand `ant dev example` to dispatch all 15 SDKs (#84) - fix(ant-dev): dispatcher swift no-skip + lua LUA_PATH wrap (#86) - feat(ant-dev): expose --preset flag on `ant dev start` (default: small) (#88) ## CI / release - ci: authenticate arduino/setup-protoc on ci.yml too (#60) - feat(release): publish antd-linux-arm64 artifact (#89) ## Validation 15/15 SDKs round-tripped end-to-end against a daemon built from this commit on a Linux dev box (Ubuntu 24.04, 0.7.1 atop ant-core v0.2.3). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
antd-swift/README.mdsays the SDK is macOS-only, but the swift.org Linux toolchain (6.0.x) builds and round-trips against antd end-to-end after a small set of upstream-fixable patches. This PR collects them and adds a snake-case decoding fix for the cost estimate that was hiding behind the macOS-only framing.Verified end-to-end on Ubuntu 24.04 / Swift 6.0.3:
Changes
Package.swift— bump grpc-swift to 2.xgrpc-swift-protobuf 1.xrequires Swift tools 6.0+, conflicting with the previousfrom: "1.23.0"pin ongrpc-swift(1.x line, 5.x tooling). Bumpsgrpc-swiftto2.0.0and adds the newgrpc-swift-nio-transportpackage —GRPCNIOTransportHTTP2moved out of the main grpc-swift repo in 2.x.Sources/AntdSdk/AntdRestClient.swift— three fixesFoundationNetworkingimport — Linux splits URLSession out ofFoundation. Guarded with#if canImport(FoundationNetworking)so macOS/iOS are unaffected.PUT-response
costis optional — daemon currently returns{address, chunks_stored, payment_mode_used}forPOST /v1/data/public//v1/data/private//v1/chunkswithoutcost. The previouslet cost: Stringdecoder fataled. Fall back to empty-string downstream, matching antd-php's pattern and what fix(antd-kotlin): make put-response cost optional; ship missing gradle wrapper #77 just shipped for kotlin.CostDTO snake_case decoding — the bug hidden behind the macOS-only framing.
JSONDecoder.snakeCaseuseskeyDecodingStrategy = .convertFromSnakeCase, so JSONfile_sizeis mapped to expected Swift propertyfileSize. The DTO had snake_case property names, so decoding silently nilled them out anddataCost/fileCostalways returned zero forfileSize/chunkCount/gas/mode. Rename to camelCase so the decoder matches.Sources/AntdSdk/Errors.swift—overrideon subclass initsSwift 6's stricter init resolution flagged 9 error subclass initializers as missing
overrideagainstAntdError.init(_:statusCode:).Sources/AntdExamples/Main.swift— Linux-safe minimal exampleThe previous bundled example used
SecRandomCopyBytes(macOS-onlySecurity.framework) and had arity bugs in several of the per-example helpers. Replace with a minimal Linux-portable example 02 that exercises the public data round-trip and exits non-zero on mismatch — enough for cross-SDK e2e validation. Restoring the full example suite is a separate task onceSecRandomCopyBytesis replaced and the arity bugs are fixed.Test plan
cd antd-swift && swift buildclean on Ubuntu 24.04 / Swift 6.0.3 (one cosmetic warning:dependency 'grpc-swift' is not used by any target— only the nio-transport sub-package is consumed)swift run AntdExamples 2against a local devnet — round-trip OK, real estimate fields populatedCompanion PR
#86 wires
swift run AntdExamples Ninto theant dev exampledispatcher and removes theskip_reasonthat was silently auto-skipping swift. Either PR can land first; without these antd-swift patches, the dispatcher's swift adapter will fail at compile.🤖 Generated with Claude Code