@@ -30,7 +30,9 @@ use crate::core::dependency::{Artifact, ArtifactKind, ArtifactTarget, DepKind};
30
30
use crate :: core:: profiles:: { Profile , Profiles , UnitFor } ;
31
31
use crate :: core:: resolver:: Resolve ;
32
32
use crate :: core:: resolver:: features:: { FeaturesFor , ResolvedFeatures } ;
33
- use crate :: core:: { Dependency , Package , PackageId , PackageSet , Target , TargetKind , Workspace } ;
33
+ use crate :: core:: {
34
+ Dependency , Feature , Package , PackageId , PackageSet , Target , TargetKind , Workspace ,
35
+ } ;
34
36
use crate :: ops:: resolve_all_features;
35
37
use crate :: util:: GlobalContext ;
36
38
use crate :: util:: interning:: InternedString ;
@@ -142,8 +144,27 @@ pub fn build_unit_dependencies<'a, 'gctx>(
142
144
// which affect the determinism of the build itself. As a result be sure
143
145
// that dependency lists are always sorted to ensure we've always got a
144
146
// deterministic output.
145
- for list in state. unit_dependencies . values_mut ( ) {
146
- list. sort ( ) ;
147
+ for ( unit, list) in & mut state. unit_dependencies {
148
+ let is_multiple_build_scripts_enabled = unit
149
+ . pkg
150
+ . manifest ( )
151
+ . unstable_features ( )
152
+ . require ( Feature :: multiple_build_scripts ( ) )
153
+ . is_ok ( ) ;
154
+
155
+ if is_multiple_build_scripts_enabled {
156
+ list. sort_by_key ( |unit_dep| {
157
+ if unit_dep. unit . target . is_custom_build ( ) {
158
+ // We do not sort build scripts to preserve the user-defined order.
159
+ // In terms of determinism, we are assuming nothing interferes with order from when the user set it in `Cargo.toml` to here
160
+ ( 0 , None )
161
+ } else {
162
+ ( 1 , Some ( unit_dep. clone ( ) ) )
163
+ }
164
+ } ) ;
165
+ } else {
166
+ list. sort ( ) ;
167
+ }
147
168
}
148
169
trace ! ( "ALL UNIT DEPENDENCIES {:#?}" , state. unit_dependencies) ;
149
170
0 commit comments