`RUSTFLAGS="-Znext-solver"` doesn't take effect when cross-compiling

I'm building a crate with cargo rustc like this:

And it worked well so far. Now I needed to add -Znext-solver to RUSTFLAGS, but it doesn't have effect, I'm still getting this from dependencies:

  error: `generic_const_args` requires -Znext-solver=globally to be enabled
    --> crates/shared/ab-merkle-tree/src/lib.rs:36:5
     |
  36 |     generic_const_args,
     |     ^^^^^^^^^^^^^^^^^^
     |
     = help: enable all of these features

I'm quite confused by this since --cfg flags definitely work, but -Znext-solver clearly doesn't.

What am I missing?

Your post title says RUSTFLAGS="-Znext-solver", but the error message says it requires "-Znext-solver=globally". Which one did you actually try?

I do try RUSTFLAGS="-Znext-solver=globally", but since =globally is just a value I skipped it in the title

Just tried creating .cargo/config.toml:

[build]
rustflags = ["-Znext-solver=globally"]

But it didn't apply either.

Is cargo rustc somehow special vs cargo build/cargo clippy in this regard or what is going on here?

I think cargo rustc only applies the flags you give it to the root crate, not the dependencies.

The env var works on all crates.

I use RUSTFLAGS environment variable and I can't seem to enable next solver with it. --cfg sha2_backend="riscv-zknh" is used deep in dependencies and is applied correctly.

How did you use RUSTFLAGS to enable next-solver?

Oh, and could you try adding --verbose to the cargo arguments, so it shows in stderr what rustc commands are running?

I literally specify RUSTFLAGS="-Znext-solver=globally" or in case of above script I added -Znext-solver=globally to the end of the value of RUSTFLAGS:

