forked from pool/rust1.71
William Brown b9f728b107 Accepting request 1102264 from home:firstyear:branches:devel:languages:rust
- Update to version 1.71.1
- bsc#1213817 - CVE-2023-38497 - Cargo does not respect the umask
  when extracting dependencies

2023-08-04 05:50:10 +00:00

731 lines
23 KiB

# spec file
# Copyright (c) 2023 SUSE LLC
# Copyright (c) 2019 Luke Jones,
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via
%global version_suffix 1.71
%global version_current 1.71.1
%global version_previous 1.70.0
# This has to be kept lock step to the rust version.
%global llvm_version 16
%if 0%{?sle_version} <= 150500 && 0%{?suse_version} < 1599
# We may need a minimum gcc version for some linker flags
# This is especially true on leap/sle
# ⚠️ 11 is required for a number of linker flags to be supported in sle.
%global gcc_version 11
%define obsolete_rust_versioned() \
Obsoletes: %{1}1.70%{?2:-%{2}} \
Obsoletes: %{1}1.69%{?2:-%{2}} \
Obsoletes: %{1}1.68%{?2:-%{2}} \
Obsoletes: %{1}1.67%{?2:-%{2}} \
Obsoletes: %{1}1.66%{?2:-%{2}} \
Obsoletes: %{1}1.65%{?2:-%{2}} \
Obsoletes: %{1}1.64%{?2:-%{2}} \
Obsoletes: %{1}1.63%{?2:-%{2}} \
Obsoletes: %{1}1.62%{?2:-%{2}}
# ⚠️ Must leave 1.62 here due to kernel requirements.
# Build the rust target triple.
# Some rust arches don't match what SUSE labels them.
%global rust_arch %{_arch}
%global abi gnu
%ifarch armv7hl
%global rust_arch armv7
%global abi gnueabihf
%ifarch armv6hl
%global rust_arch arm
%global abi gnueabihf
%ifarch ppc
%global rust_arch powerpc
%ifarch ppc64
%global rust_arch powerpc64
%ifarch ppc64le
%global rust_arch powerpc64le
%ifarch riscv64
%global rust_arch riscv64gc
# Must restrict the x86 build to i686 since i586 is currently
# unsupported
%ifarch %{ix86}
%global rust_arch i686
%global rust_triple %{rust_arch}-unknown-linux-%{abi}
# All sources and bootstraps are fetched form here
%global dl_url
# Rust doesn't function well when put in /usr/lib64
%global common_libdir %{_prefix}/lib
%global rustlibdir %{common_libdir}/rustlib
# Detect if sccache has been requested by the build
%if "%{getenv:RUSTC_WRAPPER}" == "sccache"
%bcond_without sccache
%bcond_with sccache
# === rust arch support tiers ===
# tl;dr only aarch64, x86_64 and i686 are guaranteed to work.
# armv6/7, s390x, ppc[64[le]], riscv are all "guaranteed to build" only
# but may not always work.
# === broken distro llvm ===
# In some situations the llvm provided on the platform may not work.
# we add these conditions here.
# ⚠️ SLE/LEAP 15.3 LLVM is too old!
# ⚠️ 1.59 breaks codegen with distro llvm!!!
%if 0%{?is_opensuse} == 1 && 0%{?suse_version} >= 1550
# && "{version_suffix}" != "1.61"
# Can proceed with pinned llvm.
%bcond_with bundled_llvm
# Use bundled llvm instead.
# For details see boo#1192067
%bcond_without bundled_llvm
# === Use clang/lld during build if possible ===
# i586 - unable to link libatomic
# aarch64 - fails due to an invalid linker flag
%bcond_with llvmtools
# Depending on our environment, we may need to configure our linker in a different manner.
# If we elect for llvm, always use clang.
%if %{with llvmtools}
%define rust_linker clang
%if 0%{?gcc_version} != 0
%define rust_linker gcc-%{gcc_version}
%define rust_linker cc
# === Enable wasm/wasi on t1 targets ===
%if 0%{?is_opensuse} == 1 && 0%{?suse_version} >= 1550
%ifarch x86_64 aarch64
%bcond_without wasm32
%bcond_without wasi
%bcond_with wasm32
%bcond_with wasi
%bcond_with wasm32
%bcond_with wasi
# Test is done in a different multibuild package (rustXXX-test). This
# package will replace the local-rust-root and use the systems's one
# from the rustXXX package itself. This will exercise the compiler,
# even tho, the tests will require more compilation. If we do not
# agree on this model we can drop the _multibuild option and do the
# pct check as a part of the main spec.
%global flavor @BUILD_FLAVOR@%{nil}
%if "%{flavor}" == "test"
%define psuffix -test
%bcond_without test
%define psuffix %{nil}
%bcond_with test
# """
# Do not use parallel codegen in order to
# a) not exhaust memory on build-machines and
# b) generate the fastest possible binary
# at the cost of longer build times for this package
# """
# These claims are incorrect
# a) codegen=1, actually consumes MORE memory due to the fact that the full
# code unit is then LTO'd in a single pass. This can cause LLVM to internally OOM
# especially if the machine has less than 1G of ram, and this is documented:
# *
# it has also been observed in OBS during builds of 1.52 and 1.53
# b) the performance gains from codegen=1 are minimal at best, and not worth
# us messing about with these values - especially when the rust language team
# probably know more about how to set and tune these based on data and research
# Debuginfo can exhaust memory on these architecture workers
%ifarch %{arm} %{ix86}
%define debug_info --debuginfo-level=0 --debuginfo-level-rustc=0 --debuginfo-level-std=0 --debuginfo-level-tools=0 --debuginfo-level-tests=0
%define debug_info %{nil}
%global rustflags -Clink-arg=-Wl,-z,relro,-z,now
# Exclude implicitly-scanned Provides, especially the ones:
%global __provides_exclude_from ^%{rustlibdir}/.*$
Name: rust%{version_suffix}%{psuffix}
Version: %{version_current}
Release: 0
Summary: A systems programming language
License: Apache-2.0 OR MIT
Group: Development/Languages/Rust
Source0: %{dl_url}/rustc-%{version}-src.tar.xz
Source1: rust.keyring
%if %{without test}
Source99: %{name}-rpmlintrc
Source100: %{dl_url}/rust-%{version_current}-x86_64-unknown-linux-gnu.tar.xz
NoSource: 100
Source101: %{dl_url}/rust-%{version_current}-i686-unknown-linux-gnu.tar.xz
NoSource: 101
Source102: %{dl_url}/rust-%{version_current}-aarch64-unknown-linux-gnu.tar.xz
NoSource: 102
Source103: %{dl_url}/rust-%{version_current}-armv7-unknown-linux-gnueabihf.tar.xz
NoSource: 103
Source104: %{dl_url}/rust-%{version_current}-arm-unknown-linux-gnueabihf.tar.xz
NoSource: 104
Source105: %{dl_url}/rust-%{version_current}-powerpc64-unknown-linux-gnu.tar.xz
NoSource: 105
Source106: %{dl_url}/rust-%{version_current}-powerpc64le-unknown-linux-gnu.tar.xz
NoSource: 106
Source107: %{dl_url}/rust-%{version_current}-s390x-unknown-linux-gnu.tar.xz
NoSource: 107
Source108: %{dl_url}/rust-%{version_current}-powerpc-unknown-linux-gnu.tar.xz
NoSource: 108
Source109: %{dl_url}/rust-%{version_current}-riscv64gc-unknown-linux-gnu.tar.xz
NoSource: 109
Source200: %{dl_url}/rust-%{version_current}-x86_64-unknown-linux-gnu.tar.xz.asc
NoSource: 200
Source201: %{dl_url}/rust-%{version_current}-i686-unknown-linux-gnu.tar.xz.asc
NoSource: 201
Source202: %{dl_url}/rust-%{version_current}-aarch64-unknown-linux-gnu.tar.xz.asc
NoSource: 202
Source203: %{dl_url}/rust-%{version_current}-armv7-unknown-linux-gnueabihf.tar.xz.asc
NoSource: 203
Source204: %{dl_url}/rust-%{version_current}-arm-unknown-linux-gnueabihf.tar.xz.asc
NoSource: 204
Source205: %{dl_url}/rust-%{version_current}-powerpc64-unknown-linux-gnu.tar.xz.asc
NoSource: 205
Source206: %{dl_url}/rust-%{version_current}-powerpc64le-unknown-linux-gnu.tar.xz.asc
NoSource: 206
Source207: %{dl_url}/rust-%{version_current}-s390x-unknown-linux-gnu.tar.xz.asc
NoSource: 207
Source208: %{dl_url}/rust-%{version_current}-powerpc-unknown-linux-gnu.tar.xz.asc
NoSource: 208
Source209: %{dl_url}/rust-%{version_current}-riscv64gc-unknown-linux-gnu.tar.xz.asc
NoSource: 209
# Make factory-auto stop complaining...
Source1000: README.suse-maint
# PATCH-FIX-OPENSUSE: edit src/librustc_llvm/ to ignore GCC incompatible flag
Patch0: ignore-Wstring-conversion.patch
# IMPORTANT - To generate patches for submodules in git so they apply relatively you can use
# git format-patch --text --dst-prefix=b/src/tools/cargo/ HEAD~2
BuildRequires: chrpath
BuildRequires: curl
# BUG - fdupes on leap/sle causes issues with debug info
%if 0%{?is_opensuse} == 1 && 0%{?suse_version} >= 1550
BuildRequires: fdupes
BuildRequires: pkgconfig
BuildRequires: procps
BuildRequires: python3-base
BuildRequires: util-linux
BuildRequires: pkgconfig(libcurl)
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(zlib)
# Set requires appropriately
%if %with sccache
BuildRequires: sccache
BuildRequires: ccache
# For linking to platform
Requires: glibc-devel
# Rustc doesn't really do much without Cargo, but you know, if you wanna yolo that ...
Recommends: cargo
# For static linking
Suggests: glibc-devel-static
%if %{with wasi}
BuildRequires: wasi-libc
%if %{with llvmtools}
BuildRequires: clang
BuildRequires: libstdc++-devel
BuildRequires: lld
Requires: clang
Requires: lld
%if 0%{?gcc_version} != 0
BuildRequires: gcc%{gcc_version}-c++
Requires: gcc%{gcc_version}
BuildRequires: gcc-c++
Requires: gcc
# Clang gives better errors than gcc during a compilation, and it keeps everything
# within llvm ecosystem.
Suggests: clang
# lld is significantly faster than gold for linking, so users may wish to preference it.
Suggests: lld
# CMake and Ninja required to drive the bundled llvm build.
# Cmake is also needed in tests.
%if 0%{?sle_version} >= 120000 && 0%{?sle_version} <= 150200
# In these distros cmake is 2.x, or 3.X < 3.13, so we need cmake3 for building llvm.
BuildRequires: cmake3 > 3.13.4
BuildRequires: cmake > 3.13.4
# To build rust-lld
BuildRequires: ninja
%if %{without bundled_llvm}
# Use distro provided LLVM on Tumbleweed, but pin it to the matching LLVM!
# For details see boo#1192067
BuildRequires: llvm%{llvm_version}-devel
Requires: lld%{llvm_version}
%if %{with test}
BuildRequires: cargo%{version_suffix} = %{version}
BuildRequires: rust%{version_suffix} = %{version}
# Static linking tests need this.
BuildRequires: glibc-devel-static
BuildRequires: git
%if %{without bundled_llvm}
# For FileCheck
BuildRequires: llvm%{llvm_version}-devel
%if %{with wasm32}
BuildRequires: nodejs-default
# End with test
%obsolete_rust_versioned rust
Conflicts: rust+rustc < %{version}
Conflicts: rustc-bootstrap
Provides: rust+rustc = %{version}
Conflicts: rust-std < %{version}
Obsoletes: rust-std < %{version}
Provides: rust-std = %{version}
Conflicts: rust-std-static < %{version}
Obsoletes: rust-std-static < %{version}
Provides: rust-std-static = %{version}
Conflicts: rust-gdb < %{version}
Obsoletes: rust-gdb < %{version}
Provides: rust-gdb = %{version}
%if %{without test}
# Restrict the architectures as building rust relies on being
# initially bootstrapped before we can build the n+1 release
ExclusiveArch: x86_64 %{arm} aarch64 ppc ppc64 ppc64le s390x %{ix86} riscv64
%ifarch %{ix86}
ExclusiveArch: i686
# Restrict for Tier 1 targets (but we should report bugs in Tier 2)
ExclusiveArch: x86_64 i686 aarch64
Rust is a systems programming language focused on three goals: safety,
speed, and concurrency. It maintains these goals without having a
garbage collector, making it a useful language for a number of use
cases other languages are not good at: embedding in other languages,
programs with specific space and time requirements, and writing
low-level code, like device drivers and operating systems. It improves
on current languages targeting this space by having a number of
compile-time safety checks that produce no runtime overhead, while
eliminating all data races. Rust also aims to achieve "zero-cost
abstractions", even though some of these abstractions feel like those
of a high-level language. Even then, Rust still allows precise control
like a low-level language would.
%package -n cargo%{version_suffix}
Summary: The Rust package manager
License: Apache-2.0 OR MIT
Group: Development/Languages/Rust
Requires: rust-std = %{version}
Obsoletes: cargo-vendor < %{version}
Provides: cargo-vendor = %{version}
Provides: rust+cargo = %{version}
%obsolete_rust_versioned cargo
%description -n cargo%{version_suffix}
Cargo downloads dependencies of Rust projects and compiles it.
# Previously the stage0 compiler was skipped in test builds, but there are now
# tests in rust's source tree that require it.
%ifarch x86_64
%setup -q -T -b 100 -n rust-%{version_current}-%{rust_triple}
%ifarch %{ix86}
%setup -q -T -b 101 -n rust-%{version_current}-%{rust_triple}
%ifarch aarch64
%setup -q -T -b 102 -n rust-%{version_current}-%{rust_triple}
%ifarch armv7hl
%setup -q -T -b 103 -n rust-%{version_current}-%{rust_triple}
%ifarch armv6hl
%setup -q -T -b 104 -n rust-%{version_current}-%{rust_triple}
%ifarch ppc64
%setup -q -T -b 105 -n rust-%{version_current}-%{rust_triple}
%ifarch ppc64le
%setup -q -T -b 106 -n rust-%{version_current}-%{rust_triple}
%ifarch s390x
%setup -q -T -b 107 -n rust-%{version_current}-%{rust_triple}
%ifarch ppc
%setup -q -T -b 108 -n rust-%{version_current}-%{rust_triple}
%ifarch riscv64
%setup -q -T -b 109 -n rust-%{version_current}-%{rust_triple}
./ --components=cargo,rustc,rust-std-%{rust_triple} --prefix=.%{_prefix} --disable-ldconfig
%global rust_root %{_builddir}/rust-%{version_current}-%{rust_triple}%{_prefix}
%autosetup -p1 -n rustc-%{version}-src
# We never enable emscripten.
rm -rf src/llvm-emscripten/
# We never enable other LLVM tools.
rm -rf src/tools/clang
rm -rf src/tools/lldb
# Fix rpmlint error "This script uses 'env' as an interpreter"
sed -i '1s|#!%{_bindir}/env python|#!%{_bindir}/python3|' library/core/src/unicode/
chmod +x library/core/src/unicode/
# Debugging for if anything goes south.
free -h
df -h
# Create exports file
# Keep all the "export VARIABLE" together here, so they can be
# reread in the %%install section below.
# If the environments between build and install and different,
# everything will be rebuilt during installation!
%if %{with llvmtools}
cat > <<EOF
export CC="/usr/bin/clang"
export CXX="/usr/bin/clang++"
%if 0%{?gcc_version} != 0
cat > <<EOF
export CC="/usr/bin/gcc-%{gcc_version}"
export CXX="/usr/bin/g++-%{gcc_version}"
cat > <<EOF
export CC="gcc"
export CXX="g++"
# -Clink-arg=-B{_prefix}/lib/rustlib/{rust_triple}/bin/gcc-ld/"
# -Clink-arg=-B{rust_root}/lib/rustlib/{rust_triple}/bin/gcc-ld/"
%if %{with sccache}
export CC="/usr/bin/sccache ${CC}"
export CXX="/usr/bin/sccache ${CXX}"
cat >> <<EOF
export CXXFLAGS="-I/home/abuild/rpmbuild/BUILD/rustc-%{version}-src/src/llvm-project/libunwind/include/"
export PATH="%{_prefix}/lib/rustlib/%{rust_triple}/bin/:${PATH}"
export RUSTFLAGS="%{rustflags} -Clinker=%{rust_linker}"
export LD_LIBRARY_PATH="%{rust_root}/lib"
export DESTDIR=%{buildroot}
unset FFLAGS
. ./
# Sometimes to debug sccache we need to know the state of the env.
# Check our rustroot works as we expect
%if %{without test}
cat >> <<EOF
fn main() {}
RUSTC_LOG=rustc_codegen_ssa::back::link=info %{rust_root}/bin/rustc -C link-args=-Wl,-v ${RUSTFLAGS}
# The configure macro will modify some autoconf-related files, which upsets
# cargo when it tries to verify checksums in those files. So we don't use
# the macro, as it provides no tangible benefit to our build process.
# FUTURE: See if we can build sanitizers without the full llvm bundling.
# {?with_tier1: --enable-sanitizers} \
./configure \
--build=%{rust_triple} --host=%{rust_triple} \
%{!?with_wasm32: --target=%{rust_triple}} \
%{?with_wasm32: --target=%{rust_triple},wasm32-unknown-unknown%{?with_wasi:,wasm32-wasi}} \
%{?with_wasi: --set target.wasm32-wasi.wasi-root=%{_datadir}/wasi-sysroot/ } \
--prefix=%{_prefix} \
--bindir=%{_bindir} \
--sysconfdir=%{_sysconfdir} \
--datadir=%{_datadir} \
--localstatedir=%{_localstatedir} \
--mandir=%{_mandir} \
--infodir=%{_infodir} \
--libdir=%{common_libdir} \
--docdir=%{_docdir}/rust \
--enable-local-rust \
%{!?with_test: --local-rust-root=%{rust_root} --disable-rpath} \
%{!?with_bundled_llvm: --llvm-root=%{_prefix} --enable-llvm-link-shared} \
%{?with_bundled_llvm: --disable-llvm-link-shared --set} \
%{?with_llvmtools: --set rust.use-lld=true --set llvm.use-linker=lld} \
--set rust.lld=true \
--default-linker=%{rust_linker} \
%{?with_sccache: --enable-sccache} \
%{!?with_sccache: --enable-ccache} \
--disable-docs \
--disable-compiler-docs \
--enable-verbose-tests \
%{debug_info} \
--enable-vendor \
--enable-extended \
--tools="cargo,rustdoc" \
--release-channel="stable" \
--set rust.deny-warnings=false
# We set deny warnings to false due to a problem where rust upstream didn't test building with
# the same version (they did previous ver)
%if %{without test}
python3 ./ build
# Debug for post build
free -h
df -h
# Reread exports file
%if %{without test}
. ./
python3 ./ install
# bsc#1199126 - rust-lld contains an rpath, which is invalid.
chrpath -d %{buildroot}%{rustlibdir}/%{rust_triple}/bin/rust-lld
%if %{with bundled_llvm}
# To facilitate tests when we aren't using system LLVM, we need filecheck available.
install -m 0755 %{_builddir}/rustc-%{version}-src/build/%{rust_triple}/llvm/bin/FileCheck %{buildroot}%{rustlibdir}/%{rust_triple}/bin/FileCheck
# Remove the license files from _docdir: make install put duplicates there
rm %{buildroot}%{_docdir}/rust/{,COPYRIGHT,LICENSE*}
rm %{buildroot}%{_docdir}/rust/*.old
# Remove installer artifacts (manifests, uninstall scripts, etc.)
find %{buildroot}%{rustlibdir} -maxdepth 1 -type f -exec rm -v '{}' '+'
# Remove hidden files from source
find %{buildroot}%{rustlibdir} -type f -name '.appveyor.yml' -exec rm -v '{}' '+'
find %{buildroot}%{rustlibdir} -type f -name '.travis.yml' -exec rm -v '{}' '+'
find %{buildroot}%{rustlibdir} -type f -name '.cirrus.yml' -exec rm -v '{}' '+'
find %{buildroot}%{rustlibdir} -type f -name '.clang-format' -exec rm -v '{}' '+'
find %{buildroot}%{rustlibdir} -type d -name '.github' -exec rm -r -v '{}' '+'
# The shared libraries should be executable to allow fdupes find duplicates.
find %{buildroot}%{common_libdir} -maxdepth 1 -type f -name '*.so' -exec chmod -v +x '{}' '+'
# The shared libraries should be executable for debuginfo extraction.
find %{buildroot}%{rustlibdir} -maxdepth 1 -type f -name '*.so' -exec chmod -v +x '{}' '+'
# Create the path for crate-devel packages
mkdir -p %{buildroot}%{_datadir}/cargo/registry
# Remove completions
rm -rf %{buildroot}%{_prefix}/src/etc/bash_completion.d
# rmdir %{buildroot}%{_prefix}/src/etc
rm -rf %{buildroot}%{_sysconfdir}/bash_completion.d
rm -rf %{buildroot}%{_datadir}/zsh
# There should be nothing here at all
rm -rf %{buildroot}%{_sysconfdir}
# cargo does not respect our _libexec setting on Leap:
if [ ! -f %{buildroot}%{_libexecdir}/cargo-credential-1password ] &&
[ -f %{buildroot}%{_exec_prefix}/libexec/cargo-credential-1password ]; then
mv %{buildroot}%{_exec_prefix}/libexec/cargo-credential-1password \
# Silence any duplicate library warnings.
%if 0%{?is_opensuse} == 1 && 0%{?suse_version} >= 1550
%fdupes %{buildroot}/%{common_libdir}
# Ugly hack to get brp-15-strip-debug call llvm-strip, which is wasm-aware, as system-strip will break wasm-files (same for ar/ranlib)
export CROSS_COMPILE=llvm-
# End without test
%if %{with test}
. ./
# Tests require stage0 in place, so we need to symlink that in for compiler access.
# Generally in a non-local rust build, this process assumes you downloaded and unpacked
# the compiler toolchain into stage0, which is why we have to feed that in manually.
mkdir -p %{_builddir}/rustc-%{version}-src/build/%{rust_triple}
ln -s %{rust_root} %{_builddir}/rustc-%{version}-src/build/%{rust_triple}/stage0
# Need to exclude issue-71519 as when we enable lld for wasm, this test incorrectly assumes
# we can use it with -Z gcc-ld=lld (which is sadly trapped in nightly). We can't exclude
# a single test so sadly we have to exclude that whole suite.
%ifarch aarch64
python3 ./ test --target=%{rust_triple} \
--exclude tests/run-make/issue-71519 \
--exclude src/tools/tidy \
--exclude src/tools/expand-yaml-anchors \
--exclude tests/ui/methods \
--exclude tests/ui/typeck \
--exclude tests/ui/mismatched_types \
--exclude tests/run-make/short-ice \
--exclude src/bootstrap
python3 ./ test --target=%{rust_triple} \
--exclude src/tools/tidy \
--exclude src/tools/expand-yaml-anchors \
--exclude tests/ui/methods \
--exclude tests/ui/typeck \
--exclude tests/ui/mismatched_types \
--exclude tests/run-make/short-ice \
--exclude src/bootstrap
# End with test
%if %{without test}
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%dir %{rustlibdir}
%dir %{rustlibdir}%{_sysconfdir}
%dir %{rustlibdir}/%{rust_triple}
%dir %{rustlibdir}/%{rust_triple}/lib
%if %{with wasm32}
%dir %{rustlibdir}/wasm32-unknown-unknown
%dir %{rustlibdir}/wasm32-unknown-unknown/lib
%if %{with wasi}
%dir %{rustlibdir}/wasm32-wasi
%dir %{rustlibdir}/wasm32-wasi/lib
%dir %{rustlibdir}/wasm32-wasi/lib/self-contained
%files -n cargo%{version_suffix}
%license src/tools/cargo/LICENSE-{APACHE,MIT,THIRD-PARTY}
%license src/tools/rustfmt/LICENSE-{APACHE,MIT}
%license src/tools/clippy/LICENSE-{APACHE,MIT}
%dir %{_datadir}/cargo
%dir %{_datadir}/cargo/registry
# End not with test