Skip to content

Commit

Permalink
Support sparc-unknown-linux-gnu
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 22, 2023
1 parent 43a348c commit ea9aca6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- riscv32gc-unknown-linux-gnu # tier3
- riscv64gc-unknown-linux-gnu
- s390x-unknown-linux-gnu
# - sparc-unknown-linux-gnu # tier3, supported in rust-cross-toolchain but not ported to this action
- sparc-unknown-linux-gnu # tier3
- sparc64-unknown-linux-gnu
- thumbv7neon-unknown-linux-gnueabihf
- x86_64-unknown-linux-gnu
Expand Down Expand Up @@ -217,6 +217,7 @@ jobs:
- { target: mipsisa32r6-unknown-linux-gnu, os: ubuntu-20.04 }
- { target: mipsisa64r6-unknown-linux-gnuabi64, os: ubuntu-20.04 }
- { target: powerpc64-unknown-linux-gnu, os: ubuntu-20.04 }
- { target: sparc-unknown-linux-gnu, os: ubuntu-20.04 }
- { target: sparc64-unknown-linux-gnu, os: ubuntu-20.04 }
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
timeout-minutes: 60
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
## [Unreleased]

- Support i686-pc-windows-gnullvm.
- Support sparc-unknown-linux-gnu (experimental).

## [1.17.0] - 2023-08-24

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
| `riscv32gc-unknown-linux-gnu` | Ubuntu (20.04, 18.04, 22.04) [5] | qemu-user | |
| `riscv64gc-unknown-linux-gnu` | ubuntu (<!-- 20.04 [1], 18.04 [2], -->22.04 [3]) | qemu-user | |
| `s390x-unknown-linux-gnu` | Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) | qemu-user | |
| `sparc-unknown-linux-gnu` | Ubuntu (<!-- 20.04 [1], -->18.04 [2], 22.04 [3]) | qemu-user | tier3, experimental |
| `sparc64-unknown-linux-gnu` | Ubuntu (<!-- 20.04 [1], -->18.04 [2], 22.04 [3]) | qemu-user | |
| `thumbv7neon-unknown-linux-gnueabihf` | Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) | qemu-user | |
| `x86_64-unknown-linux-gnu` | Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) | native (default), qemu-user | |
Expand Down
47 changes: 41 additions & 6 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,14 @@ setup_linux_host() {
# https://github.com/taiki-e/rust-cross-toolchain/blob/a92f4cc85408460235b024933451f0350e08b726/docker/linux-gnu.sh#L55
bail "target '${target}' not yet supported; consider using armv7-unknown-linux-gnueabihf for testing armhf or arm-unknown-linux-gnueabi for testing armv6"
;;
sparc-unknown-linux-gnu)
# (tier3) Setup is tricky.
# https://github.com/taiki-e/rust-cross-toolchain/blob/a92f4cc85408460235b024933451f0350e08b726/docker/linux-gnu.Dockerfile#L44
bail "target '${target}' not yet supported"
;;
*)
case "${target}" in
arm*hf | thumbv7neon-*) cc_target=arm-linux-gnueabihf ;;
arm*) cc_target=arm-linux-gnueabi ;;
riscv32gc-* | riscv64gc-*) cc_target="${target/gc-unknown/}" ;;
sparc-*)
# Toolchain for sparc-linux-gnu is not available in APT,
# but we can use -m32 with sparc64-linux-gnu multilib.
cc_target=sparc-linux-gnu
apt_target=sparc64-linux-gnu
multilib=1
Expand All @@ -319,10 +316,23 @@ setup_linux_host() {
apt_packages+=("g++-${multilib:+multilib-}${apt_target/_/-}")
# https://github.com/taiki-e/rust-cross-toolchain/blob/fcb7a7e6ca14333d93c528f34a1def5a38745b3a/docker/test/entrypoint.sh
sysroot_dir="/usr/${apt_target}"
cat >>"${GITHUB_ENV}" <<EOF
case "${target}" in
sparc-*)
cat >>"${GITHUB_ENV}" <<EOF
CARGO_TARGET_${target_upper}_LINKER=${target}-gcc
CC_${target_lower}=${target}-gcc
CXX_${target_lower}=${target}-g++
EOF
;;
*)
cat >>"${GITHUB_ENV}" <<EOF
CARGO_TARGET_${target_upper}_LINKER=${apt_target}-gcc
CC_${target_lower}=${apt_target}-gcc
CXX_${target_lower}=${apt_target}-g++
EOF
;;
esac
cat >>"${GITHUB_ENV}" <<EOF
AR_${target_lower}=${apt_target}-ar
RANLIB_${target_lower}=${apt_target}-ranlib
STRIP=${apt_target}-strip
Expand Down Expand Up @@ -657,6 +667,31 @@ EOF
fi

install_apt_packages

case "${target}" in
sparc-unknown-linux-gnu)
# https://github.com/taiki-e/rust-cross-toolchain/blob/a92f4cc85408460235b024933451f0350e08b726/docker/linux-gnu.Dockerfile#L44
# The interpreter for sparc-linux-gnu is /lib/ld-linux.so.2,
# so lib/ld-linux.so.2 must be target sparc-linux-gnu to run binaries on qemu-user.
toolchain_dir=/usr
sudo rm -rf "${toolchain_dir:?}/${apt_target}/lib"
sudo rm -rf "${toolchain_dir:?}/${apt_target}/lib64"
sudo ln -s lib32 "${toolchain_dir}/${apt_target}/lib"
gcc_version="$(gcc --version | sed -n '1 s/^.*) //p')"
common_flags="-m32 -mv8plus -L${toolchain_dir}/${apt_target}/lib32 -L${toolchain_dir}/${apt_target}/lib/gcc-cross/${apt_target}/${gcc_version}/32"
cat >"/usr/local/bin/${target}-gcc" <<EOF2
#!/bin/sh
set -eu
exec ${toolchain_dir}/bin/${apt_target}-gcc ${common_flags} "\$@"
EOF2
cat >"/usr/local/bin/${target}-g++" <<EOF2
#!/bin/sh
set -eu
exec ${toolchain_dir}/bin/${apt_target}-g++ ${common_flags} "\$@"
EOF2
chmod +x "/usr/local/bin/${target}-gcc" "/usr/local/bin/${target}-g++"
;;
esac
}

case "${host}" in
Expand Down

0 comments on commit ea9aca6

Please sign in to comment.