@@ -36,8 +36,6 @@ use std::thread;
36
36
37
37
// Runs an in-process instance of Cargo.
38
38
pub ( super ) fn cargo ( internals : & Internals , package_arg : PackageArg , progress_sender : Sender < ProgressUpdate > ) -> BuildResult {
39
- let workspace_mode = internals. config . lock ( ) . unwrap ( ) . workspace_mode ;
40
-
41
39
let compilation_cx = internals. compilation_cx . clone ( ) ;
42
40
let config = internals. config . clone ( ) ;
43
41
let vfs = internals. vfs . clone ( ) ;
@@ -73,7 +71,7 @@ pub(super) fn cargo(internals: &Internals, package_arg: PackageArg, progress_sen
73
71
. map_err ( |_| failure:: err_msg ( "thread panicked" ) )
74
72
. and_then ( |res| res)
75
73
{
76
- Ok ( ref cwd) if workspace_mode => {
74
+ Ok ( ref cwd) => {
77
75
let diagnostics = Arc :: try_unwrap ( diagnostics_clone)
78
76
. unwrap ( )
79
77
. into_inner ( )
@@ -84,7 +82,6 @@ pub(super) fn cargo(internals: &Internals, package_arg: PackageArg, progress_sen
84
82
. unwrap ( ) ;
85
83
BuildResult :: Success ( cwd. clone ( ) , diagnostics, analysis, true )
86
84
}
87
- Ok ( cwd) => BuildResult :: Success ( cwd, vec ! [ ] , vec ! [ ] , true ) ,
88
85
Err ( err) => {
89
86
// This message goes like this to the UI via showMessage. In VSCode
90
87
// this ends up on one single line, so it's important to keep it concise.
@@ -164,22 +161,9 @@ fn run_cargo(
164
161
let rustflags = prepare_cargo_rustflags ( & rls_config) ;
165
162
166
163
167
- if rls_config. workspace_mode {
168
- for package in & packages {
169
- if ws. members ( ) . find ( |x| * x. name ( ) == * package) . is_none ( ) {
170
- warn ! ( "cargo - couldn't find member package `{}` specified in `analyze_package` configuration" , package) ;
171
- }
172
- }
173
- } else {
174
- // Warn about invalid specified bin target or package depending on current mode
175
- // TODO: Return client notifications along with diagnostics to inform the user
176
- let cur_pkg_targets = ws. current ( ) ?. targets ( ) ;
177
-
178
- if let Some ( ref build_bin) = * rls_config. build_bin . as_ref ( ) {
179
- let mut bins = cur_pkg_targets. iter ( ) . filter ( |x| x. is_bin ( ) ) ;
180
- if bins. find ( |x| x. name ( ) == build_bin) . is_none ( ) {
181
- warn ! ( "cargo - couldn't find binary `{}` specified in `build_bin` configuration" , build_bin) ;
182
- }
164
+ for package in & packages {
165
+ if ws. members ( ) . find ( |x| * x. name ( ) == * package) . is_none ( ) {
166
+ warn ! ( "cargo - couldn't find member package `{}` specified in `analyze_package` configuration" , package) ;
183
167
}
184
168
}
185
169
@@ -254,15 +238,13 @@ fn run_cargo(
254
238
255
239
struct RlsExecutor {
256
240
compilation_cx : Arc < Mutex < CompilationContext > > ,
257
- cur_package_id : Mutex < Option < PackageId > > ,
258
241
config : Arc < Mutex < Config > > ,
259
242
/// Because of the Cargo API design, we first acquire outer lock before creating the executor
260
243
/// and calling the compilation function. This, resulting, inner lock is used to synchronize
261
244
/// env var access during underlying `rustc()` calls during parallel `exec()` callback threads.
262
245
env_lock : environment:: InnerLock ,
263
246
vfs : Arc < Vfs > ,
264
247
analysis : Arc < Mutex < Vec < Analysis > > > ,
265
- workspace_mode : bool ,
266
248
/// Packages which are directly a member of the workspace, for which
267
249
/// analysis and diagnostics will be provided
268
250
member_packages : Mutex < HashSet < PackageId > > ,
@@ -282,26 +264,14 @@ impl RlsExecutor {
282
264
analysis : Arc < Mutex < Vec < Analysis > > > ,
283
265
progress_sender : Sender < ProgressUpdate > ,
284
266
) -> RlsExecutor {
285
- let workspace_mode = config. lock ( ) . unwrap ( ) . workspace_mode ;
286
- let ( cur_package_id, member_packages) = if workspace_mode {
287
- let member_packages = ws. members ( ) . map ( |x| x. package_id ( ) . clone ( ) ) . collect ( ) ;
288
- ( None , member_packages)
289
- } else {
290
- let pkg_id = ws. current_opt ( )
291
- . expect ( "No current package in Cargo" )
292
- . package_id ( )
293
- . clone ( ) ;
294
- ( Some ( pkg_id) , HashSet :: new ( ) )
295
- } ;
267
+ let member_packages = ws. members ( ) . map ( |x| x. package_id ( ) . clone ( ) ) . collect ( ) ;
296
268
297
269
RlsExecutor {
298
270
compilation_cx,
299
- cur_package_id : Mutex :: new ( cur_package_id) ,
300
271
config,
301
272
env_lock,
302
273
vfs,
303
274
analysis,
304
- workspace_mode,
305
275
member_packages : Mutex :: new ( member_packages) ,
306
276
compiler_messages,
307
277
progress_sender : Mutex :: new ( progress_sender) ,
@@ -311,15 +281,7 @@ impl RlsExecutor {
311
281
/// Returns whether a given package is a primary one (every member of the
312
282
/// workspace is considered as such).
313
283
fn is_primary_crate ( & self , id : & PackageId ) -> bool {
314
- if self . workspace_mode {
315
- self . member_packages . lock ( ) . unwrap ( ) . contains ( id)
316
- } else {
317
- let cur_package_id = self . cur_package_id . lock ( ) . unwrap ( ) ;
318
- id
319
- == cur_package_id
320
- . as_ref ( )
321
- . expect ( "Executor has not been initialized" )
322
- }
284
+ self . member_packages . lock ( ) . unwrap ( ) . contains ( id)
323
285
}
324
286
}
325
287
@@ -339,7 +301,7 @@ impl Executor for RlsExecutor {
339
301
}
340
302
341
303
fn force_rebuild ( & self , unit : & Unit ) -> bool {
342
- // In workspace_mode we need to force rebuild every package in the
304
+ // We need to force rebuild every package in the
343
305
// workspace, even if it's not dirty at a time, to cache compiler
344
306
// invocations in the build plan.
345
307
// We only do a cargo build if we want to force rebuild the last
@@ -463,46 +425,13 @@ impl Executor for RlsExecutor {
463
425
464
426
{
465
427
let config = self . config . lock ( ) . unwrap ( ) ;
466
- let crate_type = parse_arg ( cargo_args, "--crate-type" ) ;
467
- // Because we only try to emulate `cargo test` using `cargo check`, so for now
468
- // assume crate_type arg (i.e. in `cargo test` it isn't specified for --test targets)
469
- // and build test harness only for final crate type
470
- let crate_type = if config. all_targets || config. cfg_test {
471
- // Crate type may be undefined when `all_targets` is true, for example for integration tests
472
- crate_type. unwrap_or_else ( || "undefined" . to_owned ( ) )
473
- } else {
474
- // Panic if crate type undefined for other cases
475
- crate_type. expect ( "no crate-type in rustc command line" )
476
- } ;
477
- let build_lib = * config. build_lib . as_ref ( ) ;
478
- let is_final_crate_type = crate_type == "bin" || ( crate_type == "lib" && build_lib) ;
479
428
480
429
if config. sysroot . is_none ( ) {
481
430
args. push ( "--sysroot" . to_owned ( ) ) ;
482
431
args. push ( sysroot) ;
483
432
}
484
433
485
- // We can't omit compilation here, because Cargo is going to expect to get
486
- // dep-info for this crate, so we shell out to rustc to get that.
487
- // This is not really ideal, because we are going to
488
- // compute this info anyway when we run rustc ourselves, but we don't do
489
- // that before we return to Cargo.
490
- // FIXME Don't do this. Start our build here rather than on another thread
491
- // so the dep-info is ready by the time we return from this callback.
492
- // NB: In `workspace_mode` regular compilation is performed here (and we don't
493
- // only calculate dep-info) so it should fix the problem mentioned above.
494
- let modified = args. iter ( )
495
- . map ( |a| {
496
- // Emitting only dep-info is possible only for final crate type, as
497
- // as others may emit required metadata for dependent crate types
498
- if a. starts_with ( "--emit" ) && is_final_crate_type && !self . workspace_mode {
499
- "--emit=dep-info"
500
- } else {
501
- a
502
- }
503
- } )
504
- . collect :: < Vec < _ > > ( ) ;
505
- cmd. args_replace ( & modified) ;
434
+ cmd. args_replace ( & args) ;
506
435
}
507
436
508
437
// Cache executed command for the build plan
@@ -524,30 +453,26 @@ impl Executor for RlsExecutor {
524
453
compilation_cx. cwd = cargo_cmd. get_cwd ( ) . map ( |p| p. to_path_buf ( ) ) ;
525
454
}
526
455
527
- if self . workspace_mode {
528
- let build_dir = {
529
- let cx = self . compilation_cx . lock ( ) . unwrap ( ) ;
530
- cx. build_dir . clone ( ) . unwrap ( )
531
- } ;
456
+ let build_dir = {
457
+ let cx = self . compilation_cx . lock ( ) . unwrap ( ) ;
458
+ cx. build_dir . clone ( ) . unwrap ( )
459
+ } ;
532
460
533
- if let BuildResult :: Success ( _, mut messages, mut analysis, success) = super :: rustc:: rustc (
534
- & self . vfs ,
535
- & args,
536
- & envs,
537
- cargo_cmd. get_cwd ( ) ,
538
- & build_dir,
539
- Arc :: clone ( & self . config ) ,
540
- & self . env_lock . as_facade ( ) ,
541
- ) {
542
- self . compiler_messages . lock ( ) . unwrap ( ) . append ( & mut messages) ;
543
- self . analysis . lock ( ) . unwrap ( ) . append ( & mut analysis) ;
544
-
545
- if !success {
546
- return Err ( format_err ! ( "Build error" ) ) ;
547
- }
461
+ if let BuildResult :: Success ( _, mut messages, mut analysis, success) = super :: rustc:: rustc (
462
+ & self . vfs ,
463
+ & args,
464
+ & envs,
465
+ cargo_cmd. get_cwd ( ) ,
466
+ & build_dir,
467
+ Arc :: clone ( & self . config ) ,
468
+ & self . env_lock . as_facade ( ) ,
469
+ ) {
470
+ self . compiler_messages . lock ( ) . unwrap ( ) . append ( & mut messages) ;
471
+ self . analysis . lock ( ) . unwrap ( ) . append ( & mut analysis) ;
472
+
473
+ if !success {
474
+ return Err ( format_err ! ( "Build error" ) ) ;
548
475
}
549
- } else {
550
- cmd. exec ( ) ?;
551
476
}
552
477
553
478
Ok ( ( ) )
@@ -585,40 +510,14 @@ impl Default for CargoOptions {
585
510
586
511
impl CargoOptions {
587
512
fn new ( config : & Config ) -> CargoOptions {
588
- if config. workspace_mode {
589
- CargoOptions {
590
- target : config. target . clone ( ) ,
591
- features : config. features . clone ( ) ,
592
- all_features : config. all_features ,
593
- no_default_features : config. no_default_features ,
594
- jobs : config. jobs ,
595
- all_targets : config. all_targets ,
596
- ..CargoOptions :: default ( )
597
- }
598
- } else {
599
- // In single-crate mode we currently support only one crate target,
600
- // and if lib is set, then we ignore bin target config
601
- let ( lib, bin) = if * config. build_lib . as_ref ( ) {
602
- ( true , vec ! [ ] )
603
- } else {
604
- let bin = match * config. build_bin . as_ref ( ) {
605
- Some ( ref bin) => vec ! [ bin. clone( ) ] ,
606
- None => vec ! [ ] ,
607
- } ;
608
- ( false , bin)
609
- } ;
610
-
611
- CargoOptions {
612
- lib,
613
- bin,
614
- target : config. target . clone ( ) ,
615
- features : config. features . clone ( ) ,
616
- all_features : config. all_features ,
617
- no_default_features : config. no_default_features ,
618
- jobs : config. jobs ,
619
- all_targets : config. all_targets ,
620
- ..CargoOptions :: default ( )
621
- }
513
+ CargoOptions {
514
+ target : config. target . clone ( ) ,
515
+ features : config. features . clone ( ) ,
516
+ all_features : config. all_features ,
517
+ no_default_features : config. no_default_features ,
518
+ jobs : config. jobs ,
519
+ all_targets : config. all_targets ,
520
+ ..CargoOptions :: default ( )
622
521
}
623
522
}
624
523
}
0 commit comments