2 # - consider a rust-std package containing .../rustlib/$target
3 # This might allow multilib cross-compilation to work naturally.
4 # - package additional tools
7 %bcond_with bootstrap # bootstrap using precompiled binaries
8 %bcond_with full_debuginfo # full debuginfo vs only std debuginfo (full takes gigabytes of memory to build)
9 %bcond_without system_llvm # system LLVM
10 %bcond_with tests # build without tests
12 # The channel can be stable, beta, or nightly
13 %define channel stable
15 %if "%{channel}" == "stable"
16 %define rustc_package rustc-%{version}-src
18 %define rustc_package rustc-%{channel}-src
21 # To bootstrap from scratch, set the channel and date from src/stage0.json
22 # e.g. 1.10.0 wants rustc: 1.9.0-2016-05-24
23 # or nightly wants some beta-YYYY-MM-DD
24 %define bootstrap_rust 1.76.0
25 %define bootstrap_cargo %{bootstrap_rust}
26 %define bootstrap_date 2024-02-08
32 %if %{without full_debuginfo}
33 %define _enable_debug_packages 0
36 Summary: The Rust Programming Language
37 Summary(pl.UTF-8): Język programowania Rust
41 # Licenses: (rust itself) and (bundled libraries)
42 License: (Apache v2.0 or MIT) and (BSD and ISC and MIT)
43 Group: Development/Languages
44 Source0: https://static.rust-lang.org/dist/%{rustc_package}.tar.xz
45 # Source0-md5: 7df442945fb2e32cbccd45a7faa3a5e1
46 Source1: https://static.rust-lang.org/dist/%{bootstrap_date}/rust-%{bootstrap_rust}-x86_64-unknown-linux-gnu.tar.xz
47 # Source1-md5: 5f9b4a89f2123e044cc46c7659dfc4fb
48 Source2: https://static.rust-lang.org/dist/%{bootstrap_date}/rust-%{bootstrap_rust}-i686-unknown-linux-gnu.tar.xz
49 # Source2-md5: fe76aea1be1894a9b48e1bea614038c6
50 Source3: https://static.rust-lang.org/dist/%{bootstrap_date}/rust-%{bootstrap_rust}-aarch64-unknown-linux-gnu.tar.xz
51 # Source3-md5: b4741f9574bd432e2370c91d56d17ae0
52 Source4: https://static.rust-lang.org/dist/%{bootstrap_date}/rust-%{bootstrap_rust}-arm-unknown-linux-gnueabihf.tar.xz
53 # Source4-md5: de71c41731df9187d4cca2f61359be28
54 Source5: https://static.rust-lang.org/dist/%{bootstrap_date}/rust-%{bootstrap_rust}-armv7-unknown-linux-gnueabihf.tar.xz
55 # Source5-md5: 80c933da93013752d852f6f1280d7e12
56 URL: https://www.rust-lang.org/
58 BuildRequires: cmake >= 3.4.3
60 %ifarch %{arm} %{mips32} %{ppc}
61 BuildRequires: libatomic-devel
63 # make check needs "ps" for src/test/run-pass/wait-forked-but-failed-child.rs
65 BuildRequires: python3
66 BuildRequires: python3-modules
67 BuildRequires: rpm-build >= 4.6
68 BuildRequires: rpmbuild(macros) >= 1.752
70 BuildRequires: curl-devel
71 BuildRequires: libgit2-devel >= 1.7.2
72 BuildRequires: libstdc++-devel
73 %if %{with system_llvm}
74 BuildRequires: llvm >= 16.0
75 BuildRequires: llvm-devel >= 16.0
77 BuildRequires: openssl-devel >= 1.0.1
78 BuildRequires: tar >= 1:1.22
80 BuildRequires: xz-devel
81 BuildRequires: zlib-devel
83 %if %{without bootstrap}
84 BuildRequires: %{name} >= %{bootstrap_rust}
85 BuildRequires: cargo >= %{bootstrap_cargo}
86 BuildConflicts: %{name} > %{version}
89 BuildRequires: glibc-devel(x86-64)
90 BuildRequires: glibc-devel(x86-x32)
91 %if "%{_host_cpu}" == "x86_64"
92 # building on x86_64 host with --target x32-pld-linux
93 BuildRequires: curl-devel
94 BuildRequires: gcc-multilib-x32
95 BuildRequires: libgit2-devel >= 1.7.2
96 BuildRequires: libstdc++-devel
97 %{?with_system_llvm:BuildRequires: llvm-devel >= 16.0}
98 BuildRequires: openssl-devel >= 1.0.1
99 BuildRequires: xz-devel
100 BuildRequires: zlib-devel
102 # building x86_64-hosted crosscompiler on x32 host
103 BuildRequires: curl-devel(x86-64)
104 BuildRequires: curl-devel(x86-x32)
105 BuildRequires: gcc-multilib-64
106 BuildRequires: libgit2-devel(x86-64) >= 1.7.2
107 BuildRequires: libgit2-devel(x86-x32) >= 1.7.2
108 BuildRequires: libstdc++-multilib-64-devel
109 %if %{with system_llvm}
110 BuildRequires: llvm-devel(x86-64) >= 16.0
111 BuildRequires: llvm-devel(x86-x32) >= 16.0
113 BuildRequires: openssl-devel(x86-64)
114 BuildRequires: openssl-devel(x86-x32)
115 BuildRequires: xz-devel(x86-64)
116 BuildRequires: xz-devel(x86-x32)
117 BuildRequires: zlib-devel(x86-64)
118 BuildRequires: zlib-devel(x86-x32)
121 # The C compiler is needed at runtime just for linking. Someday rustc might
122 # invoke the linker directly, and then we'll only need binutils.
123 # https://github.com/rust-lang/rust/issues/11937
125 Requires: %{name}-std%{?_isa} = %{version}-%{release}
127 Requires: %{name}-std(x86-64) = %{version}-%{release}
128 Requires: gcc-multilib-64
130 Obsoletes: rust-analysis < 1.69.0
131 # Only x86_64 and i686 are Tier 1 platforms at this time.
132 # x32 is Tier 2, only rust-std is available (no rustc or cargo).
133 # https://doc.rust-lang.org/nightly/rustc/platform-support.html
134 ExclusiveArch: %{x8664} %{ix86} x32 aarch64 armv6hl armv7hl armv7hnl
135 BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
138 %define rust_triple x86_64-unknown-linux-gnux32
139 %define rust_host_triple x86_64-unknown-linux-gnu
140 %define rust_bootstrap_triple x86_64-unknown-linux-gnu
141 # libs in _libdir are x86_64 64bit
143 %define _libdir %{_prefix}/lib64
146 %define rust_triple arm-unknown-linux-gnueabihf
147 %define rust_host_triple %{rust_triple}
148 %define rust_bootstrap_triple %{rust_triple}
150 %ifarch armv7hl armv7hnl
151 %define rust_triple armv7-unknown-linux-gnueabihf
152 %define rust_host_triple %{rust_triple}
153 %define rust_bootstrap_triple %{rust_triple}
154 %define rust_suppl_targets thumbv7neon-unknown-linux-gnueabihf
156 %define rust_triple %{_target_cpu}-unknown-linux-gnu
157 %define rust_host_triple %{rust_triple}
158 %define rust_bootstrap_triple %{rust_triple}
163 %define rust_targets %rust_triple %{?rust_suppl_targets}
165 %if %{without bootstrap}
166 %define local_rust_root %{_prefix}
168 %define bootstrap_root rust-%{bootstrap_rust}-%{rust_bootstrap_triple}
169 %define local_rust_root %{_builddir}/%{rustc_package}/%{bootstrap_root}
172 # We're going to override --libdir when configuring to get rustlib into a
173 # common path, but we'll fix the shared libraries during install.
174 # Without this ugly hack, rust would not be able to build itself
175 # for non-bootstrap build, lib64 is just too complicated for it.
176 %define common_libdir %{_prefix}/lib
177 %define rustlibdir %{common_libdir}/rustlib
179 # once_call/once_callable non-function libstdc++ symbols
180 %define skip_post_check_so 'librustc.*llvm.*\.so.*'
182 # ALL Rust libraries are private, because they don't keep an ABI.
183 %define _noautoreqfiles lib.*-[[:xdigit:]]{8}[.]so.*
184 %define _noautoprovfiles lib.*-[[:xdigit:]]{8}[.]so.*
190 %{?__jobs:CARGO_BUILD_JOBS=%__jobs }%{__python3} ./x.py "$cmd" %{?__jobs:-j %__jobs} "$@"; \
195 Rust is a systems programming language that runs blazingly fast,
196 prevents segfaults, and guarantees thread safety.
198 This package includes the Rust compiler, standard library, and
199 documentation generator.
201 %description -l pl.UTF-8
202 Rust to systemowy język programowania działający bardzo szybko,
203 zapobiegający naruszeniom ochrony pamięci i gwarantujący
204 bezpieczną wielowątkowość.
207 Summary: Standard library for Rust
208 Summary(pl.UTF-8): Standardowa biblioteka Rusta
209 Group: Development/Tools
210 Requires: %{name} = %{version}-%{release}
213 Standard library for Rust.
215 %description std -l pl.UTF-8
216 Standardowa biblioteka Rusta.
219 Summary: Implementation of Language Server Protocol for Rust
220 Summary(pl.UTF-8): Implementacja Language Server Protocol dla Rusta
221 Group: Development/Tools
222 Requires: %{name} = %{version}-%{release}
223 Obsoletes: rust-rls < 1.65.0
225 %description analyzer
226 Implementation of Language Server Protocol for Rust.
228 %description analyzer -l pl.UTF-8
229 Implementacja Language Server Protocol dla Rusta.
231 %package debugger-common
232 Summary: Common debugger pretty printers for Rust
233 Summary(pl.UTF-8): Narzędzia wypisujące struktury Rusa wspólne dla różnych debuggerów
234 Group: Development/Debuggers
237 %description debugger-common
238 This package includes the common functionality for rust-gdb and
241 %description debugger-common -l pl.UTF-8
242 Ten pakiet zawiera wspólny kod dla pakietów rust-gdb i rust-lldb.
245 Summary: GDB pretty printers for Rust
246 Summary(pl.UTF-8): Ładne wypisywanie struktur Rusta w GDB
247 Group: Development/Debuggers
248 Requires: %{name}-debugger-common = %{version}-%{release}
253 This package includes the rust-gdb script, which allows easier
254 debugging of Rust programs.
256 %description gdb -l pl.UTF-8
257 Ten pakiet zawiera skrypt rust-gdb, pozwalający na łatwiejsze
258 odpluskwianie programów w języku Rust.
261 Summary: LLDB pretty printers for Rust
262 Summary(pl.UTF-8): Ładne wypisywanie struktur Rusta w LLDB
263 Group: Development/Debuggers
264 Requires: %{name}-debugger-common = %{version}-%{release}
269 This package includes the rust-lldb script, which allows easier
270 debugging of Rust programs.
272 %description lldb -l pl.UTF-8
273 Ten pakiet zawiera skrypt rust-lldb, pozwalający na łatwiejsze
274 odpluskwianie programów w języku Rust.
277 Summary: Documentation for Rust
278 Summary(pl.UTF-8): Dokumentacja do Rusta
283 This package includes HTML documentation for the Rust programming
284 language and its standard library.
286 %description doc -l pl.UTF-8
287 Ten pakiet zawiera dokumentację w formacie HTML do języka
288 programowania Rust i jego biblioteki standardowej.
291 Summary: Rust's package manager and build tool
292 Summary(pl.UTF-8): Zarządca pakietów i narzędzie do budowania
293 Group: Development/Tools
294 Requires: %{name}%{?_isa}
296 %description -n cargo
297 Cargo is a tool that allows Rust projects to declare their various
298 dependencies and ensure that you'll always get a repeatable build.
300 %description -n cargo -l pl.UTF-8
301 Cargo to narzędzie pozwalające projektom w języku Rust deklarować ich
302 zależności i zapewniające powtarzalność procesu budowania.
304 %package -n bash-completion-cargo
305 Summary: Bash completion for cargo command
306 Summary(pl.UTF-8): Bashowe dopełnianie parametrów polecenia cargo
307 Group: Applications/Shells
308 Requires: %{name} = %{version}-%{release}
309 Requires: bash-completion
312 %description -n bash-completion-cargo
313 Bash completion for cargo command.
315 %description -n bash-completion-cargo -l pl.UTF-8
316 Bashowe dopełnianie parametrów polecenia cargo.
318 %package -n zsh-completion-cargo
319 Summary: Zsh completion for cargo command
320 Summary(pl.UTF-8): Dopełnianie parametrów polecenia cargo w powłoce Zsh
321 Group: Applications/Shells
322 Requires: %{name} = %{version}-%{release}
326 %description -n zsh-completion-cargo
327 Zsh completion for cargo command.
329 %description -n zsh-completion-cargo -l pl.UTF-8
330 Dopełnianie parametrów polecenia cargo w powłoce Zsh.
333 %setup -q -n %{rustc_package}
335 %if %{with bootstrap}
348 %ifarch armv7hl armv7hnl
351 %{__mv} %{bootstrap_root} %{bootstrap_root}-root
352 %{bootstrap_root}-root/install.sh \
353 --components=cargo,rustc,rust-std-%{rust_bootstrap_triple} \
354 --prefix=%{local_rust_root} \
356 test -f %{local_rust_root}/bin/cargo
357 test -f %{local_rust_root}/bin/rustc
361 # We're disabling jemalloc, but rust-src still wants it.
362 #%{__rm} -r src/jemalloc
363 %if %{with system_llvm}
364 %{__rm} -r src/llvm-project
365 mkdir -p src/llvm-project/libunwind
368 # rust-gdb has hardcoded SYSROOT/lib -- let's make it noarch
369 sed -i -e 's#DIRECTORY=".*"#DIRECTORY="%{_datadir}/%{name}/etc"#' \
372 # cargo has hardcoded libexec path - honour rpm _libexecdir
373 %if "%{_libexecdir}" != "%{_prefix}/libexec"
374 suffix="%(echo "%{_libexecdir}" | %{__sed} -e 's,^%{_prefix}/,,')"
375 %{__sed} -i -e 's,"libexec","'${suffix}'",' \
376 src/bootstrap/dist.rs
379 # The configure macro will modify some autoconf-related files, which upsets
380 # cargo when it tries to verify checksums in those files. If we just truncate
381 # that file list, cargo won't have anything to complain about.
382 find vendor -name .cargo-checksum.json \
383 -exec sed -i.uncheck -e 's/"files":{[^}]*}/"files":{ }/' '{}' '+'
387 export CXX="%{__cxx}"
390 --build=%{rust_bootstrap_triple} \
391 --host=%{rust_host_triple} \
392 --target="%(echo %rust_targets | tr ' ' ,)" \
393 --libdir=%{common_libdir} \
394 --disable-codegen-tests \
395 --disable-debuginfo-lines \
396 %if %{with full_debuginfo}
397 --disable-debuginfo-only-std \
400 --enable-debuginfo-only-std \
401 --disable-debuginfo \
404 --disable-option-checking \
407 --enable-llvm-link-shared \
409 --local-rust-root=%{local_rust_root} \
410 --llvm-root=%{_prefix} \
411 --release-channel=%{channel} \
412 --set=llvm.static-libstdcpp=false \
413 --set=build.optimized-compiler-builtins=false
415 export RUST_BACKTRACE=full
418 %{?with_tests:%x_py test}
421 rm -rf $RPM_BUILD_ROOT
424 export CXX="%{__cxx}"
426 export DESTDIR=$RPM_BUILD_ROOT
429 # Make sure the shared libraries are in the proper libdir
430 %if "%{_libdir}" != "%{common_libdir}"
431 mkdir -p %{buildroot}%{_libdir}
432 find $RPM_BUILD_ROOT%{common_libdir} -maxdepth 1 -type f -name '*.so' \
433 -exec mv -v -t $RPM_BUILD_ROOT%{_libdir} '{}' '+'
436 # The shared libraries should be executable for debuginfo extraction.
437 find $RPM_BUILD_ROOT%{_libdir}/ -type f -name '*.so' -exec chmod -v +x '{}' '+'
439 # The libdir libraries are identical to those under rustlib/. It's easier on
440 # library loading if we keep them in libdir, but we do need them in rustlib/
441 # to support dynamic linking for compiler plugins, so we'll symlink.
442 for rust_target in %rust_targets; do
443 for l in libstd libtest ; do
444 liblib=$RPM_BUILD_ROOT%{_libdir}/${l}-*.so
445 libstd=$RPM_BUILD_ROOT%{rustlibdir}/${rust_target}/lib/${l}-*.so
446 if [ "$(basename ${liblib})" = "$(basename ${libstd})" ]; then
447 ln -vfsr ${libstd} $RPM_BUILD_ROOT%{_libdir}/
452 # Remove installer artifacts (manifests, uninstall scripts, etc.)
453 find $RPM_BUILD_ROOT%{rustlibdir}/ -maxdepth 1 -type f -exec rm -v '{}' '+'
455 # FIXME: __os_install_post will strip the rlibs
456 # -- should we find a way to preserve debuginfo?
458 # Remove unwanted documentation files (we already package them)
459 %{__rm} $RPM_BUILD_ROOT%{_docdir}/%{name}/README.md
460 %{__rm} $RPM_BUILD_ROOT%{_docdir}/%{name}/COPYRIGHT
461 %{__rm} $RPM_BUILD_ROOT%{_docdir}/%{name}/LICENSE-APACHE
462 %{__rm} $RPM_BUILD_ROOT%{_docdir}/%{name}/LICENSE-MIT
464 # Sanitize the HTML documentation
465 find $RPM_BUILD_ROOT%{_docdir}/%{name}/html -empty -delete
466 find $RPM_BUILD_ROOT%{_docdir}/%{name}/html -type f -exec chmod -x '{}' '+'
468 # Move rust-gdb's python scripts so they're noarch
469 install -d $RPM_BUILD_ROOT%{_datadir}/%{name}
470 %{__mv} $RPM_BUILD_ROOT%{rustlibdir}/etc $RPM_BUILD_ROOT%{_datadir}/%{name}
472 # We don't need stdlib source
473 %{__rm} -r $RPM_BUILD_ROOT%{rustlibdir}/src
475 # Create the path for crate-devel packages
476 install -d $RPM_BUILD_ROOT%{_datadir}/cargo/registry
479 rm -rf $RPM_BUILD_ROOT
481 %post -p /sbin/ldconfig
482 %postun -p /sbin/ldconfig
485 %defattr(644,root,root,755)
486 %doc COPYRIGHT LICENSE-APACHE LICENSE-MIT README.md
487 %attr(755,root,root) %{_bindir}/rust-demangler
488 %attr(755,root,root) %{_bindir}/rustc
489 %attr(755,root,root) %{_bindir}/rustdoc
490 %attr(755,root,root) %{_bindir}/rustfmt
491 %attr(755,root,root) %{_libdir}/librustc_driver-*.so
492 %attr(755,root,root) %{_libdir}/libstd-*.so
493 %attr(755,root,root) %{_libdir}/libtest-*.so
494 %{_mandir}/man1/rustc.1*
495 %{_mandir}/man1/rustdoc.1*
499 %defattr(644,root,root,755)
500 %(for rust_target in %rust_targets; do
502 %dir %{rustlibdir}/$rust_target
503 %dir %{rustlibdir}/$rust_target/lib
504 %attr(755,root,root) %{rustlibdir}/$rust_target/lib/*.so
505 %{rustlibdir}/$rust_target/lib/*.rlib
511 %defattr(644,root,root,755)
512 %attr(755,root,root) %{_bindir}/rust-analyzer
513 %attr(755,root,root) %{_libexecdir}/rust-analyzer-proc-macro-srv
515 %files debugger-common
516 %defattr(644,root,root,755)
517 %dir %{_datadir}/%{name}
518 %dir %{_datadir}/%{name}/etc
519 %{_datadir}/%{name}/etc/lldb_commands
520 %{_datadir}/%{name}/etc/rust_types.py
523 %defattr(644,root,root,755)
524 %attr(755,root,root) %{_bindir}/rust-lldb
525 %{_datadir}/%{name}/etc/lldb_*.py*
528 %defattr(644,root,root,755)
529 %attr(755,root,root) %{_bindir}/rust-gdb
530 %attr(755,root,root) %{_bindir}/rust-gdbgui
531 %{_datadir}/%{name}/etc/gdb_*.py*
534 %defattr(644,root,root,755)
535 %dir %{_docdir}/%{name}
536 %doc %{_docdir}/%{name}/html
539 %defattr(644,root,root,755)
540 %attr(755,root,root) %{_bindir}/cargo
541 %attr(755,root,root) %{_bindir}/cargo-clippy
542 %attr(755,root,root) %{_bindir}/cargo-fmt
543 %attr(755,root,root) %{_bindir}/clippy-driver
544 %{_mandir}/man1/cargo*.1*
545 %dir %{_datadir}/cargo
546 %dir %{_datadir}/cargo/registry
548 %files -n bash-completion-cargo
549 %defattr(644,root,root,755)
550 %{_sysconfdir}/bash_completion.d/cargo
552 %files -n zsh-completion-cargo
553 %defattr(644,root,root,755)
554 %{zsh_compdir}/_cargo