Skip to content

fix(antd-swift): port to Linux + populate cost-estimate fields#87

Merged
Nic-dorman merged 1 commit into
mainfrom
fix/antd-swift-linux-port
May 14, 2026
Merged

fix(antd-swift): port to Linux + populate cost-estimate fields#87
Nic-dorman merged 1 commit into
mainfrom
fix/antd-swift-linux-port

Conversation

@Nic-dorman
Copy link
Copy Markdown
Collaborator

Summary

antd-swift/README.md says 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:

swift build && swift run AntdExamples 2
…
=== Example 02: Public Data ===
Estimate: 24 bytes in 3 chunks, storage 43945312500000000 atto, gas 150000000000000 wei, mode single
Stored at address: b2898da4c31d2701da63eebde490047dbb4cc2b8eeb5d596009fe633ecafd20b
Retrieved: Hello, Autonomi network!
Public data round-trip OK!

Changes

Package.swift — bump grpc-swift to 2.x

grpc-swift-protobuf 1.x requires Swift tools 6.0+, conflicting with the previous from: "1.23.0" pin on grpc-swift (1.x line, 5.x tooling). Bumps grpc-swift to 2.0.0 and adds the new grpc-swift-nio-transport package — GRPCNIOTransportHTTP2 moved out of the main grpc-swift repo in 2.x.

Sources/AntdSdk/AntdRestClient.swift — three fixes

  1. FoundationNetworking import — Linux splits URLSession out of Foundation. Guarded with #if canImport(FoundationNetworking) so macOS/iOS are unaffected.

  2. PUT-response cost is optional — daemon currently returns {address, chunks_stored, payment_mode_used} for POST /v1/data/public / /v1/data/private / /v1/chunks without cost. The previous let cost: String decoder 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.

  3. CostDTO snake_case decoding — the bug hidden behind the macOS-only framing. JSONDecoder.snakeCase uses keyDecodingStrategy = .convertFromSnakeCase, so JSON file_size is mapped to expected Swift property fileSize. The DTO 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.

Sources/AntdSdk/Errors.swiftoverride on subclass inits

Swift 6's stricter init resolution flagged 9 error subclass initializers as missing override against AntdError.init(_:statusCode:).

Sources/AntdExamples/Main.swift — Linux-safe minimal example

The previous bundled example used SecRandomCopyBytes (macOS-only Security.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 once SecRandomCopyBytes is replaced and the arity bugs are fixed.

Test plan

  • cd antd-swift && swift build clean 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 2 against a local devnet — round-trip OK, real estimate fields populated
  • Cross-SDK e2e harness: 15/15 SDKs pass with swift no longer skipped

Companion PR

#86 wires swift run AntdExamples N into the ant dev example dispatcher and removes the skip_reason that 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

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>
@Nic-dorman Nic-dorman merged commit 03fecaa into main May 14, 2026
@Nic-dorman Nic-dorman deleted the fix/antd-swift-linux-port branch May 14, 2026 13:02
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant