@@ -76,17 +76,12 @@ pub fn build_unit_dependencies<'a, 'cfg>(
7676 } ;
7777
7878 let std_unit_deps = calc_deps_of_std ( & mut state, std_roots) ?;
79- let libtest_unit_deps = calc_deps_of_libtest ( & mut state, std_roots, roots) ?;
8079
8180 deps_of_roots ( roots, & mut state) ?;
8281 super :: links:: validate_links ( state. resolve ( ) , & state. unit_dependencies ) ?;
8382 // Hopefully there aren't any links conflicts with the standard library?
8483
85- if let Some ( mut std_unit_deps) = std_unit_deps {
86- if let Some ( libtest_unit_deps) = libtest_unit_deps {
87- attach_std_test ( & mut state, libtest_unit_deps, & std_unit_deps) ;
88- }
89- fixup_proc_macro ( & mut std_unit_deps) ;
84+ if let Some ( std_unit_deps) = std_unit_deps {
9085 attach_std_deps ( & mut state, std_roots, std_unit_deps) ;
9186 }
9287
@@ -122,118 +117,6 @@ fn calc_deps_of_std<'a, 'cfg>(
122117 ) ) )
123118}
124119
125- /// Compute all the dependencies for libtest.
126- /// Returns None if libtest is not needed.
127- fn calc_deps_of_libtest < ' a , ' cfg > (
128- mut state : & mut State < ' a , ' cfg > ,
129- std_roots : & [ Unit < ' a > ] ,
130- roots : & [ Unit < ' a > ] ,
131- ) -> CargoResult < Option < UnitGraph < ' a > > > {
132- // Conditionally include libtest.
133- if std_roots. is_empty ( )
134- || !roots
135- . iter ( )
136- . any ( |unit| unit. mode . is_rustc_test ( ) && unit. target . harness ( ) )
137- {
138- return Ok ( None ) ;
139- }
140- state. is_std = true ;
141- let test_id = state. resolve ( ) . query ( "test" ) ?;
142- let test_pkg = state. get ( test_id) ?. expect ( "test doesn't need downloading" ) ;
143- let test_target = test_pkg
144- . targets ( )
145- . iter ( )
146- . find ( |t| t. is_lib ( ) )
147- . expect ( "test has a lib" ) ;
148- let test_unit = new_unit (
149- state,
150- test_pkg,
151- test_target,
152- UnitFor :: new_normal ( ) ,
153- Kind :: Target ,
154- CompileMode :: Build ,
155- ) ;
156- let res = calc_deps_of_std ( state, & [ test_unit] ) ?;
157- state. is_std = false ;
158- Ok ( res)
159- }
160-
161- /// `proc_macro` has an implicit dependency on `std`, add it.
162- fn fixup_proc_macro < ' a > ( std_unit_deps : & mut UnitGraph < ' a > ) {
163- // Synthesize a dependency from proc_macro -> std.
164- //
165- // This is a gross hack. This wouldn't be necessary with `--sysroot`. See
166- // also libtest below.
167- if let Some ( std) = std_unit_deps
168- . keys ( )
169- . find ( |unit| unit. pkg . name ( ) . as_str ( ) == "std" && unit. target . is_lib ( ) )
170- . cloned ( )
171- {
172- for ( unit, deps) in std_unit_deps. iter_mut ( ) {
173- if unit. pkg . name ( ) . as_str ( ) == "proc_macro" {
174- deps. push ( UnitDep {
175- unit : std,
176- unit_for : UnitFor :: new_normal ( ) ,
177- extern_crate_name : InternedString :: new ( "std" ) ,
178- public : true ,
179- } ) ;
180- }
181- }
182- }
183- }
184-
185- /// Add libtest as a dependency of any test unit that needs it.
186- fn attach_std_test < ' a , ' cfg > (
187- state : & mut State < ' a , ' cfg > ,
188- mut libtest_unit_deps : UnitGraph < ' a > ,
189- std_unit_deps : & UnitGraph < ' a > ,
190- ) {
191- // Attach libtest to any test unit.
192- let ( test_unit, test_deps) = libtest_unit_deps
193- . iter_mut ( )
194- . find ( |( k, _v) | k. pkg . name ( ) . as_str ( ) == "test" && k. target . is_lib ( ) )
195- . expect ( "test in deps" ) ;
196- for ( unit, deps) in state. unit_dependencies . iter_mut ( ) {
197- if unit. mode . is_rustc_test ( ) && unit. target . harness ( ) {
198- // `public` here will need to be driven by toml declaration.
199- deps. push ( UnitDep {
200- unit : * test_unit,
201- unit_for : UnitFor :: new_normal ( ) ,
202- extern_crate_name : test_unit. pkg . name ( ) ,
203- public : false ,
204- } ) ;
205- }
206- }
207-
208- // Synthesize a dependency from libtest -> libc.
209- //
210- // This is a gross hack. In theory, libtest should explicitly list this,
211- // but presumably it would cause libc to be built again when it just uses
212- // the version from sysroot. This won't be necessary if Cargo uses
213- // `--sysroot`.
214- let libc_unit = std_unit_deps
215- . keys ( )
216- . find ( |unit| unit. pkg . name ( ) . as_str ( ) == "libc" && unit. target . is_lib ( ) )
217- . expect ( "libc in deps" ) ;
218- let libc_dep = UnitDep {
219- unit : * libc_unit,
220- unit_for : UnitFor :: new_normal ( ) ,
221- extern_crate_name : InternedString :: new ( & libc_unit. target . crate_name ( ) ) ,
222- public : false ,
223- } ;
224- test_deps. push ( libc_dep) ;
225-
226- // And also include the dependencies of libtest itself.
227- for ( unit, deps) in libtest_unit_deps. into_iter ( ) {
228- if let Some ( other_unit) = state. unit_dependencies . insert ( unit, deps) {
229- panic ! (
230- "libtest unit collision with existing unit: {:?}" ,
231- other_unit
232- ) ;
233- }
234- }
235- }
236-
237120/// Add the standard library units to the `unit_dependencies`.
238121fn attach_std_deps < ' a , ' cfg > (
239122 state : & mut State < ' a , ' cfg > ,
@@ -647,29 +530,7 @@ fn check_or_build_mode(mode: CompileMode, target: &Target) -> CompileMode {
647530 }
648531}
649532
650- fn new_unit < ' a > (
651- state : & State < ' a , ' _ > ,
652- pkg : & ' a Package ,
653- target : & ' a Target ,
654- unit_for : UnitFor ,
655- kind : Kind ,
656- mode : CompileMode ,
657- ) -> Unit < ' a > {
658- let profile = state. bcx . profiles . get_profile (
659- pkg. package_id ( ) ,
660- state. bcx . ws . is_member ( pkg) ,
661- unit_for,
662- mode,
663- state. bcx . build_config . release ,
664- ) ;
665-
666- let features = state. resolve ( ) . features_sorted ( pkg. package_id ( ) ) ;
667- state
668- . bcx
669- . units
670- . intern ( pkg, target, profile, kind, mode, features)
671- }
672-
533+ /// Create a new Unit for a dependency from `parent` to `pkg` and `target`.
673534fn new_unit_dep < ' a > (
674535 state : & State < ' a , ' _ > ,
675536 parent : & Unit < ' a > ,
0 commit comments