Skip to content
Open
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
29 changes: 19 additions & 10 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ MAIN_FILES = $(GENERATED_VERSION_SOURCES) main/main.cpp

if BUILD_TESTS
stellar_core_SOURCES = $(MAIN_FILES) $(SRC_CXX_FILES) $(SRC_TEST_CXX_FILES)
CARGO_FEATURE_FUZZ_TARGETS = --features fuzz_targets
CARGO_FEATURE_TESTUTILS = --features testutils
else # !BUILD_TESTS
stellar_core_SOURCES = $(MAIN_FILES) $(SRC_CXX_FILES)
CARGO_FEATURE_FUZZ_TARGETS =
CARGO_FEATURE_TESTUTILS =
endif # !BUILD_TESTS

Expand Down Expand Up @@ -310,17 +312,24 @@ $(SOROBAN_BUILD_DIR)/%/target/git-state.txt: $(top_srcdir)/.git/modules/src/rust
printf '%s\n' "$$state" > $@.tmp; \
if cmp -s $@.tmp $@; then rm -f $@.tmp; else mv -f $@.tmp $@; fi

# The fastdev rust build is a special non-production mode that builds all of
# the rust dependencies of librust_stellar_core.a through a single cargo
# invocation, which is actually the "normal" way cargo operates, but which also
# has the negative side effect of resolving (merging) different point releases
# and pre-release minor versions across transitive dependencies, which means we
# The fastdev rust build is a special non-production mode that builds all of the
# rust dependencies of librust_stellar_core.a through a single cargo invocation,
# which is actually the "normal" way cargo operates, but which also has the
# negative side effect of resolving (merging) different point releases and
# pre-release minor versions across transitive dependencies, which means we
# can't control the _exact_ transitive dependencies as well as we'd like.
#
# So we only use the fastdev rust build for certain special cases such as
# testing with asan/tsan (they seem to only work well when built this way) and
# use the non-unified build (with separate .a files for each separate soroban
# version) for production builds.
# So we only use the fastdev rust build for fast iteration while doing
# development, or for special cases like testing with asan/tsan (they seem to
# only work well when built this way), and use the non-unified build (with
# separate .a files for each separate soroban version) for production builds.
#
# One important caveat: the $(CARGO_FEATURE_FUZZ_TARGETS) feature should _not_
# be passed to fastdev mode. It pulls in a separate copy of the soroban host
# with `testutils` enabled, which winds up up causing `testutils` to be enabled
# _on the production soroban host_ as well, which causes the build to diverge if
# run against mainnet. Leave $(CARGO_FEATURE_FUZZ_TARGETS) for the non-fastdev
# build.

if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION

Expand Down Expand Up @@ -461,7 +470,7 @@ $(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) $(ALL_SOROBAN_L
--locked \
--target-dir $(abspath $(RUST_TARGET_DIR)) \
$(CARGO_FEATURE_TRACY) $(CARGO_FEATURE_NEXT) $(CARGO_FEATURE_TESTUTILS) \
$(CARGO_FEATURE_TCMALLOC) \
$(CARGO_FEATURE_TCMALLOC) $(CARGO_FEATURE_FUZZ_TARGETS) \
-- \
$(ALL_SOROBAN_EXTERN_ARGS) \
$(ALL_SOROBAN_DEPEND_ARGS)
Expand Down
20 changes: 15 additions & 5 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,20 @@ tcmalloc = []
# staging work across intra-protocol releases.
next = []


# The testutils feature turns on stuff that should only be available in a core
# BUILD_TESTS build, such as the code to support transaction re-execution on a
# secondary host, AND enables the soroban-fuzz-targets dependency. This allows
# fuzz smoke tests to run in normal test builds without requiring the full fuzz
# _instrumentation_ infrastructure.
testutils = ["dep:soroban-fuzz-targets"]
# secondary host.

testutils = []

# Enables the soroban-fuzz-targets dependency. This may be enabled either in
# full fuzz-instrumentation builds, or even just during normal test-enabled
# builds in which the core unit tests will run soroban fuzz targets as smoke
# tests.
#
# However, this should _not_ be enabled in a fastdev build, because the
# soroban-fuzz-targets crate will pull in its own copy of the soroban host _with
# testutils enabled_ (for recording), and since fastdev is a unified build, this
# will turn on testutils in the accompanying _production soroban host_, which
# will cause it to diverge if run on mainnet.
fuzz_targets = ["dep:soroban-fuzz-targets"]
6 changes: 3 additions & 3 deletions src/rust/src/soroban_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
use crate::rust_bridge::FuzzResultCode;

// Stub implementation when testutils feature is disabled
#[cfg(not(feature = "testutils"))]
#[cfg(not(feature = "fuzz_targets"))]
pub fn run_soroban_fuzz_target(_name: &str, _data: &[u8]) -> FuzzResultCode {
FuzzResultCode::FUZZ_DISABLED
}

// When testutils feature is enabled, import and use the actual implementations
#[cfg(feature = "testutils")]
#[cfg(feature = "fuzz_targets")]
use soroban_fuzz_targets::{self as fuzz, FuzzResult};

/// Run a Soroban fuzz target with the given input bytes.
/// Panics on internal errors (which is what the fuzzer wants to find!)
#[cfg(feature = "testutils")]
#[cfg(feature = "fuzz_targets")]
pub fn run_soroban_fuzz_target(name: &str, data: &[u8]) -> FuzzResultCode {
let result = match name {
"soroban_expr" => fuzz::expr::run_fuzz_target(data),
Expand Down
Loading