From 9490476bd131f63056fe5b9d88e9eb36f64531fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 14 Feb 2022 22:25:29 +0100 Subject: [PATCH] Include linker flags for package note in %build_rustflags This was tested in copr [1]: 96 packages succeeded: - rust-afterburn rust-alacritty rust-askalono-cli rust-assert_cli rust-base100 rust-bat rust-below rust-bindgen rust-blsctl rust-bodhi-cli rust-bootupd rust-btrd rust-cargo-bloat rust-cargo-c rust-cargo-insta rust-cargo-readme rust-cbindgen rust-choosier rust-comrak rust-copydeps rust-coreos-installer rust-count-zeroes rust-dbus-codegen rust-desed rust-diskonaut rust-docopt rust-drg rust-dua-cli rust-dutree rust-edit rust-elfcat rust-exa rust-fd-find rust-fedora-coreos-pinger rust-fedora-update-feedback rust-fluent-syntax rust-git-delta rust-gitui rust-handlebars rust-heatseeker rust-helvum rust-hexyl rust-hyperfine rust-jql rust-just rust-lalrpop rust-leb128 rust-libbpf-cargo rust-libslirp rust-lscolors rust-lsd rust-oxipng rust-packaging rust-peg0.5 rust-permutate rust-pleaser rust-pommes rust-pretty-git-prompt rust-procs rust-protobuf-codegen rust-pulldown-cmark rust-python-launcher rust-rav1e rust-rd-agent rust-rd-hashd rust-read-process-memory rust-resctl-bench rust-resctl-demo rust-ripgrep rust-rpick rust-rudo rust-rustbus rust-rustdoc-stripper rust-rustfilt rust-sass-rs rust-sd rust-semver-parser rust-sequoia-keyring-linter rust-sequoia-sop rust-sequoia-sq rust-sequoia-sqv rust-sevctl rust-sha1collisiondetection rust-silver rust-skim rust-ssh-key-dir rust-starship rust-subprocess rust-system76_ectool rust-tealdeer rust-termbg rust-tokei rust-varlink-cli rust-varlink_generator rust-weezl rust-ybaas rust-yubibomb rust-zincati rust-zopfli rust-zoxide rust-zram-generator 11 failures: - rust-bootupd: partial architecture support - rust-cargo-c: compilation failure on one architecture - rust-oxipng: partial architecture support - rust-sevctl: partial architecture support - rust-cargo-edit: nothing provides requested (crate(toml_edit/default) >= 0.2.0 with crate(toml_edit/default) < 0.3.0~) - rust-ffsend: nothing provides requested (crate(version-compare/default) >= 0.1.0 with crate(version-compare/default) < 0.2.0~) - rust-image-roll: nothing provides requested (crate(infer/default) >= 0.6.0 with crate(infer/default) < 0.7.0~) - rust-inferno: nothing provides requested (crate(assert_cmd/default) >= 1.0.0 with crate(assert_cmd/default) < 2.0.0~) - rust-navi: compilation erros (releted to clap version?) - rust-rbspy: compilation erros (releted to nix version?) - rust-sequoia-octopus-librnp: cannot find function `thread_rng` in crate `rand` - rust-sevctl: copr build timeout [1] https://copr.fedorainfracloud.org/coprs/zbyszek/rust-package-notes/builds/ --- 168.patch | 34 +++++++++++++++++++++++++ 179.patch | 61 +++++++++++++++++++++++++++++++++++++++++++++ rust-packaging.spec | 2 ++ 3 files changed, 97 insertions(+) create mode 100644 168.patch create mode 100644 179.patch diff --git a/168.patch b/168.patch new file mode 100644 index 0000000..acef049 --- /dev/null +++ b/168.patch @@ -0,0 +1,34 @@ +From f1be3a0d4d2df6497d46f627cc54ce8450da8699 Mon Sep 17 00:00:00 2001 +From: Aleksei Bavshin +Date: Dec 06 2021 06:20:52 +0000 +Subject: macros: pass CFLAGS/CXXFLAGS to the processes started by cargo + + +This is mainly targeted to the crates using `rust-cc`, where we want to +apply system-wide compiler flags when invoking the compiler. `cc` +supports CFLAGS and CXXFLAGS, but we never set those. +Defining that per project is not possible, as we have no way to inherit +any build context from a dependency package. + +Possibly also affects: `bindgen`, `cxx`, any other crate that invokes +the C/C++ compiler and passes the CFLAGSS + +--- + +diff --git a/data/macros.cargo b/data/macros.cargo +index 0a68998..07fcb56 100644 +--- a/data/macros.cargo ++++ b/data/macros.cargo +@@ -22,6 +22,11 @@ rustc = "%{__rustc}"\ + rustdoc = "%{__rustdoc}"\ + rustflags = %{__global_rustflags_toml}\ + \ ++[env]\ ++CFLAGS = "%{build_cflags}"\ ++CXXFLAGS = "%{build_cxxflags}"\ ++LDFLAGS = "%{build_ldflags}"\ ++\ + [install]\ + root = "%{buildroot}%{_prefix}"\ + \ + diff --git a/179.patch b/179.patch new file mode 100644 index 0000000..25c3b80 --- /dev/null +++ b/179.patch @@ -0,0 +1,61 @@ +From 0131b4e28aca1e036d1d089a17553d6378657e07 Mon Sep 17 00:00:00 2001 +From: Zbigniew Jędrzejewski-Szmek +Date: Feb 15 2022 09:59:42 +0000 +Subject: Include linker flags for package note in %build_rustflags + + +%build_rustflags was used in %cargo_prep, which is executed in %prep, +when %buildsubdir is not set yet. To avoid this, insertion of flags is +moved to an environment variable that is set for %cargo_build and +%cargo_test. + +The linker flag gets passed to rustc, and resulting binaries seem to have +note as expected. + +--- + +diff --git a/data/macros.cargo b/data/macros.cargo +index 07fcb56..05f5eb2 100644 +--- a/data/macros.cargo ++++ b/data/macros.cargo +@@ -4,7 +4,7 @@ + # it never writes to ~/.cargo during rpmbuild. + # We also need RUSTC_BOOTSTRAP since we use -Z avoid-dev-deps + # until it gets stabilized: https://github.com/rust-lang/cargo/issues/5133 +-%__cargo %{_bindir}/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 %{_bindir}/cargo ++%__cargo %{_bindir}/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 RUSTFLAGS='%{build_rustflags}' %{_bindir}/cargo + %__cargo_common_opts %{?_smp_mflags} -Z avoid-dev-deps + %__cargo_inspector %{_bindir}/cargo-inspector + +@@ -20,7 +20,6 @@ cat > .cargo/config << EOF \ + [build]\ + rustc = "%{__rustc}"\ + rustdoc = "%{__rustdoc}"\ +-rustflags = %{__global_rustflags_toml}\ + \ + [env]\ + CFLAGS = "%{build_cflags}"\ +@@ -61,6 +60,7 @@ EOF\ + + %cargo_build(naf:) \ + %{shrink:\ ++ RUSTFLAGS='%{build_rustflags}' \ + %{__cargo} build \ + %{__cargo_common_opts} \ + --release \ +diff --git a/data/macros.rust b/data/macros.rust +index 7377f92..0940d06 100644 +--- a/data/macros.rust ++++ b/data/macros.rust +@@ -5,7 +5,9 @@ + %build_rustflags %{shrink: + -Copt-level=3 + -Cdebuginfo=2 +- -Clink-arg=-Wl,-z,relro,-z,now ++ -Clink-arg=-Wl,-z,relro ++ -Clink-arg=-Wl,-z,now ++ %{?_package_note_file:-Clink-arg=-Wl,-dT,%{_package_note_file}} + -Ccodegen-units=1 + --cap-lints=warn + } + diff --git a/rust-packaging.spec b/rust-packaging.spec index d15feb6..8fd7417 100644 --- a/rust-packaging.spec +++ b/rust-packaging.spec @@ -10,6 +10,8 @@ Summary: RPM macros for building Rust packages on various architectures License: MIT URL: https://pagure.io/fedora-rust/rust2rpm Source: https://pagure.io/fedora-rust/rust2rpm/archive/v%{version}/rust2rpm-v%{version}.tar.gz +Patch: https://pagure.io/fedora-rust/rust2rpm/pull-request/168.patch +Patch: https://pagure.io/fedora-rust/rust2rpm/pull-request/179.patch ExclusiveArch: %{rust_arches}