@@ -30,7 +30,9 @@ use crate::core::dependency::{Artifact, ArtifactKind, ArtifactTarget, DepKind};
3030use crate :: core:: profiles:: { Profile , Profiles , UnitFor } ;
3131use crate :: core:: resolver:: Resolve ;
3232use 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+ } ;
3436use crate :: ops:: resolve_all_features;
3537use crate :: util:: GlobalContext ;
3638use crate :: util:: interning:: InternedString ;
@@ -142,8 +144,28 @@ pub fn build_unit_dependencies<'a, 'gctx>(
142144 // which affect the determinism of the build itself. As a result be sure
143145 // that dependency lists are always sorted to ensure we've always got a
144146 // deterministic output.
145- for list in state. unit_dependencies . values_mut ( ) {
146- list. sort ( ) ;
147+ // We do not sort build scripts to preserve the user-defined order.
148+ for unit_dep in & mut state. unit_dependencies {
149+ let is_multiple_build_scripts_enabled = unit_dep
150+ . 0
151+ . pkg
152+ . manifest ( )
153+ . unstable_features ( )
154+ . require ( Feature :: multiple_build_scripts ( ) )
155+ . is_ok ( ) ;
156+
157+ let list = unit_dep. 1 ;
158+ if is_multiple_build_scripts_enabled {
159+ list. sort_by_key ( |unit_dep| {
160+ if unit_dep. unit . target . is_custom_build ( ) {
161+ ( 0 , None )
162+ } else {
163+ ( 1 , Some ( unit_dep. clone ( ) ) )
164+ }
165+ } ) ;
166+ } else {
167+ list. sort ( ) ;
168+ }
147169 }
148170 trace ! ( "ALL UNIT DEPENDENCIES {:#?}" , state. unit_dependencies) ;
149171
0 commit comments