From ebd24b39176265e2d001250dc279293a23b6a79c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 2 Jun 2021 15:27:34 -0700 Subject: [PATCH] Add rust-std-static-wasm32-unknown-unknown. This change is partly based on an older pull request: https://src.fedoraproject.org/rpms/rust/pull-request/6 Co-authored-by: Ivan Mironov --- ...-Use-lld-provided-by-system-for-wasm.patch | 26 ++++++ rust.spec | 89 +++++++++++++++++-- 2 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 0001-Use-lld-provided-by-system-for-wasm.patch diff --git a/0001-Use-lld-provided-by-system-for-wasm.patch b/0001-Use-lld-provided-by-system-for-wasm.patch new file mode 100644 index 0000000..ff126cc --- /dev/null +++ b/0001-Use-lld-provided-by-system-for-wasm.patch @@ -0,0 +1,26 @@ +From 1a6307bbf7972aa2ce89a213bad6f26b6325a59c Mon Sep 17 00:00:00 2001 +From: Ivan Mironov +Date: Sun, 8 Dec 2019 17:23:08 +0500 +Subject: [PATCH] Use lld provided by system for wasm + +--- + compiler/rustc_target/src/spec/wasm32_base.rs | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/compiler/rustc_target/src/spec/wasm32_base.rs b/compiler/rustc_target/src/spec/wasm32_base.rs +index bfef3d37228f..0ecb29248fe2 100644 +--- a/compiler/rustc_target/src/spec/wasm32_base.rs ++++ b/compiler/rustc_target/src/spec/wasm32_base.rs +@@ -97,8 +97,7 @@ pub fn options() -> TargetOptions { + // arguments just yet + limit_rdylib_exports: false, + +- // we use the LLD shipped with the Rust toolchain by default +- linker: Some("rust-lld".to_owned()), ++ linker: Some("lld".to_owned()), + lld_flavor: LldFlavor::Wasm, + + // No need for indirection here, simd types can always be passed by +-- +2.31.1 + diff --git a/rust.spec b/rust.spec index a084245..b508e36 100644 --- a/rust.spec +++ b/rust.spec @@ -17,6 +17,15 @@ # Only the specified arches will use bootstrap binaries. #global bootstrap_arches %%{rust_arches} +# Define a space-separated list of targets to ship rust-std-static-$triple for +# cross-compilation. The packages are noarch, but they're not fully +# reproducible between hosts, so only x86_64 actually builds it. +%ifarch x86_64 +%if 0%{?fedora} +%global cross_targets wasm32-unknown-unknown +%endif +%endif + # Using llvm-static may be helpful as an opt-in, e.g. to aid LLVM rebases. %bcond_with llvm_static @@ -71,6 +80,9 @@ Source0: https://static.rust-lang.org/dist/%{rustc_package}.tar.xz # https://github.com/rust-lang/rust/issues/80810#issuecomment-781784032 Patch1: 0001-Revert-Auto-merge-of-79547.patch +# By default, rust tries to use "rust-lld" as a linker for WebAssembly. +Patch2: 0001-Use-lld-provided-by-system-for-wasm.patch + ### RHEL-specific patches below ### # Disable cargo->libgit2->libssh2 on RHEL, as it's not approved for FIPS (rhbz1732949) @@ -235,6 +247,19 @@ Requires: /usr/bin/cc %endif %endif +# We're going to override --libdir when configuring to get rustlib into a +# common path, but we'll fix the shared libraries during install. +%global common_libdir %{_prefix}/lib +%global rustlibdir %{common_libdir}/rustlib + +%if %defined cross_targets +# brp-strip-static-archive breaks the archive index for wasm +%global __os_install_post \ +%__os_install_post \ +find %{buildroot}%{rustlibdir} -type f -path '*/wasm*/lib/*.rlib' -exec ranlib '{}' ';' \ +%{nil} +%endif + %description Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. @@ -249,6 +274,32 @@ Summary: Standard library for Rust This package includes the standard libraries for building applications written in Rust. +%if %defined cross_targets +%{lua: do + for triple in string.gmatch(rpm.expand("%{cross_targets}"), "%S+") do + local requires = rpm.expand("Requires: rust = %{version}-%{release}") + if string.sub(triple, 1, 4) == "wasm" then + requires = requires .. "\nRequires: lld >= 8.0" + end + local subs = { + triple = triple, + requires = requires, + } + local s = string.gsub([[ +%package std-static-{{triple}} +Summary: Standard library for Rust +BuildArch: noarch +{{requires}} + +%description std-static-{{triple}} +This package includes the standard libraries for building applications +written in Rust for the {{triple}} target. +]], "{{(%w+)}}", subs) + print(s) + end +end} +%endif + %package debugger-common Summary: Common debugger pretty printers for Rust @@ -406,6 +457,7 @@ test -f '%{local_rust_root}/bin/rustc' %setup -q -n %{rustc_package} %patch1 -p1 +%patch2 -p1 %if %with disabled_libssh2 %patch100 -p1 @@ -491,11 +543,6 @@ find -name '*.rs' -type f -perm /111 -exec chmod -v -x '{}' '+' %build export %{rust_env} -# We're going to override --libdir when configuring to get rustlib into a -# common path, but we'll fix the shared libraries during install. -%global common_libdir %{_prefix}/lib -%global rustlibdir %{common_libdir}/rustlib - %ifarch %{arm} %{ix86} s390x # full debuginfo is exhausting memory; just do libstd for now # https://github.com/rust-lang/rust/issues/45854 @@ -540,12 +587,23 @@ fi %{python} ./x.py build -j "$ncpus" --stage 2 %{python} ./x.py doc --stage 2 +%if %defined cross_targets +for triple in %{cross_targets}; do + %{python} ./x.py build --stage 2 --target=$triple std +done +%endif %install export %{rust_env} DESTDIR=%{buildroot} %{python} ./x.py install +%if %defined cross_targets +for triple in %{cross_targets}; do + DESTDIR=%{buildroot} %{python} ./x.py install --target=$triple std +done +%endif + # Make sure the shared libraries are in the proper libdir %if "%{_libdir}" != "%{common_libdir}" mkdir -p %{buildroot}%{_libdir} @@ -648,6 +706,26 @@ export %{rust_env} %{rustlibdir}/%{rust_triple}/lib/*.rlib +%if %defined cross_targets +%{lua: do + for triple in string.gmatch(rpm.expand("%{cross_targets}"), "%S+") do + local subs = { + triple = triple, + rustlibdir = rpm.expand("%{rustlibdir}"), + } + local s = string.gsub([[ +%files std-static-{{triple}} +%dir {{rustlibdir}} +%dir {{rustlibdir}}/{{triple}} +%dir {{rustlibdir}}/{{triple}}/lib +{{rustlibdir}}/{{triple}}/lib/*.rlib +]], "{{(%w+)}}", subs) + print(s) + end +end} +%endif + + %files debugger-common %dir %{rustlibdir} %dir %{rustlibdir}/etc @@ -733,6 +811,7 @@ export %{rust_env} %changelog * Wed Jun 02 2021 Josh Stone - 1.52.1-2 - Set rust.codegen-units-std=1 for all targets again. +- Add rust-std-static-wasm32-unknown-unknown. * Mon May 10 2021 Josh Stone - 1.52.1-1 - Update to 1.52.1.