Skip to content

Fallback to spec shaking v1 if env var is not set#1831

Merged
mootz12 merged 3 commits intomainfrom
fix-spec-v2-build-error
Apr 9, 2026
Merged

Fallback to spec shaking v1 if env var is not set#1831
mootz12 merged 3 commits intomainfrom
fix-spec-v2-build-error

Conversation

@mootz12
Copy link
Copy Markdown
Contributor

@mootz12 mootz12 commented Apr 9, 2026

What

Change spec shaking v2 feature to gracefully fall back to v1 when the SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2 env var is not set, instead of panicking.

If the build process falls back to v1, a build warning is emitted:

    Compiling soroban-sdk v26.0.0-rc.1 (/Users/alex/dev/stellar/rs-soroban-sdk/soroban-sdk)
warning: soroban-sdk@26.0.0-rc.1: soroban-sdk: feature 'experimental_spec_shaking_v2' was enabled 
but not used, because this build was not started by a tool that supports spec shaking v2. Falling back to
spec shaking v1. To use v2, use a build tool that supports spec shaking v2 such as stellar-cli v25.2.0+ 
with `stellar contract build`. To manually use v2 without a supporting build tool, set the env var 
SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2 before building.

Why

The experimental_spec_shaking_v2 feature 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 build to succeed without requiring stellar-cli, while still benefiting from v2 when built with compatible tooling.

Known limitations

None

Copilot AI review requested due to automatic review settings April 9, 2026 01:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_v2 cfg (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.

@mootz12 mootz12 added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit c80fb1b Apr 9, 2026
111 checks passed
@mootz12 mootz12 deleted the fix-spec-v2-build-error branch April 9, 2026 13:53
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.

3 participants