Fallback to spec shaking v1 if env var is not set#1831
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Soroban SDK’s “spec shaking v2” behavior so that enabling the experimental_spec_shaking_v2 feature no longer causes a wasm build to panic when the SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2 env var is missing; instead it falls back to v1 behavior and warns.
Changes:
- Add a
spec_shaking_v2cfg (enabled only when both the feature is on and the env var is present) and gate v2-only SDK code on it, emitting a build warning on wasm when falling back. - Update the proc-macro codegen so v2-only exports/markers are generated only when v2 is actually active (feature + env var).
- Extend the spec shaking v2 test harness/Makefile to build a “no env var” wasm and assert v1 fallback behavior.
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
soroban-sdk/build.rs |
Defines cfg(spec_shaking_v2) based on env var presence; emits a warning on wasm when falling back. |
soroban-sdk/src/lib.rs |
Gates v2 marker meta + SpecShakingMarker export behind cfg(spec_shaking_v2). |
soroban-sdk/src/into_val_for_contract_fn.rs |
Switches v2-only marker calls from feature-gating to cfg(spec_shaking_v2). |
soroban-sdk/src/try_from_val_for_contract_fn.rs |
Same as above for inbound conversions. |
soroban-sdk/src/_features.rs |
Documents env-var-controlled activation and fallback behavior. |
soroban-sdk-macros/src/lib.rs |
Adds env-var-aware spec_shaking_v2_enabled() helper to control v2 codegen. |
soroban-sdk-macros/src/derive_*.rs |
Uses spec_shaking_v2_enabled() to conditionally generate marker impls / exports. |
tests/spec_shaking_v2/src/test.rs |
Adds a second wasm fixture and a test covering “no env var => v1 fallback”. |
Makefile |
Builds test_spec_shaking_v2 twice (with and without env var) and saves the “no env” wasm. |
tests-expanded/* |
Updates checked-in macro expansions to reflect new conditional marker/export generation. |
sisuresh
approved these changes
Apr 9, 2026
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.
What
Change spec shaking v2 feature to gracefully fall back to v1 when the
SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2env var is not set, instead of panicking.If the build process falls back to v1, a build warning is emitted:
Why
The
experimental_spec_shaking_v2feature is enabled by default. Previously, if the env var was not set and the target was wasm, the build script panicked with an error.Now, spec shaking v2 activates only when both the feature and the env var are present. When the feature is enabled but the env var is missing, the SDK falls back to v1 behavior and emits a compiler warning on wasm targets. This allows
cargo buildto succeed without requiringstellar-cli, while still benefiting from v2 when built with compatible tooling.Known limitations
None