21
21
/* Target (platform) data for conditional dependencies.
22
22
This corresponds roughly to what buildRustCrate is setting.
23
23
*/
24
- makeDefaultTarget = platform : {
24
+ makeDefaultTargetSpec = platform : {
25
25
unix = platform . isUnix ;
26
26
windows = platform . isWindows ;
27
27
fuchsia = true ;
@@ -241,20 +241,21 @@ rec {
241
241
, crateConfigs ? crates
242
242
, buildRustCrateForPkgsFunc
243
243
, runTests
244
- , makeTarget ? makeDefaultTarget
244
+ , makeTargetSpec ? makeDefaultTargetSpec
245
245
} @ args :
246
246
assert ( builtins . isAttrs crateConfigs ) ;
247
247
assert ( builtins . isString packageId ) ;
248
248
assert ( builtins . isList features ) ;
249
- assert ( builtins . isAttrs ( makeTarget stdenv . hostPlatform ) ) ;
249
+ assert ( builtins . isAttrs ( makeTargetSpec stdenv . hostPlatform ) ) ;
250
250
assert ( builtins . isBool runTests ) ;
251
251
let
252
252
rootPackageId = packageId ;
253
253
mergedFeatures = mergePackageFeatures
254
254
(
255
255
args // {
256
256
inherit rootPackageId ;
257
- target = makeTarget stdenv . hostPlatform // { test = runTests ; } ;
257
+ target = stdenv . hostPlatform . rust . rustcTarget ;
258
+ targetSpec = makeTargetSpec stdenv . hostPlatform // { test = runTests ; } ;
258
259
}
259
260
) ;
260
261
# Memoize built packages so that reappearing packages are only built once.
@@ -263,7 +264,8 @@ rec {
263
264
let
264
265
self = {
265
266
crates = lib . mapAttrs ( packageId : value : buildByPackageIdForPkgsImpl self pkgs packageId ) crateConfigs ;
266
- target = makeTarget stdenv . hostPlatform ;
267
+ target = pkgs . stdenv . hostPlatform . rust . rustcTarget ;
268
+ targetSpec = makeTargetSpec pkgs . stdenv . hostPlatform ;
267
269
build = mkBuiltByPackageIdByPkgs pkgs . buildPackages ;
268
270
} ;
269
271
in
@@ -281,7 +283,7 @@ rec {
281
283
dependencies =
282
284
dependencyDerivations {
283
285
inherit features ;
284
- inherit ( self ) target ;
286
+ inherit ( self ) target targetSpec ;
285
287
buildByPackageId = depPackageId :
286
288
# proc_macro crates must be compiled for the build architecture
287
289
if crateConfigs . ${ depPackageId } . procMacro or false
@@ -294,7 +296,7 @@ rec {
294
296
buildDependencies =
295
297
dependencyDerivations {
296
298
inherit features ;
297
- inherit ( self . build ) target ;
299
+ inherit ( self . build ) target targetSpec ;
298
300
buildByPackageId = depPackageId :
299
301
self . build . crates . ${ depPackageId } ;
300
302
dependencies = crateConfig . buildDependencies or [ ] ;
@@ -303,12 +305,12 @@ rec {
303
305
let
304
306
buildDeps = filterEnabledDependencies {
305
307
inherit features ;
306
- inherit ( self ) target ;
308
+ inherit ( self ) target targetSpec ;
307
309
dependencies = crateConfig . dependencies or [ ] ++ devDependencies ;
308
310
} ;
309
311
hostDeps = filterEnabledDependencies {
310
312
inherit features ;
311
- inherit ( self . build ) target ;
313
+ inherit ( self . build ) target targetSpec ;
312
314
dependencies = crateConfig . buildDependencies or [ ] ;
313
315
} ;
314
316
in
@@ -362,13 +364,14 @@ rec {
362
364
, features
363
365
, dependencies
364
366
, target
367
+ , targetSpec
365
368
} :
366
369
assert ( builtins . isList features ) ;
367
370
assert ( builtins . isList dependencies ) ;
368
- assert ( builtins . isAttrs target ) ;
371
+ assert ( builtins . isAttrs targetSpec ) ;
369
372
let
370
373
enabledDependencies = filterEnabledDependencies {
371
- inherit dependencies features target ;
374
+ inherit dependencies features target targetSpec ;
372
375
} ;
373
376
depDerivation = dependency : buildByPackageId dependency . packageId ;
374
377
in
@@ -387,7 +390,7 @@ rec {
387
390
else val ;
388
391
389
392
/* Returns various tools to debug a crate. */
390
- debugCrate = { packageId , target ? makeDefaultTarget stdenv . hostPlatform } :
393
+ debugCrate = { packageId , target ? stdenv . hostPlatform . rust . rustcTarget , targetSpec ? makeDefaultTargetSpec stdenv . hostPlatform } :
391
394
assert ( builtins . isString packageId ) ;
392
395
let
393
396
debug = rec {
@@ -410,10 +413,10 @@ rec {
410
413
) ;
411
414
mergedPackageFeatures = mergePackageFeatures {
412
415
features = rootFeatures ;
413
- inherit packageId target ;
416
+ inherit packageId target targetSpec ;
414
417
} ;
415
418
diffedDefaultPackageFeatures = diffDefaultPackageFeatures {
416
- inherit packageId target ;
419
+ inherit packageId target targetSpec ;
417
420
} ;
418
421
} ;
419
422
in
@@ -428,14 +431,15 @@ rec {
428
431
{ crateConfigs ? crates
429
432
, packageId
430
433
, target
434
+ , targetSpec
431
435
} :
432
436
assert ( builtins . isAttrs crateConfigs ) ;
433
437
let
434
438
prefixValues = prefix : lib . mapAttrs ( n : v : { "${ prefix } " = v ; } ) ;
435
439
mergedFeatures =
436
440
prefixValues
437
441
"crate2nix"
438
- ( mergePackageFeatures { inherit crateConfigs packageId target ; features = [ "default" ] ; } ) ;
442
+ ( mergePackageFeatures { inherit crateConfigs packageId target targetSpec ; features = [ "default" ] ; } ) ;
439
443
configs = prefixValues "cargo" crateConfigs ;
440
444
combined = lib . foldAttrs ( a : b : a // b ) { } [ mergedFeatures configs ] ;
441
445
onlyInCargo =
@@ -470,6 +474,7 @@ rec {
470
474
, dependencyPath ? [ crates . ${ packageId } . crateName ]
471
475
, featuresByPackageId ? { }
472
476
, target
477
+ , targetSpec
473
478
# Adds devDependencies to the crate with rootPackageId.
474
479
, runTests ? false
475
480
, ...
@@ -480,7 +485,7 @@ rec {
480
485
assert ( builtins . isList features ) ;
481
486
assert ( builtins . isList dependencyPath ) ;
482
487
assert ( builtins . isAttrs featuresByPackageId ) ;
483
- assert ( builtins . isAttrs target ) ;
488
+ assert ( builtins . isAttrs targetSpec ) ;
484
489
assert ( builtins . isBool runTests ) ;
485
490
let
486
491
crateConfig = crateConfigs . "${ packageId } " or ( builtins . throw "Package not found: ${ packageId } " ) ;
@@ -497,7 +502,7 @@ rec {
497
502
assert ( builtins . isList dependencies ) ;
498
503
let
499
504
enabledDependencies = filterEnabledDependencies {
500
- inherit dependencies target ;
505
+ inherit dependencies target targetSpec ;
501
506
features = enabledFeatures ;
502
507
} ;
503
508
directDependencies = map depWithResolvedFeatures enabledDependencies ;
@@ -516,7 +521,7 @@ rec {
516
521
mergePackageFeatures {
517
522
features = combinedFeatures ;
518
523
featuresByPackageId = cache ;
519
- inherit crateConfigs packageId target runTests rootPackageId ;
524
+ inherit crateConfigs packageId target targetSpec runTests rootPackageId ;
520
525
}
521
526
) ;
522
527
cacheWithSelf =
@@ -543,18 +548,19 @@ rec {
543
548
cacheWithAll ;
544
549
545
550
/* Returns the enabled dependencies given the enabled features. */
546
- filterEnabledDependencies = { dependencies , features , target } :
551
+ filterEnabledDependencies = { dependencies , features , target , targetSpec } :
547
552
assert ( builtins . isList dependencies ) ;
548
553
assert ( builtins . isList features ) ;
549
- assert ( builtins . isAttrs target ) ;
554
+ assert ( builtins . isString target ) ;
555
+ assert ( builtins . isAttrs targetSpec ) ;
550
556
551
557
lib . filter
552
558
(
553
559
dep :
554
560
let
555
561
targetFunc = dep . target or ( features : true ) ;
556
562
in
557
- targetFunc { inherit features target ; }
563
+ targetFunc { inherit features target targetSpec ; }
558
564
&& (
559
565
! ( dep . optional or false )
560
566
|| builtins . any ( doesFeatureEnableDependency dep ) features
0 commit comments