recipe 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Build recipe for rust.
  2. #
  3. # Copyright (c) 2022 Matias Fonzo, <selk@dragora.org>.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Exit immediately on any error
  17. set -e
  18. program=rustc
  19. pkgname=rust
  20. version=1.64.0
  21. release=1
  22. # Define a category for the output of the package name
  23. pkgcategory=devel
  24. tarname=${program}-${version}-src.tar.gz
  25. # Set remote source(s) according to the architecture/platform
  26. fetch=https://static.rust-lang.org/dist/$tarname
  27. rustfetch_date=2022-08-11
  28. case $arch in
  29. amd64 | x32 )
  30. tarname_rust_std_platform=rust-std-1.63.0-x86_64-unknown-linux-musl.tar.xz
  31. tarname_rustc_platform=rustc-1.63.0-x86_64-unknown-linux-musl.tar.xz
  32. tarname_cargo_platform=cargo-1.63.0-x86_64-unknown-linux-musl.tar.xz
  33. fetch="
  34. $fetch
  35. https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rust_std_platform
  36. https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rustc_platform
  37. https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_cargo_platform
  38. "
  39. ;;
  40. i586)
  41. tarname_rust_std_platform=
  42. tarname_rustc_platform=
  43. tarname_cargo_platform=
  44. fetch="
  45. $fetch
  46. https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rust_std_platform
  47. https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rustc_platform
  48. https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_cargo_platform
  49. "
  50. ;;
  51. esac
  52. description="
  53. The Rust programming language.
  54. The Rust programming language helps you write faster, more reliable software.
  55. High-level ergonomics and low-level control are often at odds in programming
  56. language design; Rust challenges that conflict. Through balancing powerful
  57. technical capacity and a great developer experience, Rust gives you the
  58. option to control low-level details (such as memory usage) without all the
  59. hassle traditionally associated with such control.
  60. "
  61. homepage=https://www.rust-lang.org/
  62. license="Apachev2.0, MIT"
  63. # Source documentation
  64. docs=""; # This build system already installs the documentation.
  65. docsdir="${docdir}/${pkgname}-${version}"
  66. # The source has a custom directory name
  67. srcdir=${program}-${version}-src
  68. build()
  69. {
  70. unpack "${tardir}/$tarname"
  71. cd "$srcdir"
  72. mkdir -p build/cache/$rustfetch_date
  73. cp -f \
  74. "${tardir}/$tarname_rust_std_platform" \
  75. "${tardir}/$tarname_rustc_platform" \
  76. "${tardir}/$tarname_cargo_platform" \
  77. build/cache/$rustfetch_date
  78. # Set sane permissions
  79. chmod -R u+w,go-w,a+rX-s .
  80. # Apply patches taken from "Void Linux" (Thanks!)
  81. for file in "${worktree}"/patches/rust/void/*.patch
  82. do
  83. if test -f "$file"
  84. then
  85. echo " Applying patch $file ..."
  86. patch -Np1 -i "$file"
  87. fi
  88. done
  89. unset -v file
  90. # Uncomment this only if the build of LLVM is static
  91. #rm -rf src/llvm-project
  92. #patch -Np1 -i "${worktree}/patches/rust/llvm/llvm-with-dependencies.patch"
  93. # We need this because cargo verifies checksums of all files in vendor
  94. # crates when it builds and gives us no way to override or update the
  95. # file sanely... so just clear out the file list (Thanks to "Void Linux")
  96. for postdir in libc typenum cc target-lexicon tikv-jemallocator
  97. do
  98. sed -i 's/\("files":{\)[^}]*/\1/' vendor/${postdir}/.cargo-checksum.json
  99. done
  100. unset -v postdir
  101. # Insert our custom config.toml
  102. cp -f "${worktree}/archive/rust/config.toml" config.toml && \
  103. sed -e "s|@prefix@|/usr|" \
  104. -e "s|@libdir@|lib${libSuffix}|" \
  105. -e "s|@docsdir@|$docsdir|" \
  106. -i config.toml
  107. # Set flags prior to build
  108. CPPFLAGS="$QICPPFLAGS"
  109. CFLAGS="$QICFLAGS"
  110. CXXFLAGS="$QICXXFLAGS"
  111. LDFLAGS="$QILDFLAGS"
  112. SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
  113. RUST_BACKTRACE=full
  114. RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi"
  115. export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS SSL_CERT_FILE RUST_BACKTRACE RUSTFLAGS
  116. # Build and install Rust
  117. python3 ./x.py build
  118. DESTDIR="$destdir" python3 x.py install
  119. unset -v CPPFLAGS CFLAGS CXXFLAGS LDFLAGS SSL_CERT_FILE RUST_BACKTRACE RUSTFLAGS \
  120. rustfetch_date tarname_rust_std_platform tarname_rustc_platform tarname_cargo_platform
  121. # Strip remaining binaries and libraries
  122. find "$destdir" -type f | xargs file | \
  123. awk '/ELF/ && /executable/ || /shared object/' | \
  124. cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  125. # Compress and link man pages (if needed)
  126. if test -d "${destdir}/$mandir"
  127. then
  128. (
  129. cd "${destdir}/$mandir"
  130. find . -type f -exec lzip -9 {} +
  131. find . -type l | while read -r file
  132. do
  133. ln -sf "$(readlink -- "$file").lz" "${file}.lz"
  134. rm -- "$file"
  135. done
  136. )
  137. fi
  138. }