#21 Add %%build_rustflags
Opened a year ago by orion. Modified a year ago
rpms/ orion/rust epel7-rustflags  into  epel7

file modified
+36
@@ -49,3 +49,39 @@ 

  %cargo_test %__cargo test --release %{?_smp_mflags} --no-fail-fast

  

  %cargo_install %__cargo install --no-track --path .

+ 

+ # From rust-srpm-macros 8+

+ # rustflags_opt_level: default optimization level

+ #

+ # It corresponds to the "-Copt-level" rustc command line option.

+ %rustflags_opt_level 3

+ 

+ # rustflags_debuginfo: default verbosity of debug information

+ #

+ # It corresponds to the "-Cdebuginfo" rustc command line option.

+ # In some cases, it might be required to override this macro with "1" or even

+ # "0", if memory usage gets too high during builds on some resource-constrained

+ # architectures (most likely on 32-bit architectures), which will however

+ # reduce the quality of the produced debug symbols.

+ %rustflags_debuginfo 2

+ 

+ # rustflags_codegen_units: default number of parallel code generation units

+ #

+ # The default value of "1" results in generation of better code, but comes at

+ # the cost of longer build times.

+ %rustflags_codegen_units 1

+ 

+ # build_rustflags: default compiler flags for rustc (RUSTFLAGS)

+ #

+ # -Copt-level: set optimization level (default: highest optimization level)

+ # -Cdebuginfo: set debuginfo verbosity (default: full debug information)

+ # -Ccodegen-units: set number of parallel code generation units (default: 1)

+ # Cforce-frame-pointers: force inclusion of frame pointers (default: enabled

+ #       on x86_64 and aarch64 on Fedora 37+)

+ #

+ # Additionally, sime linker flags are set which correspond to the default

+ # Fedora compiler flags for hardening and for embedding package versions into

+ # compiled binaries.

+ #

+ # ref. https://doc.rust-lang.org/rustc/codegen-options/index.html

+ %build_rustflags -Copt-level=%rustflags_opt_level -Cdebuginfo=%rustflags_debuginfo -Ccodegen-units=%rustflags_codegen_units %{?_include_frame_pointers:-Cforce-frame-pointers=yes} -Clink-arg=-Wl,-z,relro -Clink-arg=-Wl,-z,now %{?_package_note_file:-Clink-arg=-Wl,-dT,%{_package_note_file}} --cap-lints=warn

The hope is to help with building clamav-1.0 for EPEL7, at least in a COPR.

Parts of this macro use syntax that is only valid with RPM 4.16 (i.e. the inclusion of package notes and frame pointers flags). These don't apply to EPEL 7 anyway, so you'd need to remove them.

Damn, I was afraid of that. I would still like to have an appropriate %build_rustflags available. I'll try to look into it more.

I think it should be fine if you just drop these two lines from the macro:

    %{expr:0%{?_include_frame_pointers} && ("%{_arch}" != "ppc64le" && "%{_arch}" != "s390x" && "%{_arch}" != "i386") ? "-Cforce-frame-pointers=yes" : ""}
    %[0%{?_package_note_status} ? "-Clink-arg=%_package_note_flags" : ""]

They are no-ops on EPEL 7 anyway, both flags are specific only to recent releases of Fedora.

I think %shrink is also too new for el7 rpm.

I do want to get around to a more holistic update to rust-toolset macros in RHEL, without conflicting with rust-packager in epel9. But for simple macro compatibility in epel7, would it be enough to just copy the flags that are already there?

%build_rustflags %__global_rustflags

rebased onto 8ddb8e9

a year ago

Well, why not use %__global_rustflags directly on RHEL 7? It's the official definition of default Rust compiler flags there ... I don't see a reason for EPEL builds to diverge from RHEL builds in this regard.

(The current diff also shows conditional flags for frame pointers and package notes - both of which are noops on all EPEL releases and can just be dropped entirely, if that helps make the implementation simpler.)

Metadata