#179 Include linker flags for package note in %build_rustflags
Merged 2 years ago by zbyszek. Opened 2 years ago by zbyszek.
fedora-rust/ zbyszek/rust2rpm add-package-note-linker-flags  into  main

file modified
+1 -2
@@ -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 @@ 

  [build]\

  rustc = "%{__rustc}"\

  rustdoc = "%{__rustdoc}"\

- rustflags = %{__global_rustflags_toml}\

  \

  [env]\

  CFLAGS = "%{build_cflags}"\

file modified
+3 -1
@@ -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

  }

%build_rustflags is used in %cargo_prep, which is executed in %prep,
when %buildsubdir is not set yet. When the linker script is actually created
in %build, %buildsubdir is defined, and we get a different path. To work
around this, in %build_rustflags we check if %_package_note_file is defined,
and add the linker arg if yes. But we summarilly ignore the actual value
and hardcode the path with the presumed value of %buildsubdir. Rust creates
have a standarized layout, so this should work OK in practice.

The linker flag gets passed to rustc, and resulting binaries seem to have
note as expected.

rebased onto c776d509de9f219f96088e9f4ef143e2caaf705e

2 years ago

rebased onto 0131b4e28aca1e036d1d089a17553d6378657e07

2 years ago

I pushed this version to fedora rawhide now.

@zbyszek I think you also need same flags for cargo install / cargo test, otherwise it will recompile all binaries …

Oh, there's a stupid bug: RUSTFLAGS is set twice for %cargo_build, and once for the other commands. In other words, the issue you point out was present in the earlier version of the patch, and it is not present in the current version. I'll fix the patch to remove the duplication (but it doesn't actually hurt).

rebased onto e1f9116

2 years ago

This seems to work fine based on the mini-mass-rebuild in Fedora.

Commit 3781ce3 fixes this pull-request

Pull-Request has been merged by zbyszek

2 years ago

Pull-Request has been merged by zbyszek

2 years ago

Will this affect RPM based distros other than Fedora?

It hopefully shouldn't if @zbyszek's conditioning of the package note stuff is correct.

Metadata