sickcodes / aur

Sick Codes AUR Packages
GNU General Public License v3.0
8 stars 4 forks source link

riscv-gnu-toolchain cannot compile #3

Open JakubVanek opened 2 years ago

JakubVanek commented 2 years ago

Hi!

it seems that the riscv-gnu-toolchain(-bin) packages are not working properly. I've encountered this in https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1005. The toolchain is unable to find its assembler when called via riscv32-unknown-elf-gcc. The issue seems to be that the target-specific directories shouldn't be deleted:

  rm -rf "${srcdir}"/riscv/riscv64-unknown-linux-gnu
  rm -rf "${srcdir}"/riscv/riscv32-unknown-linux-gnu
  rm -rf "${srcdir}"/riscv/riscv64-unknown-elf
  rm -rf "${srcdir}"/riscv/riscv32-unknown-elf

I think they need to be copied into /usr with the rest of the toolchain. This should fix the problem.

However, there remain some file conflicts as noted in the current PKGBUILD. I've hacked together an alternative PKGBUILD for a single toolchain variant that fixes this. It is not a drop-in replacement for either of the packages, but it should be slightly more robust - it puts all files into an isolated directory in /opt and only adds symlinks for the toolchain binaries.

# Maintainer: Sick Codes <info at sick dot codes>
#
pkgname=riscv-gnu-toolchain-bin
# To maintain, simply change the nightly date: https://github.com/riscv-collab/riscv-gnu-toolchain/releases
pkgver=2021.09.21
_target=11.1.0
_pkg_prefix=ubuntu-20.04-nightly
pkgrel=1
pkgdesc="GNU toolchain for RISC-V, including GCC. Precompiled riscv32-unknown-elf-gcc."
arch=('x86_64')
url="https://github.com/riscv-collab/riscv-gnu-toolchain"
license=('GPL2')
provides=(${pkgname}
  riscv32-unknown-elf-gcc-11.1.0 riscv32-unknown-elf-size riscv32-unknown-elf-run riscv32-unknown-elf-objdump riscv32-unknown-elf-nm riscv32-unknown-elf-gdb-add-index riscv32-unknown-elf-c++filt riscv32-unknown-elf-addr2line riscv32-unknown-elf-gcc-nm riscv32-unknown-elf-readelf riscv32-unknown-elf-lto-dump riscv32-unknown-elf-gcc riscv32-unknown-elf-ld.bfd riscv32-unknown-elf-ranlib riscv32-unknown-elf-gcov-tool riscv32-unknown-elf-ld riscv32-unknown-elf-gcc-ar riscv32-unknown-elf-gdb riscv32-unknown-elf-gcov riscv32-unknown-elf-as riscv32-unknown-elf-gcov-dump riscv32-unknown-elf-objcopy riscv32-unknown-elf-gcc-ranlib riscv32-unknown-elf-strip riscv32-unknown-elf-c++ riscv32-unknown-elf-cpp riscv32-unknown-elf-strings riscv32-unknown-elf-ar riscv32-unknown-elf-elfedit riscv32-unknown-elf-gprof riscv32-unknown-elf-g++
)
depends=()
optdepends=()
makedepends=(curl python3 mpc mpfr gmp texinfo gperf libtool patchutils bc zlib expat)
source=(
  "https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/${pkgver}/riscv32-elf-${_pkg_prefix}-${pkgver}-nightly.tar.gz"
)
# skipping shasums due to size
sha256sums=(
  'SKIP'
)

