Open leighmcculloch opened 2 weeks ago
Can you provide a standalone and minimal test case that reproduces the issue? That would be helpful in diagnosing and fixing the bug.
I suspect it's the use of std::thread_local in the recursion counter.
I think folks should just #[cfg_attr(feature = "std", derive(Arbitrary))]
or something (or #[cfg(feature = "arbitrary)] extern crate std;
). I don't think this crate ever guaranteed that the derive works in no_std
. We potentially could try to but I don't see a clean way of doing so without losing the recursion guard.
Recursion guard was added in https://github.com/rust-fuzz/arbitrary/pull/109
Up until the 1.4 releases we've been able to support arbitrary in no_std crates by extern importing std into the space like so:
soroban-sdk-macros/src/arbitrary.rs
:
const _: () = {
// derive(Arbitrary) expects these two to be in scope
use #path::testutils::arbitrary::std;
use #path::testutils::arbitrary::arbitrary;
#[derive(#path::testutils::arbitrary::arbitrary::Arbitrary)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
#vis #arbitrary_type_decl
impl #path::testutils::arbitrary::SorobanArbitrary for #ident {
type Prototype = #arbitrary_type_ident;
}
impl #path::TryFromVal<#path::Env, #arbitrary_type_ident> for #ident {
type Error = #path::ConversionError;
fn try_from_val(env: &#path::Env, v: &#arbitrary_type_ident) -> std::result::Result<Self, Self::Error> {
Ok(#arbitrary_ctor)
}
}
};
soroban-sdk/src/testutils/arbitrary.rs
:
// Used by `contracttype`
#[doc(hidden)]
pub use std;
It seems something has changed where I guess the arbitrary derive is now creating a new scope, that isn't seeing the std
we are including into the derive scope.
I think this basically breaks arbitrary for any no_std crate, where it worked before as long as the crate imported std into the scope being derived into.
Similar to #203, it seems like the
1.4.1
releases are still making assumptions about items in the current space that weren't prior, which is a breaking change, and fails to build on projects who were dependent on1.3.2
.Cargo.toml
:src/lib.rs
:Run
cargo test
with1.4.1
:Included in the output are the following build errors:
Re-run
cargo test
with1.3.2
and it compiles: