Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests, linkers, and specifications for various targets. #1028

Merged
merged 5 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .changes/1028.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"description": "link to libgcc for armv5te-unknown-linux-musleabi.",
"type": "fixed"
},
{
"description": "add C++ support for FreeBSD targets.",
"type": "added"
},
{
"description": "test dynamic library support for Android targets in CI.",
"type": "internal"
},
{
"description": "test partial C++ support for mips64el-unknown-linux-muslabi64 in CI.",
"type": "internal"
},
{
"description": "convert mips64el-unknown-linux-muslabi64 to a hard-float toolchain to match the rust target.",
"type": "changed",
"breaking": true
},
{
"description": "convert mips64el-unknown-linux-muslabi64 to use the mips64r2 architecture, identical to the rust target.",
"type": "changed",
"breaking": true
},
{
"description": "convert mips-unknown-linux-musl and mipsel-unknown-linux-musl to use the mips32r2 architecture, identical to the rust targets.",
"type": "changed",
"breaking": true
}
]
4 changes: 3 additions & 1 deletion docker/Dockerfile.armv5te-unknown-linux-musleabi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ RUN /musl-symlink.sh $CROSS_MUSL_SYSROOT arm

COPY qemu-runner base-runner.sh /

ENV CARGO_TARGET_ARMV5TE_UNKNOWN_LINUX_MUSLEABI_LINKER=arm-linux-musleabi-gcc \
COPY arm-linux-musleabi-gcc.sh /usr/bin/

ENV CARGO_TARGET_ARMV5TE_UNKNOWN_LINUX_MUSLEABI_LINKER=arm-linux-musleabi-gcc.sh \
CARGO_TARGET_ARMV5TE_UNKNOWN_LINUX_MUSLEABI_RUNNER="/qemu-runner arm" \
CC_armv5te_unknown_linux_musleabi=arm-linux-musleabi-gcc \
CXX_armv5te_unknown_linux_musleabi=arm-linux-musleabi-g++ \
Expand Down
4 changes: 3 additions & 1 deletion docker/Dockerfile.i686-unknown-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ COPY freebsd-install.sh /
COPY freebsd-extras.sh /
RUN /freebsd-extras.sh

ENV CARGO_TARGET_I686_UNKNOWN_FREEBSD_LINKER=i686-unknown-freebsd12-gcc \
COPY i686-unknown-freebsd12-gcc.sh /usr/bin

ENV CARGO_TARGET_I686_UNKNOWN_FREEBSD_LINKER=i686-unknown-freebsd12-gcc.sh \
CC_i686_unknown_freebsd=i686-unknown-freebsd12-gcc \
CXX_i686_unknown_freebsd=i686-unknown-freebsd12-g++ \
BINDGEN_EXTRA_CLANG_ARGS_i686_unknown_freebsd="--sysroot=/usr/local/i686-unknown-freebsd12" \
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile.mips-unknown-linux-musl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ RUN /xargo.sh
COPY qemu.sh /
RUN /qemu.sh mips

# this is a soft-float target for the mips32r2 architecture
# https://github.com/rust-lang/rust/blob/75d3027fb5ce1af6712e4503c9574802212101bd/compiler/rustc_target/src/spec/mips_unknown_linux_musl.rs#L7
COPY musl.sh /
RUN /musl.sh \
TARGET=mips-linux-muslsf \
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile.mips64-unknown-linux-muslabi64
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RUN /xargo.sh
COPY qemu.sh /
RUN /qemu.sh mips64

# this is a hard-float target for the mips64r2 architecture
# https://github.com/rust-lang/rust/blob/75d3027fb5ce1af6712e4503c9574802212101bd/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64.rs#L7
COPY musl.sh /
RUN /musl.sh \
TARGET=mips64-linux-musl \
Expand Down
22 changes: 15 additions & 7 deletions docker/Dockerfile.mips64el-unknown-linux-muslabi64
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ RUN /xargo.sh
COPY qemu.sh /
RUN /qemu.sh mips64el

# this is a hard-float target for the mips64r2 architecture
# https://github.com/rust-lang/rust/blob/75d3027fb5ce1af6712e4503c9574802212101bd/compiler/rustc_target/src/spec/mips64el_unknown_linux_muslabi64.rs#L6
COPY musl.sh /
RUN /musl.sh \
TARGET=mips64el-linux-muslsf \
"COMMON_CONFIG += -with-arch=mips64"
TARGET=mips64el-linux-musl \
"COMMON_CONFIG += -with-arch=mips64r2"

ENV CROSS_MUSL_SYSROOT=/usr/local/mips64el-linux-muslsf
ENV CROSS_MUSL_SYSROOT=/usr/local/mips64el-linux-musl
COPY musl-symlink.sh /
RUN /musl-symlink.sh $CROSS_MUSL_SYSROOT mips64el-sf
RUN /musl-symlink.sh $CROSS_MUSL_SYSROOT mips64el
RUN mkdir -p $CROSS_MUSL_SYSROOT/usr/lib64
# needed for the C/C++ runners
RUN ln -s $CROSS_MUSL_SYSROOT/usr/lib/libc.so $CROSS_MUSL_SYSROOT/usr/lib64/libc.so
RUN ln -s $CROSS_MUSL_SYSROOT/usr/lib/libc.so.1 $CROSS_MUSL_SYSROOT/usr/lib64/libc.so.1

COPY mips64el-linux-musl-gcc.sh /usr/bin/

COPY qemu-runner base-runner.sh /

ENV CARGO_TARGET_MIPS64EL_UNKNOWN_LINUX_MUSLABI64_LINKER=mips64el-linux-muslsf-gcc \
ENV CARGO_TARGET_MIPS64EL_UNKNOWN_LINUX_MUSLABI64_LINKER=mips64el-linux-musl-gcc.sh \
CARGO_TARGET_MIPS64EL_UNKNOWN_LINUX_MUSLABI64_RUNNER="/qemu-runner mips64el" \
CC_mips64el_unknown_linux_muslabi64=mips64el-linux-muslsf-gcc \
CXX_mips64el_unknown_linux_muslabi64=mips64el-linux-muslsf-g++ \
CC_mips64el_unknown_linux_muslabi64=mips64el-linux-musl-gcc \
CXX_mips64el_unknown_linux_muslabi64=mips64el-linux-musl-g++ \
Comment on lines -26 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @abcfy2

does this change work for you?
You can build the image with

cargo xtask build-docker-image mips64el-unknown-linux-muslabi64

this is a hard-float target according to rustc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be hard-float, we're just using a soft float toolchain which is bound to cause problems at some point. A quick test is:

$ cargo init --bin hello
$ cross build --target mips64el-unknown-linux-muslabi64
$ file target/mips64el-unknown-linux-muslabi64/debug/hello
target/mips64el-unknown-linux-muslabi64/debug/hello: ELF 64-bit LSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), statically linked, with debug_info, not stripped
$ readelf -A target/mips64el-unknown-linux-muslabi64/debug/hello | grep Tag_GNU_MIPS_ABI_FP
  Tag_GNU_MIPS_ABI_FP: Hard float (double precision)
$ docker run -it --rm ghcr.io/cross-rs/mips64el-unknown-linux-muslabi64:main bash
# still using the soft-float toolchain
$ echo $CROSS_MUSL_SYSROOT/
/usr/local/mips64el-linux-muslsf/

# show 32-bit is soft-float
$ cross build --target mipsel-unknown-linux-musl
$ file target/mipsel-unknown-linux-musl/debug/hello
target/mipsel-unknown-linux-musl/debug/hello: ELF 32-bit LSB pie executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mipsel-sf.so.1, with debug_info, not stripped
$ readelf -A target/mipsel-unknown-linux-musl/debug/hello | grep Tag_GNU_MIPS_ABI_FP
  Tag_GNU_MIPS_ABI_FP: Soft float

So we're linking a hard-float executable with a soft-float toolchain, which isn't exactly ideal, and bound to cause problems later down the line.

BINDGEN_EXTRA_CLANG_ARGS_mips64el_unknown_linux_muslabi64="--sysroot=$CROSS_MUSL_SYSROOT" \
QEMU_LD_PREFIX=$CROSS_MUSL_SYSROOT \
RUST_TEST_THREADS=1
4 changes: 3 additions & 1 deletion docker/Dockerfile.mipsel-unknown-linux-musl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ RUN /xargo.sh
COPY qemu.sh /
RUN /qemu.sh mipsel

# this is a soft-float target for the mips32r2 architecture
# https://github.com/rust-lang/rust/blob/75d3027fb5ce1af6712e4503c9574802212101bd/compiler/rustc_target/src/spec/mipsel_unknown_linux_musl.rs#L6
COPY musl.sh /
RUN /musl.sh \
TARGET=mipsel-linux-muslsf \
"COMMON_CONFIG += -with-arch=mips32"
"COMMON_CONFIG += -with-arch=mips32r2"

ENV CROSS_MUSL_SYSROOT=/usr/local/mipsel-linux-muslsf
COPY musl-symlink.sh /
Expand Down
4 changes: 3 additions & 1 deletion docker/Dockerfile.x86_64-unknown-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ COPY freebsd-install.sh /
COPY freebsd-extras.sh /
RUN /freebsd-extras.sh

ENV CARGO_TARGET_X86_64_UNKNOWN_FREEBSD_LINKER=x86_64-unknown-freebsd12-gcc \
COPY x86_64-unknown-freebsd12-gcc.sh /usr/bin

ENV CARGO_TARGET_X86_64_UNKNOWN_FREEBSD_LINKER=x86_64-unknown-freebsd12-gcc.sh \
CC_x86_64_unknown_freebsd=x86_64-unknown-freebsd12-gcc \
CXX_x86_64_unknown_freebsd=x86_64-unknown-freebsd12-g++ \
BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_freebsd="--sysroot=/usr/local/x86_64-unknown-freebsd12" \
Expand Down
8 changes: 1 addition & 7 deletions docker/aarch64-linux-musl-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ set -x
set -euo pipefail

main() {
local release=
release=$(rustc -Vv | grep '^release:' | cut -d ':' -f2)
# NOTE we assume `major` is always "1"
local minor=
minor=$(echo "$release" | cut -d '.' -f2)

if (( minor >= 48 )) || [[ $# -eq 0 ]]; then
if (( CROSS_RUSTC_MINOR_VERSION >= 48 )) || [[ $# -eq 0 ]]; then
# no workaround
exec aarch64-linux-musl-gcc "${@}"
else
Expand Down
4 changes: 2 additions & 2 deletions docker/arm-linux-musleabi-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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

set -x
set -euo pipefail

main() {
if [[ $# -eq 0 ]]; then
if (( CROSS_RUSTC_MINOR_VERSION >= 65 )) || [[ $# -eq 0 ]]; then
exec arm-linux-musleabi-gcc "${@}"
else
exec arm-linux-musleabi-gcc "${@}" -lgcc -static-libgcc
Expand Down
17 changes: 17 additions & 0 deletions docker/i686-unknown-freebsd12-gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# the freebsd images need libstdc++ to be linked as well
# otherwise, we get `undefined reference to `std::ios_base::Init::Init()'`

set -x
set -euo pipefail

main() {
if [[ $# -eq 0 ]]; then
exec i686-unknown-freebsd12-gcc "${@}"
else
exec i686-unknown-freebsd12-gcc "${@}" -lc++ -lstdc++
fi
}

main "${@}"
4 changes: 2 additions & 2 deletions docker/mips64-linux-musl-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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

set -x
set -euo pipefail

main() {
if [[ $# -eq 0 ]]; then
if (( CROSS_RUSTC_MINOR_VERSION >= 65 )) || [[ $# -eq 0 ]]; then
exec mips64-linux-musl-gcc "${@}"
else
exec mips64-linux-musl-gcc "${@}" -lgcc -static-libgcc
Expand Down
20 changes: 20 additions & 0 deletions docker/mips64el-linux-musl-gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# this linker wrapper works around the missing soft-fp routine __trunctfsf2
# this affects rust versions with compiler-builtins <= 0.1.77,
# which affects toolchains older than 1.65 which require the `-lgcc`
# linker flag to provide the missing builtin.
# https://github.com/rust-lang/compiler-builtins/pull/483

set -x
set -euo pipefail

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

main "${@}"
17 changes: 17 additions & 0 deletions docker/x86_64-unknown-freebsd12-gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# the freebsd images need libstdc++ to be linked as well
# otherwise, we get `undefined reference to `std::ios_base::Init::Init()'`

set -x
set -euo pipefail

main() {
if [[ $# -eq 0 ]]; then
exec x86_64-unknown-freebsd12-gcc "${@}"
else
exec x86_64-unknown-freebsd12-gcc "${@}" -lc++ -lstdc++
fi
}

main "${@}"
9 changes: 1 addition & 8 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ pub(crate) fn run(
.image
.platform
.specify_platform(&options.engine, &mut docker);
docker_envvars(
&mut docker,
&options.config,
dirs,
&options.target,
options.cargo_variant,
msg_info,
)?;
docker_envvars(&mut docker, &options, dirs, msg_info)?;

docker_mount(
&mut docker,
Expand Down
9 changes: 1 addition & 8 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,14 +1209,7 @@ symlink_recurse \"${{prefix}}\"
// 6. execute our cargo command inside the container
let mut docker = subcommand(engine, "exec");
docker_user_id(&mut docker, engine.kind);
docker_envvars(
&mut docker,
&options.config,
dirs,
target,
options.cargo_variant,
msg_info,
)?;
docker_envvars(&mut docker, &options, dirs, msg_info)?;
docker_cwd(&mut docker, &paths)?;
docker.arg(&container);
docker.args(["sh", "-c", &build_command(dirs, &cmd)]);
Expand Down
32 changes: 26 additions & 6 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::rustc::QualifiedToolchain;
use crate::shell::{MessageInfo, Verbosity};
use crate::{CargoVariant, Target};

use rustc_version::Version as RustcVersion;

pub use super::custom::CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX;

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

impl DockerOptions {
Expand All @@ -46,13 +50,15 @@ impl DockerOptions {
config: Config,
image: Image,
cargo_variant: CargoVariant,
rustc_version: Option<RustcVersion>,
) -> DockerOptions {
DockerOptions {
engine,
target,
config,
image,
cargo_variant,
rustc_version,
}
}

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

pub(crate) fn docker_envvars(
docker: &mut Command,
config: &Config,
options: &DockerOptions,
dirs: &Directories,
target: &Target,
cargo_variant: CargoVariant,
msg_info: &mut MessageInfo,
) -> Result<()> {
for ref var in config.env_passthrough(target)?.unwrap_or_default() {
for ref var in options
.config
.env_passthrough(&options.target)?
.unwrap_or_default()
{
validate_env_var(var)?;

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

let runner = config.runner(target)?;
let runner = options.config.runner(&options.target)?;
let cross_runner = format!("CROSS_RUNNER={}", runner.unwrap_or_default());
docker
.args(["-e", "PKG_CONFIG_ALLOW_CROSS=1"])
.args(["-e", &format!("XARGO_HOME={}", dirs.xargo_mount_path())])
.args(["-e", &format!("CARGO_HOME={}", dirs.cargo_mount_path())])
.args(["-e", "CARGO_TARGET_DIR=/target"])
.args(["-e", &cross_runner]);
if cargo_variant.uses_zig() {
if options.cargo_variant.uses_zig() {
// otherwise, zig has a permission error trying to create the cache
docker.args(["-e", "XDG_CACHE_HOME=/target/.zig-cache"]);
}
Expand Down Expand Up @@ -564,6 +572,18 @@ pub(crate) fn docker_envvars(
docker.args(&parse_docker_opts(&value)?);
};

let (major, minor, patch) = match options.rustc_version.as_ref() {
Some(version) => (version.major, version.minor, version.patch),
// no toolchain version available, always provide the oldest
// compiler available. this isn't a major issue because
// linking will libgcc will not include symbols found in
// the builtins.
None => (1, 0, 0),
};
docker.args(["-e", &format!("CROSS_RUSTC_MAJOR_VERSION={}", major)]);
docker.args(["-e", &format!("CROSS_RUSTC_MINOR_VERSION={}", minor)]);
docker.args(["-e", &format!("CROSS_RUSTC_PATCH_VERSION={}", patch)]);

Ok(())
}

Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,19 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
}
};

if let Some((rustc_version, channel, rustc_commit)) = toolchain.rustc_version()? {
let mut rustc_version = None;
if let Some((version, channel, commit)) = toolchain.rustc_version()? {
if toolchain.date.is_none() {
warn_host_version_mismatch(
&host_version_meta,
&toolchain,
&rustc_version,
&rustc_commit,
&version,
&commit,
msg_info,
)?;
}
is_nightly = channel == Channel::Nightly;
rustc_version = Some(version);
}

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