rust/rust.spectmp

621 lines
19 KiB
Text
Raw Normal View History

2025-02-04 11:03:30 +00:00
##
# Build bootstrap
# Don't disable static build otherwise you won't build dynamically
# --- rpmbuild -bb --with=bootstrap --without=llvm_boot --with=llvm_static
# Bootstrap with clang
# --- rpmbuild -bb --with=bootstrap --without=llvm_boot --without=clang --with=llvm_static
# Don't try to build at bootstrap !!!
# Build with clang
# --- rpmbuild -bb --without=clang
# Build no sytem llvm
# --- rpmbuild -bb --without=system_llvm
# Build no system llvm with clang
# --- rpmbuild -bb --without=system_llvm --without=clang
############################################################################
# ALL Rust libraries are private, because they don't keep an ABI.
%define _privatelibs lib(.*-[[:xdigit:]]{16}*|rustc.*)[.]so.*
%define __provides_exclude ^(%{_privatelibs})$
%define __requires_exclude ^(%{_privatelibs})$
%define __provides_exclude_from ^(%{_docdir}|%{rustlibdir}/src)/.*$
%define __requires_exclude_from ^(%{_docdir}|%{rustlibdir}/src)/.*$
%define debug_package %{nil}
%define _disable_ld_no_undefined 1
# To avoid undefined symbols
%define _find_debuginfo_opts -g
# We're going to override --libdir when configuring to get rustlib into a
# common path, but we'll fix the shared libraries during install.
%define rustlibdir %{_libdir}/rustlib
# Only x86_64 and i686 are Tier 1 platforms at this time.
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
%define rust_arches x86_64 %{ix86} aarch64 %{riscv}
# To bootstrap from scratch, set the channel and date from src/stage0.txt
# e.g. 1.10.0 wants rustc: 1.9.0-2016-05-24
# or nightly wants some beta-YYYY-MM-DD
# Note that cargo matches the program version here, not its crate version.
%global bootstrap_rust 1.63.0
%global bootstrap_cargo 1.63.0
%global bootstrap_date 2022-09-22
%bcond_with bootstrap
%if %{with bootstrap}
%define bootstrap_arches %{rust_arches}
%else
%define bootstrap_arches ! %{nil}
%endif
# Using llvm-static may be helpful as an opt-in, e.g. to aid LLVM rebases.
%bcond_with llvm_static
# LLDB only works on some architectures
# LLDB isn't available everywhere...
%bcond_with lldb
%ifarch x86_64
%define rust_triple x86_64-unknown-linux-gnu
%endif
%ifarch %{ix86}
%define rust_triple i686-unknown-linux-gnu
%endif
%ifarch aarch64
%define rust_triple aarch64-unknown-linux-gnu
%endif
%ifarch %{bootstrap_arches}
%define bootstrap_root rust-%{bootstrap_rust}-%{rust_triple}
%define local_rust_root %{_builddir}/%{bootstrap_root}/usr
%else
%define local_rust_root %{_prefix}
%endif
# rpm5: do not put in /usr/lib(64)
%if %rpm5
%define _libexecdir /usr/libexec
%endif
%bcond_without clang
# if you need an llvm different from the system one
# llvm15 .. llvm*
%bcond_without system_llvm
%define llvm_dir_ver llvm15
%define llvm_path /opt/%{llvm_dir_ver}
# On llvm-config system and no
%{!?with_system_llvm:%define _llvm_config %{llvm_path}/bin/llvm-config}
%{?with_system_llvm:%define _llvm_config %{_bindir}/llvm-config}
# Required for bootstrap llvm if it doesn't exist or is outdated
%bcond_without llvm_boot
# Select compilers for building llvm by default gcc.
%if %{without clang}
%if %{with system_llvm}
%define _cc %{_bindir}/clang
%define _cxx %{_bindir}/clang++
%define _ar %{_bindir}/llvm-ar
%define _ranlib %{_bindir}/llvm-ranlib
%else
%define _cc %{llvm_path}/bin/clang
%define _cxx %{llvm_path}/bin/clang++
%define _ar %{llvm_path}/bin/llvm-ar
%define _ranlib %{llvm_path}/bin//llvm-ranlib
%endif
%else
%define _cc %{__cc}
%define _cxx %{__cxx}
%define _ar %{_bindir}/ar
%define _ranlib %{_bindir}/ranlib
%endif
Summary: The Rust Programming Language
Name: rust
Version: 1.64.0
Release: 1
License: (ASL 2.0 or MIT) and (BSD and MIT)
Group: Development/Rust
# ^ written as: (rust itself) and (bundled libraries)
Url: https://www.rust-lang.org
Source0: https://static.rust-lang.org/dist/rustc-%{version}-src.tar.xz
%ifarch %{bootstrap_arches}
# do bootstrap to download
Source1: https://static.rust-lang.org/dist/rust-%{bootstrap_rust}-x86_64-unknown-linux-gnu.tar.xz
Source2: https://static.rust-lang.org/dist/rust-%{bootstrap_rust}-i686-unknown-linux-gnu.tar.xz
Source3: https://static.rust-lang.org/dist/rust-%{bootstrap_rust}-aarch64-unknown-linux-gnu.tar.xz
Source4: https://static.rust-lang.org/dist/rust-%{bootstrap_rust}-riscv64gc-unknown-linux-gnu.tar.xz
%endif
Source10: rust.rpmlintrc
BuildRequires: ncurses-devel
BuildRequires: curl
BuildRequires: pkgconfig(libcurl)
BuildRequires: pkgconfig(liblzma)
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(zlib)
# needs libssh2_userauth_publickey_frommemory
BuildRequires: pkgconfig(libssh2) >= 1.6.0
BuildRequires: pkgconfig(python3)
BuildRequires: cmake >= 2.8.11
BuildRequires: stdc++-static-devel
%if %{without bootstrap}
%{?with_system_llvm:BuildRequires: llvm-devel}
%{?with_system_llvm:BuildRequires: clang-devel}
%{!?with_system_llvm:BuildRequires: llvm15}
%endif
%{!?with_clang:BuildRequires: clang}
BuildRequires: gcc-c++
%ifnarch %{ix86}
BuildRequires: ninja
%endif
%if %{with llvm_static}
BuildRequires: pkgconfig(libffi)
%endif
# make check needs "ps" for src/test/run-pass/wait-forked-but-failed-child.rs
BuildRequires: procps-ng
# debuginfo-gdb tests need gdb
BuildRequires: gdb
%if %{without bootstrap}
BuildRequires: cargo >= %{bootstrap_cargo}
BuildRequires: %{name} >= %{bootstrap_rust}
%endif
# Virtual provides for folks who attempt "dnf install rustc"
Provides: rustc = %{version}-%{release}
# Always require our exact standard library
Requires: %{name}-std-static = %{version}-%{release}
Requires: /usr/bin/cc
%description
Rust is a systems programming language that runs blazingly fast, prevents
segfaults, and guarantees thread safety.
This package includes the Rust compiler and documentation generator.
%files
%license COPYRIGHT* LICENSE-APACHE LICENSE-MIT
%doc README.md
%{_bindir}/rustc
%{_bindir}/rustdoc
%{_libdir}/*.so
%{_libexecdir}/rust-analyzer-proc-macro-srv
%{_mandir}/man1/rustc.1*
%{_mandir}/man1/rustdoc.1*
%dir %{rustlibdir}
%dir %{rustlibdir}/%{rust_triple}
%dir %{rustlibdir}/%{rust_triple}/lib
%{rustlibdir}/%{rust_triple}/lib/*.so*
#-------------------------------------------------------------------------
%package std-static
Summary: Standard library for Rust
Group: Development/Rust
%description std-static
This package includes the standard libraries for building applications
written in Rust.
%files std-static
%dir %{rustlibdir}
%dir %{rustlibdir}/%{rust_triple}
%dir %{rustlibdir}/%{rust_triple}/lib
%{rustlibdir}/%{rust_triple}/lib/*.rlib
#-------------------------------------------------------------------------
%package debugger-common
Summary: Common debugger pretty printers for Rust
Group: Development/Rust
BuildArch: noarch
%description debugger-common
This package includes the common functionality
for %{name}-gdb and %{name}-lldb.
%files debugger-common
%dir %{rustlibdir}
%dir %{rustlibdir}/etc
%{rustlibdir}/etc/rust_*.py*
%if %{mdvver} >= 201910
%{rustlibdir}/etc/__pycache__/rust_*.py*
%endif
#-------------------------------------------------------------------------
%package gdb
Summary: GDB pretty printers for Rust
Group: Development/Rust
Requires: gdb
Requires: %{name}-debugger-common = %{version}-%{release}
BuildArch: noarch
# (akien) Handle moved files between our old Mageia package and this Fedora-based one
Conflicts: rust < 1.11.0-3
%description gdb
This package includes the rust-gdb script,
which allows easier debugging of Rust programs.
%files gdb
%{_bindir}/rust-gdb
%{rustlibdir}/etc/gdb_*
%if %{mdvver} >= 201910
%{rustlibdir}/etc/__pycache__/gdb_*
%endif
# %%exclude - No work!
#%%exclude %%{_bindir}/rust-gdbgui
%{_bindir}/rust-gdbgui
#-------------------------------------------------------------------------
%if %{with lldb}
%package lldb
Summary: LLDB pretty printers for Rust
Group: Development/Rust
Requires: lldb
%if %{mdvver} > 201610
Requires: python3-lldb
%else
Requires: python-lldb
%endif
Requires: %{name}-debugger-common = %{version}-%{release}
BuildArch: noarch
%description lldb
This package includes the rust-lldb script,
which allows easier debugging of Rust programs.
%files lldb
%doc README.md COPYRIGHT LICENSE-APACHE LICENSE-MIT
%{_bindir}/rust-lldb
%{rustlibdir}/etc/lldb_*
%endif
#-------------------------------------------------------------------------
%package -n cargo
Summary: Rust's package manager and build tool
Group: Development/Rust
# For tests:
BuildRequires: git-core
# Cargo is not much use without Rust
Requires: rust
Obsoletes: cargo < 1.26.0-1
# "cargo vendor" is a builtin command starting with 1.37. The Obsoletes and
# Provides are mostly relevant to RHEL, but harmless to have on Fedora/etc. too
Obsoletes: cargo-vendor <= 0.1.23
Provides: cargo-vendor = %{version}-%{release}
%description -n cargo
Cargo is a tool that allows Rust projects to declare their various dependencies
and ensure that you'll always get a repeatable build.
%files -n cargo
%license src/tools/cargo/LICENSE-{APACHE,MIT,THIRD-PARTY}
%doc src/tools/cargo/README.md
%{_bindir}/cargo
%{_libexecdir}/cargo*
%{_mandir}/man1/cargo*.1*
%{_sysconfdir}/bash_completion.d/cargo
%{_datadir}/zsh/site-functions/_cargo
%dir %{_datadir}/cargo
%dir %{_datadir}/cargo/registry
#-------------------------------------------------------------------------
%package -n rustfmt
Summary: Tool to find and fix Rust formatting issues
Group: Development/Rust
Requires: cargo
# The component/package was rustfmt-preview until Rust 1.31.
Obsoletes: rustfmt-preview < 1.0.0
Provides: rustfmt-preview = %{version}-%{release}
%description -n rustfmt
A tool for formatting Rust code according to style guidelines.
%files -n rustfmt
%doc src/tools/rustfmt/{README,CHANGELOG,Configurations}.md
%license src/tools/rustfmt/LICENSE-{APACHE,MIT}
%{_bindir}/rustfmt
%{_bindir}/cargo-fmt
#-------------------------------------------------------------------------
%package -n rls
Summary: Rust Language Server for IDE integration
Group: Development/Rust
Requires: rust-analysis
# /usr/bin/rls is dynamically linked against internal rustc libs
Requires: %{name} = %{version}-%{release}
# The component/package was rls-preview until Rust 1.31.
Obsoletes: rls-preview < 1.31.6
Provides: rls-preview = %{version}-%{release}
%description -n rls
The Rust Language Server provides a server that runs in the background,
providing IDEs, editors, and other tools with information about Rust programs.
It supports functionality such as 'goto definition', symbol search,
reformatting, and code completion, and enables renaming and refactorings.
%files -n rls
%doc src/tools/rust-analyzer/README.md
%license src/tools/rust-analyzer/LICENSE-{APACHE,MIT}
%{_bindir}/rls
%{_bindir}/rust-analyzer
#-------------------------------------------------------------------------
%package -n clippy
Summary: Lints to catch common mistakes and improve your Rust code
Group: Development/Rust
Requires: cargo
# /usr/bin/clippy-driver is dynamically linked against internal rustc libs
Requires: %{name} = %{version}-%{release}
# The component/package was clippy-preview until Rust 1.31.
Obsoletes: clippy-preview <= 0.0.212
Provides: clippy-preview = %{version}-%{release}
%description -n clippy
A collection of lints to catch common mistakes and improve your Rust code.
%files -n clippy
%doc src/tools/clippy/{README.md,CHANGELOG.md}
%license src/tools/clippy/LICENSE-{APACHE,MIT}
%{_bindir}/cargo-clippy
%{_bindir}/clippy-driver
#-------------------------------------------------------------------------
%package src
Summary: Sources for the Rust standard library
Group: Development/Rust
BuildArch: noarch
%description src
This package includes source files for the Rust standard library. It may be
useful as a reference for code completion tools in various editors.
%files src
%dir %{rustlibdir}
%{rustlibdir}/src
#-------------------------------------------------------------------------
%package analysis
Summary: Compiler analysis data for the Rust standard library
Group: Development/Rust
Requires: rust-std-static = %{version}-%{release}
%description analysis
This package contains analysis data files produced with rustc's -Zsave-analysis
feature for the Rust standard library. The RLS (Rust Language Server) uses this
data to provide information about the Rust standard library.
%files analysis
%{rustlibdir}/%{rust_triple}/analysis/
#-------------------------------------------------------------------------
%prep
%ifarch %{bootstrap_arches}
%ifarch x86_64
tar xf %{SOURCE1}
%endif
%ifarch %{ix86}
tar xf %{SOURCE2}
%endif
%ifarch aarch64
tar xf %{SOURCE3}
%endif
%ifarch %{riscv}
tar xf %{SOURCE4}
%endif
cd rust-%{bootstrap_rust}-%{rust_triple}
./install.sh --components=cargo,rustc,rust-std-%{rust_triple} \
--prefix=%{local_rust_root} --disable-ldconfig
test -f '%{local_rust_root}/bin/cargo'
test -f '%{local_rust_root}/bin/rustc'
%endif
%setup -qn rustc-%{version}-src
%autopatch -p1
# python3
sed -i.try-py3 -e '/try python2.7/i try python3 "$@"' ./configure
%if %{without bootstrap}
rm -rf src/llvm-project
mkdir -p src/llvm-project/libunwind/
%endif
# Remove other unused vendored libraries
rm -rf vendor/jemalloc-sys/jemalloc/
rm -rf vendor/libz-sys/src/zlib/
rm -rf vendor/libz-sys/src/zlib-ng/
rm -rf vendor/lzma-sys/xz-*/
rm -rf vendor/openssl-src/openssl/
# This only affects the transient rust-installer, but let it use our dynamic xz-libs
sed -i.lzma -e '/LZMA_API_STATIC/d' src/bootstrap/tool.rs
%if %{without llvm_boot} && %{with llvm_static}
# Static linking to distro LLVM needs to add -lffi
# https://github.com/rust-lang/rust/issues/34486
sed -i.ffi -e '$a #[link(name = "ffi")] extern {}' \
compiler/rustc_llvm/src/lib.rs
%endif
# The configure macro will modify some autoconf-related files, which upsets
# cargo when it tries to verify checksums in those files. If we just truncate
# that file list, cargo won't have anything to complain about.
find vendor -name .cargo-checksum.json \
-exec sed -i.uncheck -e 's/"files":{[^}]*}/"files":{ }/' '{}' '+'
# Sometimes Rust sources start with #![...] attributes, and "smart" editors think
# it's a shebang and make them executable. Then brp-mangle-shebangs gets upset...
find -name '*.rs' -type f -perm /111 -exec chmod -v -x '{}' '+'
%build
# Use hardening ldflags.
%if %{with bootstrap}
export PATH="%{local_rust_root}/bin:$PATH"
%ifarch x86_64
%global rustflags -Clink-arg=-Wl,-z,relro,-z,now -L %{rustlibdir}/%{rust_triple}/lib %{!?with_system_llvm:-L %{llvm_path}/%{_lib}}
%else
%global rustflags -Clink-arg=-Wl,-z,relro,-z,now %{!?with_system_llvm:-L %{llvm_path}/%{_lib}}
%endif
%else
%global rustflags -Clink-arg=-Wl,-z,relro,-z,now %{!?with_system_llvm:-L %{llvm_path}/%{_lib}}
%endif
# convince libgit2-sys to use the distro libgit2
export LIBGIT2_SYS_USE_PKG_CONFIG=1
# convince libssh2-sys to use the distro libssh2
export LIBSSH2_SYS_USE_PKG_CONFIG=1
export RUSTFLAGS="%{rustflags}"
export CXXSTDLIB="stdc++"
lib_driver=build/%{rust_triple}/stage1/%{_lib}
export LD_LIBRARY_PATH="$lib_driver:LD_LIBRARY_PATH"
export CC=%{_cc}
export CXX=%{_cxx}
%configure \
--disable-option-checking \
--libdir=%{_libdir} \
--build=%{rust_triple} --host=%{rust_triple} --target=%{rust_triple} \
--python=python3 \
--local-rust-root=%{local_rust_root} \
%if %{without bootstrap}
--llvm-config=%{_llvm_config} \
%endif
%ifarch %{bootstrap_arches}
%{!?with_llvm_boot:--set target.%{rust_triple}.cc="%{_cc}"} \
%{!?with_llvm_boot:--set target.%{rust_triple}.cxx="%{_cxx}"} \
%{!?with_llvm_boot:--set target.%{rust_triple}.ar="%{_ar}"} \
%{!?with_llvm_boot:--set target.%{rust_triple}.ranlib="%{_ranlib}"} \
%ifnarch %{ix86}
%{!?with_llvm_boot:--enable-ninja} \
%endif
%endif
--disable-codegen-tests \
--disable-rpath \
--enable-extended \
--tools=analysis,cargo,clippy,rls,rust-analyzer,rustfmt,src \
--enable-vendor \
--release-channel=stable \
%if %{mdkver} > 201610
--set rust.codegen-units-std=1 \
%endif
--disable-debuginfo \
--disable-debuginfo-only-std \
--disable-debuginfo-tools \
--disable-debuginfo-lines \
%{!?with_llvm_static:--enable-llvm-link-shared} \
--set build.verbose=1 \
--set build.build-stage=2 \
--set build.test-stage=2 \
--set build.doc-stage=2 \
--set build.gdb="%{_bindir}/gdb" \
--disable-use-libcxx \
--set rust.jemalloc=false \
--disable-llvm-static-stdcpp \
--disable-dist-src
python3 ./x.py build
%install
# convince libgit2-sys to use the distro libgit2
export LIBGIT2_SYS_USE_PKG_CONFIG=1
# convince libssh2-sys to use the distro libssh2
export LIBSSH2_SYS_USE_PKG_CONFIG=1
export RUSTFLAGS="%{rustflags}"
DESTDIR=%{buildroot} python3 ./x.py install
# The shared libraries should be executable for debuginfo extraction.
find %{buildroot}%{_libdir} -maxdepth 1 -type f -name '*.so' \
-exec chmod -v +x '{}' '+'
# The libdir libraries are identical to those under rustlib/. It's easier on
# library loading if we keep them in libdir, but we do need them in rustlib/
# to support dynamic linking for compiler plugins, so we'll symlink.
(cd "%{buildroot}%{rustlibdir}/%{rust_triple}/lib" &&
find ../../../../%{_lib} -maxdepth 1 -name '*.so' |
while read lib; do
if [ -f "${lib##*/}" ]; then
# make sure they're actually identical!
cmp "$lib" "${lib##*/}"
ln -v -f -s -t . "$lib"
fi
done)
# Remove installer artifacts (manifests, uninstall scripts, etc.)
find %{buildroot}%{rustlibdir} -maxdepth 1 -type f -exec rm -v '{}' '+'
# Remove backup files from %%configure munging
find %{buildroot}%{rustlibdir} -type f -name '*.orig' -exec rm -v '{}' '+'
# https://fedoraproject.org/wiki/Changes/Make_ambiguous_python_shebangs_error
# We don't actually need to ship any of those python scripts in rust-src anyway.
find %{buildroot}%{rustlibdir}/src -type f -name '*.py' -exec rm -v '{}' '+'
# Remove unwanted documentation files (we already package them)
rm -f %{buildroot}%{_docdir}/%{name}/README.md
rm -f %{buildroot}%{_docdir}/%{name}/COPYRIGHT
rm -f %{buildroot}%{_docdir}/%{name}/LICENSE
rm -f %{buildroot}%{_docdir}/%{name}/LICENSE-APACHE
rm -f %{buildroot}%{_docdir}/%{name}/LICENSE-MIT
rm -f %{buildroot}%{_docdir}/%{name}/LICENSE-THIRD-PARTY
rm -f %{buildroot}%{_docdir}/%{name}/*.old
# Delete the HTML documentation
rm -rf %{buildroot}%{_docdir}/%{name}/html
# Create the path for crate-devel packages
mkdir -p %{buildroot}%{_datadir}/cargo/registry
%if %{without lldb}
rm -f %{buildroot}%{_bindir}/rust-lldb
rm -f %{buildroot}%{rustlibdir}/etc/lldb_*
%endif
# We don't want Rust copies of LLVM tools (rust-lld, rust-llvm-dwp)
rm -f %{buildroot}%{rustlibdir}/%{rust_triple}/bin/rust-ll*
%check
export PATH="%{buildroot}%{_bindir}:$PATH"
export LD_LIBRARY_PATH="%{buildroot}%{_libdir}:LD_LIBRARY_PATH"
readelf -d %{buildroot}%{_libdir}/librustc_driver* | grep LLVM || :
%{buildroot}%{_bindir}/rustc -V
%{buildroot}%{_bindir}/cargo -V
mkdir -p projects/hello_world
pushd projects/hello_world
cat > main.rs <<EOF
fn main() {
println!("Hello, world!");
}
EOF
rustc main.rs
./main
popd