package() {

  install -dm755 "${pkgdir}"/opt/riscv32-unknown-elf
  install -dm755 "${pkgdir}"/usr/bin

  # copy to /opt
  cp -pvr "${srcdir}"/riscv/* "${pkgdir}"/opt/riscv32-unknown-elf/

  # strip host binaries
  find "${pkgdir}"/opt/riscv32-unknown-elf/bin "${pkgdir}"/opt/riscv32-unknown-elf/libexec -type f -and \( -executable \) -exec strip '{}' \;

  # replace binutils copies with symlinks
  for file in  "${pkgdir}"/opt/riscv32-unknown-elf/riscv32-unknown-elf/bin/*; do
    just_name="$(basename "$file")"
    rm "$file"
    ln -s "../../bin/riscv32-unknown-elf-$just_name" "$file"
  done

  # install symlinks to /usr/bin
  for file in "${pkgdir}"/opt/riscv32-unknown-elf/bin/*; do
    just_name="$(basename "$file")"
    ln -s "/opt/riscv32-unknown-elf/bin/$just_name" "${pkgdir}/usr/bin/$just_name"
  done
}

Could you please take a look at this?

Thank you,

Jakub

sickcodes commented 2 years ago

LGTM, should I put the toolchain in /opt?

TheZoq2 commented 2 years ago

I updated the pkgbuild here to make it install all the variations that the one currently in git does. Seems to work well from a small test

# Maintainer: Sick Codes <info at sick dot codes>
#
pkgname=riscv-gnu-toolchain-bin
# To maintain, simply change the nightly date: https://github.com/riscv-collab/riscv-gnu-toolchain/releases
pkgver=2022.06.10
_target=11.1.0
_pkg_prefix=ubuntu-20.04-nightly
pkgrel=1
pkgdesc="GNU toolchain for RISC-V, including GCC. Precompiled riscv32-unknown-elf-gcc."
arch=('x86_64')
url="https://github.com/riscv-collab/riscv-gnu-toolchain"
license=('GPL2')
provides=(${pkgname}
  riscv32-unknown-elf-gcc-11.1.0 riscv32-unknown-elf-size riscv32-unknown-elf-run riscv32-unknown-elf-objdump riscv32-unknown-elf-nm riscv32-unknown-elf-gdb-add-index riscv32-unknown-elf-c++filt riscv32-unknown-elf-addr2line riscv32-unknown-elf-gcc-nm riscv32-unknown-elf-readelf riscv32-unknown-elf-lto-dump riscv32-unknown-elf-gcc riscv32-unknown-elf-ld.bfd riscv32-unknown-elf-ranlib riscv32-unknown-elf-gcov-tool riscv32-unknown-elf-ld riscv32-unknown-elf-gcc-ar riscv32-unknown-elf-gdb riscv32-unknown-elf-gcov riscv32-unknown-elf-as riscv32-unknown-elf-gcov-dump riscv32-unknown-elf-objcopy riscv32-unknown-elf-gcc-ranlib riscv32-unknown-elf-strip riscv32-unknown-elf-c++ riscv32-unknown-elf-cpp riscv32-unknown-elf-strings riscv32-unknown-elf-ar riscv32-unknown-elf-elfedit riscv32-unknown-elf-gprof riscv32-unknown-elf-g++
)
depends=()
optdepends=()
makedepends=(curl python3 libmpc mpfr gmp texinfo gperf libtool patchutils bc zlib expat)
source=(
"https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/${pkgver}/riscv32-elf-${_pkg_prefix}-${pkgver}-nightly.tar.gz"
  "https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/${pkgver}/riscv32-glibc-${_pkg_prefix}-${pkgver}-nightly.tar.gz"
  "https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/${pkgver}/riscv64-elf-${_pkg_prefix}-${pkgver}-nightly.tar.gz"
  "https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/${pkgver}/riscv64-glibc-${_pkg_prefix}-${pkgver}-nightly.tar.gz"
)
# skipping shasums due to size
sha256sums=(
  'SKIP'
  'SKIP'
  'SKIP'
  'SKIP'
)

package() {

  install -dm755 "${pkgdir}"/opt/riscv32-unknown-elf
  install -dm755 "${pkgdir}"/usr/bin

  # copy to /opt
  cp -pvr "${srcdir}"/riscv/* "${pkgdir}"/opt/riscv32-unknown-elf/

  # strip host binaries
  find "${pkgdir}"/opt/riscv32-unknown-elf/bin "${pkgdir}"/opt/riscv32-unknown-elf/libexec -type f -and \( -executable \) -exec strip '{}' \;

  # replace binutils copies with symlinks
  for file in  "${pkgdir}"/opt/riscv32-unknown-elf/riscv32-unknown-elf/bin/*; do
    just_name="$(basename "$file")"
    rm "$file"
    ln -s "../../bin/riscv32-unknown-elf-$just_name" "$file"
  done

  # install symlinks to /usr/bin
  for file in "${pkgdir}"/opt/riscv32-unknown-elf/bin/*; do
    just_name="$(basename "$file")"
    ln -s "/opt/riscv32-unknown-elf/bin/$just_name" "${pkgdir}/usr/bin/$just_name"
  done
}