Repository navigation
feat: gate the server behind a default feature - #19
Closed
jonasz-lasut wants to merge 2 commits into
Closed
jonasz-lasut wants to merge 2 commits into
jonasz-lasut wants to merge 2 commits into
Conversation
tonic's service generator appended the gRPC client and server to prost's message file. A wrapping ServiceGenerator routes its output into sdk/src/generated/v1.tonic.rs instead, so the messages and the gRPC code can be included independently. The generated bytes are unchanged: the old v1.rs is the new v1.rs followed by v1.tonic.rs. Signed-off-by: Jonasz Małecki <jonasz@upbound.io>
The crate had no Cargo features: tokio, tonic with its TLS stack, clap, prometheus-client and the generated tonic client and server were unconditional, so a WebAssembly guest that wants only the messages and the request/response/resource helpers could not depend on it. A server feature, on by default, now carries server.rs, metrics.rs, logging.rs, the server-side Error variants, the generated tonic client and server and FILE_DESCRIPTOR_SET, with their dependencies optional behind it. Every current dependent keeps the whole crate; with default-features = false the messages and the helpers remain and build for wasm32-wasip1 and wasm32-wasip2. CI builds that set natively and for wasm32-wasip1. Fixes #18 Signed-off-by: Jonasz Małecki <jonasz@upbound.io>
jonasz-lasut
force-pushed
the
feat/server-feature
branch
from
October 7, 2026 12:05
c554940 to
2e156fb
Compare
Collaborator
Author
|
Closing: the split is more invasive than the gain for its one consumer justifies. function-wasm keeps vendoring run_function.proto for its rust scaffold instead (jonasz-lasut/function-wasm#129). |
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.
Motivation
The crate has no Cargo features, so everything it links is unconditional: tokio (
rt-multi-thread,signal), tonic withtls-aws-lc, tonic-health, tonic-reflection, clap, prometheus-client, tracing-subscriber and the generated tonic client and server. A WebAssembly guest that wants only the protocol messages and therequest/response/resourcehelpers cannot depend on it, because tokio and aws-lc-sys do not build for wasm targets.What the
serverfeature gates[features] default = ["server"]. The feature enables the optional dependencies (bytes, clap, http, http-body, prometheus-client, tokio, tonic, tonic-health, tonic-prost, tonic-reflection, tower-layer, tower-service, tracing, tracing-subscriber) and, under#[cfg(feature = "server")]:server.rs(serve,Args, the re-exports),metrics.rs,logging.rsErrorvariants:InvalidAddress,MissingTlsCertsDir,ReadCertificate,Transport,Reflection, and with them theirFromimplsfunction_runner_service_client/function_runner_service_servermodules underproto::v1proto::FILE_DESCRIPTOR_SETserveintegration test (required-features = ["server"])Every existing dependent keeps the whole crate, the feature being on by default. The feature is documented in the README (a "Features" section), the crate README, the crate docs and
sdk/Cargo.toml.What
default-features = falsebuildsThe protocol messages with their protojson serde impls, plus
context,request,responseandresource. That set builds natively and forwasm32-wasip1andwasm32-wasip2, and is what a function compiled to a WebAssembly module depends on (function-wasm's Rust scaffold, whose host serves the gRPC side). A newno-serverCI job builds, tests and lints that set natively and builds it forwasm32-wasip1.How the generated code stays reproducible
No generated output was edited by hand. tonic's service generator used to append the gRPC client and server to prost's message file;
codegennow wraps it in aprost_build::ServiceGeneratorthat routes its output into a buffer of its own, written tosdk/src/generated/v1.tonic.rs.proto.rsincludes that file under the cfg, next to the unconditionalv1.rsandv1.serde.rs. The bytes are unchanged: the oldv1.rsis the newv1.rsfollowed byv1.tonic.rs, andv1.serde.rsdid not move.cargo run -p codegenregenerates all three as before, and the existingcodegen-driftjob covers the new file through itssdk/src/generated/*.rsglob. The committedfileset.binwas left as is (it differs only by local protoc version, which that job tolerates).The change is two commits: the codegen split on its own (builds and tests exactly as before, with the new file included unconditionally), then the feature gate.
Verified
All on stable Rust 1.97.1, macOS arm64:
cargo fmt --all --check: cleancargo clippy --workspace --tests -- -D warnings(CI's command) andcargo clippy --workspace --all-targets -- -D warnings: cleancargo clippy -p function-sdk-rust --no-default-features --all-targets -- -D warnings: cleancargo test --workspace: all pass (5 unit, 18 helpers, 1 serve, doc tests)cargo test -p function-sdk-rust --no-default-features: all pass (18 helpers, doc tests;serveskipped byrequired-features)cargo build -p function-sdk-rust --no-default-features: okcargo build -p function-sdk-rust --no-default-features --target wasm32-wasip1: okcargo build -p function-sdk-rust --no-default-features --target wasm32-wasip2: okRUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p function-sdk-rust, with and without--no-default-features: cleancargo run -p codegenthendiff <(cat v1.rs v1.tonic.rs) <(git show main:sdk/src/generated/v1.rs): identicalcargo publish -p function-sdk-rust --dry-run: ok,v1.tonic.rspackagedCargo.lock: unchangedFixes #18