Skip to content

Commit 9311417

Browse files
committed
Add rustc versions to docker environment variables.
1 parent 187b691 commit 9311417

File tree

8 files changed

+41
-38
lines changed

8 files changed

+41
-38
lines changed

docker/aarch64-linux-musl-gcc.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ set -x
88
set -euo pipefail
99

1010
main() {
11-
local release=
12-
release=$(rustc -Vv | grep '^release:' | cut -d ':' -f2)
13-
# NOTE we assume `major` is always "1"
14-
local minor=
15-
minor=$(echo "$release" | cut -d '.' -f2)
16-
17-
if (( minor >= 48 )) || [[ $# -eq 0 ]]; then
11+
if (( CROSS_RUSTC_MINOR_VERSION >= 48 )) || [[ $# -eq 0 ]]; then
1812
# no workaround
1913
exec aarch64-linux-musl-gcc "${@}"
2014
else

docker/arm-linux-musleabi-gcc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
# this linker wrapper works around the missing sync `sync_X_and_fetch`
44
# routines. this affects rust versions with compiler-builtins <= 0.1.77,
5-
# which has not yet been merged into stable. this requires the `-lgcc`
5+
# which affects toolchains older than 1.65 which require the `-lgcc`
66
# linker flag to provide the missing builtin.
77
# https://github.com/rust-lang/compiler-builtins/pull/484
88

99
set -x
1010
set -euo pipefail
1111

1212
main() {
13-
if [[ $# -eq 0 ]]; then
13+
if (( CROSS_RUSTC_MINOR_VERSION >= 65 )) || [[ $# -eq 0 ]]; then
1414
exec arm-linux-musleabi-gcc "${@}"
1515
else
1616
exec arm-linux-musleabi-gcc "${@}" -lgcc -static-libgcc

docker/mips64-linux-musl-gcc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
# this linker wrapper works around the missing soft-fp routine __trunctfsf2
44
# this affects rust versions with compiler-builtins <= 0.1.77,
5-
# which has not yet been merged into stable. this requires the `-lgcc`
5+
# which affects toolchains older than 1.65 which require the `-lgcc`
66
# linker flag to provide the missing builtin.
77
# https://github.com/rust-lang/compiler-builtins/pull/483
88

99
set -x
1010
set -euo pipefail
1111

1212
main() {
13-
if [[ $# -eq 0 ]]; then
13+
if (( CROSS_RUSTC_MINOR_VERSION >= 65 )) || [[ $# -eq 0 ]]; then
1414
exec mips64-linux-musl-gcc "${@}"
1515
else
1616
exec mips64-linux-musl-gcc "${@}" -lgcc -static-libgcc

docker/mips64el-linux-musl-gcc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
# this linker wrapper works around the missing soft-fp routine __trunctfsf2
44
# this affects rust versions with compiler-builtins <= 0.1.77,
5-
# which has not yet been merged into stable. this requires the `-lgcc`
5+
# which affects toolchains older than 1.65 which require the `-lgcc`
66
# linker flag to provide the missing builtin.
77
# https://github.com/rust-lang/compiler-builtins/pull/483
88

99
set -x
1010
set -euo pipefail
1111

1212
main() {
13-
if [[ $# -eq 0 ]]; then
13+
if (( CROSS_RUSTC_MINOR_VERSION >= 65 )) || [[ $# -eq 0 ]]; then
1414
exec mips64el-linux-musl-gcc "${@}"
1515
else
1616
exec mips64el-linux-musl-gcc "${@}" -lgcc -static-libgcc

src/docker/local.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ pub(crate) fn run(
3838
.image
3939
.platform
4040
.specify_platform(&options.engine, &mut docker);
41-
docker_envvars(
42-
&mut docker,
43-
&options.config,
44-
dirs,
45-
&options.target,
46-
options.cargo_variant,
47-
msg_info,
48-
)?;
41+
docker_envvars(&mut docker, &options, dirs, msg_info)?;
4942

5043
docker_mount(
5144
&mut docker,

src/docker/remote.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,14 +1209,7 @@ symlink_recurse \"${{prefix}}\"
12091209
// 6. execute our cargo command inside the container
12101210
let mut docker = subcommand(engine, "exec");
12111211
docker_user_id(&mut docker, engine.kind);
1212-
docker_envvars(
1213-
&mut docker,
1214-
&options.config,
1215-
dirs,
1216-
target,
1217-
options.cargo_variant,
1218-
msg_info,
1219-
)?;
1212+
docker_envvars(&mut docker, &options, dirs, msg_info)?;
12201213
docker_cwd(&mut docker, &paths)?;
12211214
docker.arg(&container);
12221215
docker.args(["sh", "-c", &build_command(dirs, &cmd)]);

src/docker/shared.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use crate::rustc::QualifiedToolchain;
1818
use crate::shell::{MessageInfo, Verbosity};
1919
use crate::{CargoVariant, Target};
2020

21+
use rustc_version::Version as RustcVersion;
22+
2123
pub use super::custom::CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX;
2224

2325
pub const CROSS_IMAGE: &str = "ghcr.io/cross-rs";
@@ -37,6 +39,8 @@ pub struct DockerOptions {
3739
pub config: Config,
3840
pub image: Image,
3941
pub cargo_variant: CargoVariant,
42+
// not all toolchains will provide this
43+
pub rustc_version: Option<RustcVersion>,
4044
}
4145

4246
impl DockerOptions {
@@ -46,13 +50,15 @@ impl DockerOptions {
4650
config: Config,
4751
image: Image,
4852
cargo_variant: CargoVariant,
53+
rustc_version: Option<RustcVersion>,
4954
) -> DockerOptions {
5055
DockerOptions {
5156
engine,
5257
target,
5358
config,
5459
image,
5560
cargo_variant,
61+
rustc_version,
5662
}
5763
}
5864

@@ -514,29 +520,31 @@ fn add_cargo_configuration_envvars(docker: &mut Command) {
514520

515521
pub(crate) fn docker_envvars(
516522
docker: &mut Command,
517-
config: &Config,
523+
options: &DockerOptions,
518524
dirs: &Directories,
519-
target: &Target,
520-
cargo_variant: CargoVariant,
521525
msg_info: &mut MessageInfo,
522526
) -> 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+
{
524532
validate_env_var(var)?;
525533

526534
// Only specifying the environment variable name in the "-e"
527535
// flag forwards the value from the parent shell
528536
docker.args(["-e", var]);
529537
}
530538

531-
let runner = config.runner(target)?;
539+
let runner = options.config.runner(&options.target)?;
532540
let cross_runner = format!("CROSS_RUNNER={}", runner.unwrap_or_default());
533541
docker
534542
.args(["-e", "PKG_CONFIG_ALLOW_CROSS=1"])
535543
.args(["-e", &format!("XARGO_HOME={}", dirs.xargo_mount_path())])
536544
.args(["-e", &format!("CARGO_HOME={}", dirs.cargo_mount_path())])
537545
.args(["-e", "CARGO_TARGET_DIR=/target"])
538546
.args(["-e", &cross_runner]);
539-
if cargo_variant.uses_zig() {
547+
if options.cargo_variant.uses_zig() {
540548
// otherwise, zig has a permission error trying to create the cache
541549
docker.args(["-e", "XDG_CACHE_HOME=/target/.zig-cache"]);
542550
}
@@ -564,6 +572,18 @@ pub(crate) fn docker_envvars(
564572
docker.args(&parse_docker_opts(&value)?);
565573
};
566574

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+
567587
Ok(())
568588
}
569589

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,19 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
595595
}
596596
};
597597

598-
if let Some((rustc_version, channel, rustc_commit)) = toolchain.rustc_version()? {
598+
let mut rustc_version = None;
599+
if let Some((version, channel, commit)) = toolchain.rustc_version()? {
599600
if toolchain.date.is_none() {
600601
warn_host_version_mismatch(
601602
&host_version_meta,
602603
&toolchain,
603-
&rustc_version,
604-
&rustc_commit,
604+
&version,
605+
&commit,
605606
msg_info,
606607
)?;
607608
}
608609
is_nightly = channel == Channel::Nightly;
610+
rustc_version = Some(version);
609611
}
610612

611613
let uses_build_std = config.build_std(&target).unwrap_or(false);
@@ -711,6 +713,7 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
711713
config,
712714
image,
713715
cargo_variant,
716+
rustc_version,
714717
);
715718
let status = docker::run(options, paths, &filtered_args, msg_info)
716719
.wrap_err("could not run container")?;

0 commit comments

Comments
 (0)