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

feat: add support for no_std env #392

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ concurrency:
cancel-in-progress: true

env:
CARGO_HACK_ARGS: --feature-powerset --exclude-features default --group-features base64,serde,serde_json,schemars,arbitrary,hex
CARGO_HACK_ARGS: --feature-powerset --exclude-features default --group-features base64,serde,serde_json,schemars,arbitrary,hex --skip "embedded_io"
EMBEDDED_IO_CARGO_HACK_ARGS: --feature-powerset --exclude-features default --skip "cli,std,base64,serde,serde_json,schemars,arbitrary,hex"

jobs:

Expand Down Expand Up @@ -90,6 +91,9 @@ jobs:
name: cargo-hack
version: 0.5.16
- run: cargo hack clippy $CARGO_HACK_ARGS --target ${{ matrix.sys.target }} --all-targets
# TODO: Features "std" and "embedded_io" cannot be enabled simultaneously.
# Is there a better solution to solve it?
- run: cargo hack clippy $EMBEDDED_IO_CARGO_HACK_ARGS --target ${{ matrix.sys.target }} --all-targets

test:
strategy:
Expand Down Expand Up @@ -126,6 +130,8 @@ jobs:
name: cargo-hack
version: 0.5.16
- run: cargo hack test $CARGO_HACK_ARGS
# TODO: Features "std" and "embedded_io" cannot be enabled simultaneously.
- run: cargo hack test $EMBEDDED_IO_CARGO_HACK_ARGS

publish-dry-run:
if: github.event_name == 'push' || startsWith(github.head_ref, 'release/')
Expand Down
21 changes: 18 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
version = "22.0.0"
edition = "2021"
rust-version = "1.74.0"
rust-version = "1.81.0"

[[bin]]
name = "stellar-xdr"
Expand All @@ -19,25 +19,27 @@ doctest = false
crate-git-revision = "0.0.6"

[dependencies]
stellar-strkey = { version = "0.0.9", optional = true }
stellar-strkey = { version = "0.0.11", optional = true }
base64 = { version = "0.13.0", optional = true }
serde = { version = "1.0.139", features = ["derive"], optional = true }
serde_with = { version = "3.0.0", optional = true }
escape-bytes = { version = "0.1.1", default-features = false }
hex = { version = "0.4.3", optional = true }
arbitrary = {version = "1.1.3", features = ["derive"], optional = true}
hex = { version = "0.4.3", default-features = false, optional = true }
arbitrary = { version = "1.1.3", features = ["derive"], optional = true }
clap = { version = "4.2.4", default-features = false, features = ["std", "derive", "usage", "help"], optional = true }
serde_json = { version = "1.0.89", optional = true }
thiserror = { version = "1.0.37", optional = true }
schemars = { version = "0.8.16", optional = true }
embedded-io-extras = { version = "0.0.2", default-features = false, optional = true }

[dev-dependencies]
serde_json = "1.0.89"

[features]
default = ["std", "curr"]
std = ["alloc"]
alloc = ["dep:hex", "dep:stellar-strkey", "escape-bytes/alloc"]
embedded_io = ["alloc", "dep:embedded-io-extras"]
alloc = ["dep:hex", "dep:stellar-strkey", "escape-bytes/alloc", "hex/alloc", "embedded-io-extras/alloc"]
curr = []
next = []

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ CARGO_HACK_ARGS=--feature-powerset --exclude-features default --group-features b

CARGO_DOC_ARGS?=--open

XDRGEN_VERSION=b7bc57ecdd277c9575930d3e17c12dfaa76655fc
# TODO: Update this after https://github.com/stellar/xdrgen/pull/205 is merged
XDRGEN_VERSION=e57dfa9199f476acde88ddb096699c829ad86c28
# XDRGEN_LOCAL=1
XDRGEN_TYPES_CUSTOM_STR_IMPL_CURR=PublicKey,AccountId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12,ClaimableBalanceId
XDRGEN_TYPES_CUSTOM_STR_IMPL_NEXT=PublicKey,AccountId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12,ClaimableBalanceId
Expand Down Expand Up @@ -44,7 +45,7 @@ src/curr/generated.rs: $(sort $(wildcard xdr/curr/*.x))
ifeq ($(XDRGEN_LOCAL),)
docker run -i --rm -v $$PWD:/wd -w /wd docker.io/library/ruby:latest /bin/bash -c '\
gem install specific_install -v 0.3.8 && \
gem specific_install https://github.com/stellar/xdrgen.git -b $(XDRGEN_VERSION) && \
gem specific_install https://github.com/lightsail-network/xdrgen.git -b $(XDRGEN_VERSION) && \
xdrgen --language rust --namespace generated --output src/curr \
--rust-types-custom-str-impl $(XDRGEN_TYPES_CUSTOM_STR_IMPL_CURR) \
--rust-types-custom-jsonschema-impl '$(XDRGEN_TYPES_CUSTOM_JSONSCHEMA_IMPL_CURR)' \
Expand All @@ -69,7 +70,7 @@ src/next/generated.rs: $(sort $(wildcard xdr/next/*.x))
ifeq ($(XDRGEN_LOCAL),)
docker run -i --rm -v $$PWD:/wd -w /wd docker.io/library/ruby:latest /bin/bash -c '\
gem install specific_install -v 0.3.8 && \
gem specific_install https://github.com/stellar/xdrgen.git -b $(XDRGEN_VERSION) && \
gem specific_install https://github.com/lightsail-network/xdrgen.git -b $(XDRGEN_VERSION) && \
xdrgen --language rust --namespace generated --output src/next \
--rust-types-custom-str-impl $(XDRGEN_TYPES_CUSTOM_STR_IMPL_NEXT) \
--rust-types-custom-jsonschema-impl '$(XDRGEN_TYPES_CUSTOM_JSONSCHEMA_IMPL_NEXT)' \
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ only necessary to use utility functions that depend on serde_json.
5. `hex` – Enables support for hex in string representations of some types.
Automatically enabled when serde is enabled.
6. `schemars` – Enables support for JSON Schema generation. (Experimental)
7. `embedded_io` - Enables support for encoding and decoding using the
`embedded-io` library, without relying on `std::io`, making it suitable for
`no_std` environments. (Experimental)

Features marked experimental may disappear at anytime, see breaking changes
at anytime, or and may be minimal implementations instead of complete.
Expand Down
Loading
Loading