Skip to content

Commit

Permalink
Add some features to reduce size (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Sep 27, 2024
1 parent 3f6f6d8 commit 489edd9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ on:

jobs:
build-and-test:
name: Build and test (${{ matrix.os }})
name: Build and test with features '${{ matrix.features }}' (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ ubuntu-22.04 ]
features: [ "all", "" ]
env:
RUST_BACKTRACE: full
steps:
Expand All @@ -40,7 +41,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run tests
run: just verify
run: just --set features "${{ matrix.features }}" verify

build-smoke-test:
name: Build only (${{ matrix.os }} / ${{ matrix.target }})
Expand Down
17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ description = "SDK Shared core"
license = "MIT"
repository = "https://github.com/restatedev/sdk-shared-core"

[features]
default = []
request_identity = ["dep:ring", "dep:sha2", "dep:jsonwebtoken", "dep:bs58"]
sha2_random_seed = ["dep:sha2"]

[dependencies]
thiserror = "1.0.61"
prost = "0.13.2"
bytes = "1.6"
bytes-utils = "0.1.4"
ambassador = "0.4.0"
tracing = "0.1.40"
paste = "1.0.15"
strum = { version = "0.26", features = ["derive"] }
base64 = "0.22"
bs58 = { version = "0.5.0" }
sha2 = "0.11.0-pre.3"
ring = { version = "0.17.8" }
jsonwebtoken = { version = "9.3.0" }
serde = { version = "1.0.204", features = ["derive"] }

sha2 = { version = "0.11.0-pre.3", optional = true }

bs58 = { version = "0.5.1", optional = true }
ring = { version = "0.17.8", optional = true }
jsonwebtoken = { version = "9.3.0", optional = true }

http = { version = "1.1.0", optional = true }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ check-fmt:
cargo fmt --all -- --check

clippy: (_target-installed target)
cargo clippy {{ _target-option }} --all-targets --workspace -- -D warnings
cargo clippy {{ _target-option }} {{ _features }} --all-targets --workspace -- -D warnings

# Runs all lints (fmt, clippy, deny)
lint: check-fmt clippy
Expand All @@ -64,7 +64,7 @@ print-target:
@echo {{ _resolved_target }}

test: (_target-installed target)
cargo nextest run {{ _target-option }} --all-features
cargo nextest run {{ _target-option }} {{ _features }}

# Runs lints and tests
verify: lint test
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod headers;
#[cfg(feature = "request_identity")]
mod request_identity;
mod retries;
mod service_protocol;
Expand All @@ -12,6 +13,7 @@ use std::time::Duration;
pub use crate::retries::RetryPolicy;
use crate::vm::AsyncResultAccessTrackerInner;
pub use headers::HeaderMap;
#[cfg(feature = "request_identity")]
pub use request_identity::*;
pub use vm::CoreVM;

Expand Down
15 changes: 13 additions & 2 deletions src/vm/transitions/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use crate::{
AsyncResultHandle, Header, Input, NonEmptyValue, RetryPolicy, RunEnterResult, RunExitResult,
VMError,
};
use bytes::Buf;
use sha2::{Digest, Sha256};
use std::{fmt, mem};

impl State {
Expand Down Expand Up @@ -137,12 +135,25 @@ impl TransitionAndReturn<Context, SysInput> for State {
}
}

#[cfg(feature = "sha2_random_seed")]
fn compute_random_seed(id: &[u8]) -> u64 {
use bytes::Buf;
use sha2::{Digest, Sha256};

let id_hash = Sha256::digest(id);
let mut b = id_hash.as_slice();
b.get_u64()
}

#[cfg(not(feature = "sha2_random_seed"))]
fn compute_random_seed(id: &[u8]) -> u64 {
use std::hash::{DefaultHasher, Hash, Hasher};

let mut hasher = DefaultHasher::new();
id.hash(&mut hasher);
hasher.finish()
}

pub(crate) struct SysNonCompletableEntry<M>(pub(crate) &'static str, pub(crate) M);

impl<M: RestateMessage + EntryMessageHeaderEq + EntryMessage + Clone + WriteableRestateMessage>
Expand Down

0 comments on commit 489edd9

Please sign in to comment.