--- a/crates/contracts/core/ab-contracts-tooling/src/build.rs
+++ b/crates/contracts/core/ab-contracts-tooling/src/build.rs
@@ -43,7 +43,7 @@
         // and they really don't like using normal features for it
         .env(
             "RUSTFLAGS",
-            "--cfg sha2_backend=\"riscv-zknh\" --cfg sha2_backend_riscv_zknh=\"compact\"",
+            "--cfg sha2_backend=\"riscv-zknh\" --cfg sha2_backend_riscv_zknh=\"compact\" -Znext-solver=globally",
         )
         .args([
             "rustc",

I tried -v, but rustc command had neither --cfg flags no solver flags:

Summary

process didn't exit successfully: /home/nazar-pc/.rustup/toolchains/nightly-2026-05-29-x86_64-unknown-linux-gnu/bin/rustc --crate-name ab_merkle_tree --edition=2024 crates/shared/ab-merkle-tree/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no '--warn=clippy::restriction' '--warn=clippy::pedantic' '--allow=clippy::wildcard_imports' '--allow=clippy::wildcard_enum_match_arm' '--allow=clippy::verbose_file_reads' '--allow=clippy::use_debug' '--allow=clippy::unwrap_used' '--allow=clippy::unwrap_in_result' '--allow=clippy::unused_trait_names' '--allow=clippy::unused_self' '--allow=clippy::unused_async' '--allow=clippy::unseparated_literal_suffix' '--allow=clippy::unsafe_derive_deserialize' --warn=unreachable_pub '--allow=clippy::unreachable' '--allow=clippy::unnested_or_patterns' '--allow=clippy::unneeded_field_pattern' '--allow=clippy::unnecessary_safety_comment' '--allow=clippy::unnecessary_box_returns' '--allow=clippy::unimplemented' '--allow=clippy::unchecked_time_subtraction' '--allow=clippy::trivially_copy_pass_by_ref' '--allow=clippy::transmute_ptr_to_ptr' '--allow=clippy::too_many_lines' '--allow=clippy::tests_outside_test_module' '--allow=clippy::struct_field_names' '--allow=clippy::struct_excessive_bools' '--allow=clippy::string_slice' '--allow=clippy::str_to_string' '--allow=clippy::std_instead_of_core' '--allow=clippy::std_instead_of_alloc' '--allow=clippy::stable_sort_primitive' '--allow=clippy::single_char_lifetime_names' '--allow=clippy::single_call_fn' '--allow=clippy::similar_names' '--allow=clippy::should_panic_without_expect' '--allow=clippy::shadow_unrelated' '--allow=clippy::shadow_same' '--allow=clippy::shadow_reuse' '--allow=clippy::separated_literal_suffix' '--allow=clippy::semicolon_outside_block' '--allow=clippy::semicolon_if_nothing_returned' '--allow=clippy::self_named_module_files' '--allow=clippy::same_name_method' '--allow=clippy::same_length_and_capacity' --warn=rust_2018_idioms '--allow=clippy::return_self_not_must_use' '--allow=clippy::ref_patterns' '--allow=clippy::redundant_type_annotations' '--allow=clippy::redundant_test_prefix' '--allow=clippy::rc_buffer' '--allow=clippy::question_mark_used' '--allow=clippy::pub_with_shorthand' '--allow=clippy::pub_use' '--allow=clippy::pub_underscore_fields' '--allow=clippy::print_stdout' '--allow=clippy::print_stderr' '--allow=clippy::pattern_type_mismatch' '--allow=clippy::partial_pub_fields' '--allow=clippy::panic_in_result_fn' '--allow=clippy::panic' '--allow=clippy::option_option' '--allow=clippy::non_zero_suggestions' '--allow=clippy::non_ascii_literal' '--allow=clippy::needless_pass_by_value' '--allow=clippy::needless_borrows_for_generic_args' '--allow=clippy::must_use_candidate' '--allow=clippy::multiple_unsafe_ops_per_block' '--allow=clippy::multiple_inherent_impl' '--allow=clippy::modulo_arithmetic' '--allow=clippy::module_name_repetitions' '--allow=clippy::missing_trait_methods' '--allow=clippy::missing_panics_doc' '--allow=clippy::missing_inline_in_public_items' '--allow=clippy::missing_errors_doc' '--allow=clippy::missing_docs_in_private_items' --warn=missing_debug_implementations '--allow=clippy::missing_asserts_for_indexing' '--allow=clippy::missing_assert_message' '--allow=clippy::min_ident_chars' '--allow=clippy::mem_forget' '--allow=clippy::match_same_arms' '--allow=clippy::many_single_char_names' '--allow=clippy::little_endian_bytes' '--allow=clippy::let_underscore_must_use' '--allow=clippy::large_types_passed_by_value' '--allow=clippy::large_stack_arrays' '--allow=clippy::large_futures' '--allow=clippy::iter_over_hash_type' '--allow=clippy::items_after_statements' '--allow=clippy::integer_division_remainder_used' '--allow=clippy::integer_division' '--allow=clippy::inline_always' '--allow=clippy::infinite_loop' '--allow=clippy::indexing_slicing' '--allow=clippy::implicit_return' '--allow=clippy::implicit_hasher' '--allow=clippy::impl_trait_in_params' '--allow=clippy::ignored_unit_patterns' '--allow=clippy::ignore_without_reason' '--allow=clippy::if_then_some_else_none' '--allow=clippy::host_endian_bytes' '--allow=clippy::get_unwrap' '--allow=clippy::from_iter_instead_of_collect' '--allow=clippy::float_cmp' '--allow=clippy::float_arithmetic' '--allow=clippy::field_scoped_visibility_modifiers' '--allow=clippy::expect_used' '--allow=clippy::exit' '--allow=clippy::exhaustive_structs' '--allow=clippy::exhaustive_enums' '--allow=clippy::error_impl_error' '--allow=clippy::empty_drop' '--allow=clippy::else_if_without_else' '--allow=clippy::elidable_lifetime_names' '--allow=clippy::doc_paragraphs_missing_punctuation' '--allow=clippy::doc_markdown' '--allow=clippy::doc_link_with_quotes' '--allow=clippy::default_trait_access' '--allow=clippy::default_numeric_fallback' '--allow=clippy::decimal_literal_representation' '--allow=clippy::decimal_bitwise_operands' '--allow=clippy::create_dir' '--allow=clippy::collapsible_else_if' '--allow=clippy::cognitive_complexity' '--allow=clippy::cast_ptr_alignment' '--allow=clippy::cast_precision_loss' '--allow=clippy::cast_possible_truncation' '--allow=clippy::borrow_as_ptr' '--allow=clippy::blanket_clippy_restriction_lints' '--allow=clippy::big_endian_bytes' '--allow=clippy::assertions_on_result_states' '--allow=clippy::as_underscore' '--deny=clippy::as_ptr_cast_mut' '--allow=clippy::as_conversions' '--allow=clippy::arithmetic_side_effects' '--allow=clippy::arbitrary_source_item_ordering' '--allow=clippy::allow_attributes_without_reason' '--allow=clippy::absolute_paths' --allow=unexpected_cfgs --check-cfg 'cfg(target_arch, values("spirv"))' -C debug-assertions=off --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("alloc", "blake3", "no-panic"))' -C metadata=00d8ca5591c4d548 -C extra-filename=-6749c9a0e6fd2495 --out-dir /home/nazar-pc/.cache/cargo/target/release/build/ab-riscv-benchmarks-70a4aa4b3a17b6e8/out/contract/deps -C strip=debuginfo -L dependency=/home/nazar-pc/.cache/cargo/target/release/build/ab-riscv-benchmarks-70a4aa4b3a17b6e8/out/contract/deps --extern ab_blake3=/home/nazar-pc/.cache/cargo/target/release/build/ab-riscv-benchmarks-70a4aa4b3a17b6e8/out/contract/deps/libab_blake3-fca88b44234daf78.rmeta --verbose -L native=/home/nazar-pc/.cache/cargo/target/release/build/ab-riscv-benchmarks-70a4aa4b3a17b6e8/out/contract/build/blake3-075decbe4e8cc885/out -L native=/home/nazar-pc/.cache/cargo/target/release/build/ab-riscv-benchmarks-70a4aa4b3a17b6e8/out/contract/build/blake3-075decbe4e8cc885/out (exit status: 101)

It looks like that crate is compiled for the host. If --target is passed to cargo, RUSTFLAGS will be ignored for all host dependencies.

Thanks for the hint! Now I know what it is. That same crate is also compiled as part of the build script dependencies, which uses yet another set of flags, and that is what didn't compile.

Thank you!

This was caused by --target presence, which prevented propagation of rustflags, so I had to add this to the cargo rustc invocation:

.args([
    "-Ztarget-applies-to-host",
    "-Zhost-config",
    "--config",
    r#"host.rustflags=["-Znext-solver=globally"]"#,
])

Very confusing behavior, but :man_shrugging: