@@ -18,6 +18,8 @@ use crate::rustc::QualifiedToolchain;
18
18
use crate :: shell:: { MessageInfo , Verbosity } ;
19
19
use crate :: { CargoVariant , Target } ;
20
20
21
+ use rustc_version:: Version as RustcVersion ;
22
+
21
23
pub use super :: custom:: CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX ;
22
24
23
25
pub const CROSS_IMAGE : & str = "ghcr.io/cross-rs" ;
@@ -37,6 +39,8 @@ pub struct DockerOptions {
37
39
pub config : Config ,
38
40
pub image : Image ,
39
41
pub cargo_variant : CargoVariant ,
42
+ // not all toolchains will provide this
43
+ pub rustc_version : Option < RustcVersion > ,
40
44
}
41
45
42
46
impl DockerOptions {
@@ -46,13 +50,15 @@ impl DockerOptions {
46
50
config : Config ,
47
51
image : Image ,
48
52
cargo_variant : CargoVariant ,
53
+ rustc_version : Option < RustcVersion > ,
49
54
) -> DockerOptions {
50
55
DockerOptions {
51
56
engine,
52
57
target,
53
58
config,
54
59
image,
55
60
cargo_variant,
61
+ rustc_version,
56
62
}
57
63
}
58
64
@@ -514,29 +520,31 @@ fn add_cargo_configuration_envvars(docker: &mut Command) {
514
520
515
521
pub ( crate ) fn docker_envvars (
516
522
docker : & mut Command ,
517
- config : & Config ,
523
+ options : & DockerOptions ,
518
524
dirs : & Directories ,
519
- target : & Target ,
520
- cargo_variant : CargoVariant ,
521
525
msg_info : & mut MessageInfo ,
522
526
) -> Result < ( ) > {
523
- for ref var in config. env_passthrough ( target) ?. unwrap_or_default ( ) {
527
+ for ref var in options
528
+ . config
529
+ . env_passthrough ( & options. target ) ?
530
+ . unwrap_or_default ( )
531
+ {
524
532
validate_env_var ( var) ?;
525
533
526
534
// Only specifying the environment variable name in the "-e"
527
535
// flag forwards the value from the parent shell
528
536
docker. args ( [ "-e" , var] ) ;
529
537
}
530
538
531
- let runner = config. runner ( target) ?;
539
+ let runner = options . config . runner ( & options . target ) ?;
532
540
let cross_runner = format ! ( "CROSS_RUNNER={}" , runner. unwrap_or_default( ) ) ;
533
541
docker
534
542
. args ( [ "-e" , "PKG_CONFIG_ALLOW_CROSS=1" ] )
535
543
. args ( [ "-e" , & format ! ( "XARGO_HOME={}" , dirs. xargo_mount_path( ) ) ] )
536
544
. args ( [ "-e" , & format ! ( "CARGO_HOME={}" , dirs. cargo_mount_path( ) ) ] )
537
545
. args ( [ "-e" , "CARGO_TARGET_DIR=/target" ] )
538
546
. args ( [ "-e" , & cross_runner] ) ;
539
- if cargo_variant. uses_zig ( ) {
547
+ if options . cargo_variant . uses_zig ( ) {
540
548
// otherwise, zig has a permission error trying to create the cache
541
549
docker. args ( [ "-e" , "XDG_CACHE_HOME=/target/.zig-cache" ] ) ;
542
550
}
@@ -564,6 +572,18 @@ pub(crate) fn docker_envvars(
564
572
docker. args ( & parse_docker_opts ( & value) ?) ;
565
573
} ;
566
574
575
+ let ( major, minor, patch) = match options. rustc_version . as_ref ( ) {
576
+ Some ( version) => ( version. major , version. minor , version. patch ) ,
577
+ // no toolchain version available, always provide older
578
+ // compiler available. this isn't a major issue because
579
+ // linking will libgcc will not include symbols found in
580
+ // the builtins.
581
+ None => ( 1 , 0 , 0 ) ,
582
+ } ;
583
+ docker. args ( [ "-e" , & format ! ( "CROSS_RUSTC_MAJOR_VERSION={}" , major) ] ) ;
584
+ docker. args ( [ "-e" , & format ! ( "CROSS_RUSTC_MINOR_VERSION={}" , minor) ] ) ;
585
+ docker. args ( [ "-e" , & format ! ( "CROSS_RUSTC_PATCH_VERSION={}" , patch) ] ) ;
586
+
567
587
Ok ( ( ) )
568
588
}
569
589
0 commit comments