@@ -1294,7 +1294,7 @@ impl Build {
12941294
12951295 #[ cfg( feature = "parallel" ) ]
12961296 fn compile_objects ( & self , objs : & [ Object ] , print : & PrintThread ) -> Result < ( ) , Error > {
1297- use std:: sync:: { mpsc, Once } ;
1297+ use std:: sync:: mpsc;
12981298
12991299 if objs. len ( ) <= 1 {
13001300 for obj in objs {
@@ -1306,7 +1306,7 @@ impl Build {
13061306 }
13071307
13081308 // Limit our parallelism globally with a jobserver.
1309- let server = jobserver ( ) ;
1309+ let server = job_token :: jobserver ( ) ;
13101310 // Reacquire our process's token on drop
13111311
13121312 // When compiling objects in parallel we do a few dirty tricks to speed
@@ -1440,51 +1440,6 @@ impl Build {
14401440
14411441 return wait_thread. join ( ) . expect ( "wait_thread panics" ) ;
14421442
1443- /// Returns a suitable `jobserver::Client` used to coordinate
1444- /// parallelism between build scripts.
1445- fn jobserver ( ) -> jobserver:: Client {
1446- static INIT : Once = Once :: new ( ) ;
1447- static mut JOBSERVER : Option < jobserver:: Client > = None ;
1448-
1449- fn _assert_sync < T : Sync > ( ) { }
1450- _assert_sync :: < jobserver:: Client > ( ) ;
1451-
1452- unsafe {
1453- INIT . call_once ( || {
1454- let server = default_jobserver ( ) ;
1455- JOBSERVER = Some ( server) ;
1456- } ) ;
1457- JOBSERVER . clone ( ) . unwrap ( )
1458- }
1459- }
1460-
1461- unsafe fn default_jobserver ( ) -> jobserver:: Client {
1462- // Try to use the environmental jobserver which Cargo typically
1463- // initializes for us...
1464- if let Some ( client) = jobserver:: Client :: from_env ( ) {
1465- return client;
1466- }
1467-
1468- // ... but if that fails for whatever reason select something
1469- // reasonable and crate a new jobserver. Use `NUM_JOBS` if set (it's
1470- // configured by Cargo) and otherwise just fall back to a
1471- // semi-reasonable number. Note that we could use `num_cpus` here
1472- // but it's an extra dependency that will almost never be used, so
1473- // it's generally not too worth it.
1474- let mut parallelism = 4 ;
1475- if let Ok ( amt) = env:: var ( "NUM_JOBS" ) {
1476- if let Ok ( amt) = amt. parse ( ) {
1477- parallelism = amt;
1478- }
1479- }
1480-
1481- // If we create our own jobserver then be sure to reserve one token
1482- // for ourselves.
1483- let client = jobserver:: Client :: new ( parallelism) . expect ( "failed to create jobserver" ) ;
1484- client. acquire_raw ( ) . expect ( "failed to acquire initial" ) ;
1485- return client;
1486- }
1487-
14881443 struct KillOnDrop ( Child ) ;
14891444
14901445 impl Drop for KillOnDrop {
0 commit comments