diff mbox series

rust-common: add LDFLAGS to 'build-rust-cc' wrapper

Message ID 20250120164504.680234-1-enrico.scholz@sigma-chemnitz.de
State Accepted, archived
Commit 49b37575b548f0ab082c700f91fdd856740dc829
Headers show
Series rust-common: add LDFLAGS to 'build-rust-cc' wrapper | expand

Commit Message

Enrico Scholz Jan. 20, 2025, 4:45 p.m. UTC
From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>

Although rust differs between compiling (--> 'rust-cc' wrapper) and
linking (--> 'rust-ccld' wrapper), some core crates are using only the
'rust-cc' wrapper to check for available compiler options [1] and
libraries [2].

Not having LDFLAGS can break the build in subtle ways.  E.g. 'cargo-native'
can fail to build with

|   = note: .../hosttools/ld: .../liblibz_sys-....rlib(deflate.o):
|     relocation R_X86_64_32S against hidden symbol `_length_code' can not be used when making a PIE object

because it does not find '-lz' (added by "DEPENDS = zlib") and builds
a static libz.a with missing PIC flags.

Add LDFLAGS to the 'build-rust-cc' wrapper as it is done already for
the target one.

[1] https://github.com/rust-lang/cc-rs/pull/1322

[2] https://github.com/rust-lang/libz-sys/blob/12a32798c6bd18986cb5cd603359b03c96f0eb4c/build.rs#L228-L234

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
---
 meta/classes-recipe/rust-common.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mathieu Dubois-Briand Jan. 21, 2025, 1:19 p.m. UTC | #1
On Mon Jan 20, 2025 at 5:45 PM CET, Enrico Scholz via lists.openembedded.org wrote:
> From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
>
> Although rust differs between compiling (--> 'rust-cc' wrapper) and
> linking (--> 'rust-ccld' wrapper), some core crates are using only the
> 'rust-cc' wrapper to check for available compiler options [1] and
> libraries [2].
>
> Not having LDFLAGS can break the build in subtle ways.  E.g. 'cargo-native'
> can fail to build with
>
> |   = note: .../hosttools/ld: .../liblibz_sys-....rlib(deflate.o):
> |     relocation R_X86_64_32S against hidden symbol `_length_code' can not be used when making a PIE object
>
> because it does not find '-lz' (added by "DEPENDS = zlib") and builds
> a static libz.a with missing PIC flags.
>
> Add LDFLAGS to the 'build-rust-cc' wrapper as it is done already for
> the target one.
>
> [1] https://github.com/rust-lang/cc-rs/pull/1322
>
> [2] https://github.com/rust-lang/libz-sys/blob/12a32798c6bd18986cb5cd603359b03c96f0eb4c/build.rs#L228-L234
>
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> ---

Hi Enrico,

Thanks for your patch.

I believe it is breaking some of the builds on the autobuilder, with the
following error:

error: failed to run custom build command for `hello v0.1.0 (/srv/pokybuild/yocto-worker/qemuarmv5/build/build/tmp/work/qemuarmv5-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/hello)`
Caused by:
  could not execute process `/srv/pokybuild/yocto-worker/qemuarmv5/build/build/tmp/work/qemuarmv5-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/hello/target/debug/build/hello-1d90539edb14488a/build-script-build` (never executed)

Caused by:
  No such file or directory (os error 2)


https://autobuilder.yoctoproject.org/valkyrie/#/builders/80/builds/775/steps/13/logs/stdio

Can you have a look at this failure please ?
Mathieu Dubois-Briand Jan. 21, 2025, 3:58 p.m. UTC | #2
On Tue Jan 21, 2025 at 2:19 PM CET, Mathieu Dubois-Briand wrote:
> On Mon Jan 20, 2025 at 5:45 PM CET, Enrico Scholz via lists.openembedded.org wrote:
> > From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> >
> > Although rust differs between compiling (--> 'rust-cc' wrapper) and
> > linking (--> 'rust-ccld' wrapper), some core crates are using only the
> > 'rust-cc' wrapper to check for available compiler options [1] and
> > libraries [2].
> >
> > Not having LDFLAGS can break the build in subtle ways.  E.g. 'cargo-native'
> > can fail to build with
> >
> > |   = note: .../hosttools/ld: .../liblibz_sys-....rlib(deflate.o):
> > |     relocation R_X86_64_32S against hidden symbol `_length_code' can not be used when making a PIE object
> >
> > because it does not find '-lz' (added by "DEPENDS = zlib") and builds
> > a static libz.a with missing PIC flags.
> >
> > Add LDFLAGS to the 'build-rust-cc' wrapper as it is done already for
> > the target one.
> >
> > [1] https://github.com/rust-lang/cc-rs/pull/1322
> >
> > [2] https://github.com/rust-lang/libz-sys/blob/12a32798c6bd18986cb5cd603359b03c96f0eb4c/build.rs#L228-L234
> >
> > Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> > ---
>
> Hi Enrico,
>
> Thanks for your patch.
>
> I believe it is breaking some of the builds on the autobuilder, with the
> following error:
>
> error: failed to run custom build command for `hello v0.1.0 (/srv/pokybuild/yocto-worker/qemuarmv5/build/build/tmp/work/qemuarmv5-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/hello)`
> Caused by:
>   could not execute process `/srv/pokybuild/yocto-worker/qemuarmv5/build/build/tmp/work/qemuarmv5-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/hello/target/debug/build/hello-1d90539edb14488a/build-script-build` (never executed)
>
> Caused by:
>   No such file or directory (os error 2)
>
>
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/80/builds/775/steps/13/logs/stdio
>
> Can you have a look at this failure please ?

Ok, after more testing, it might be something else causing this error. I
will keep you updated.
Mathieu Dubois-Briand Jan. 23, 2025, 7:30 a.m. UTC | #3
On Tue Jan 21, 2025 at 4:58 PM CET, Mathieu Dubois-Briand wrote:
> On Tue Jan 21, 2025 at 2:19 PM CET, Mathieu Dubois-Briand wrote:
> > On Mon Jan 20, 2025 at 5:45 PM CET, Enrico Scholz via lists.openembedded.org wrote:
> > > From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> > >
> > > Although rust differs between compiling (--> 'rust-cc' wrapper) and
> > > linking (--> 'rust-ccld' wrapper), some core crates are using only the
> > > 'rust-cc' wrapper to check for available compiler options [1] and
> > > libraries [2].
> > >
> > > Not having LDFLAGS can break the build in subtle ways.  E.g. 'cargo-native'
> > > can fail to build with
> > >
> > > |   = note: .../hosttools/ld: .../liblibz_sys-....rlib(deflate.o):
> > > |     relocation R_X86_64_32S against hidden symbol `_length_code' can not be used when making a PIE object
> > >
> > > because it does not find '-lz' (added by "DEPENDS = zlib") and builds
> > > a static libz.a with missing PIC flags.
> > >
> > > Add LDFLAGS to the 'build-rust-cc' wrapper as it is done already for
> > > the target one.
> > >
> > > [1] https://github.com/rust-lang/cc-rs/pull/1322
> > >
> > > [2] https://github.com/rust-lang/libz-sys/blob/12a32798c6bd18986cb5cd603359b03c96f0eb4c/build.rs#L228-L234
> > >
> > > Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> > > ---
> >
> > Hi Enrico,
> >
> > Thanks for your patch.
> >
> > I believe it is breaking some of the builds on the autobuilder, with the
> > following error:
> >
> > error: failed to run custom build command for `hello v0.1.0 (/srv/pokybuild/yocto-worker/qemuarmv5/build/build/tmp/work/qemuarmv5-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/hello)`
> > Caused by:
> >   could not execute process `/srv/pokybuild/yocto-worker/qemuarmv5/build/build/tmp/work/qemuarmv5-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/hello/target/debug/build/hello-1d90539edb14488a/build-script-build` (never executed)
> >
> > Caused by:
> >   No such file or directory (os error 2)
> >
> >
> > https://autobuilder.yoctoproject.org/valkyrie/#/builders/80/builds/775/steps/13/logs/stdio
> >
> > Can you have a look at this failure please ?
>
> Ok, after more testing, it might be something else causing this error. I
> will keep you updated.

Hi Enrico,

Sorry for the false alarm, this patch is fine in an autobuilder point of
view. Said error was caused by another patch and I was able to build
with yours without any error.

Best regards,
Mathieu
diff mbox series

Patch

diff --git a/meta/classes-recipe/rust-common.bbclass b/meta/classes-recipe/rust-common.bbclass
index 6940093e59bf..baa3869c478f 100644
--- a/meta/classes-recipe/rust-common.bbclass
+++ b/meta/classes-recipe/rust-common.bbclass
@@ -173,7 +173,7 @@  do_rust_create_wrappers () {
 	mkdir -p "${WRAPPER_DIR}"
 
 	# Yocto Build / Rust Host C compiler
-	create_wrapper_rust "${RUST_BUILD_CC}" "" "${CRATE_CC_FLAGS}" "${BUILD_CC}"
+	create_wrapper_rust "${RUST_BUILD_CC}" "" "${CRATE_CC_FLAGS}" "${BUILD_CC}" "${BUILD_LDFLAGS}"
 	# Yocto Build / Rust Host C++ compiler
 	create_wrapper_rust "${RUST_BUILD_CXX}" "" "${CRATE_CC_FLAGS}" "${BUILD_CXX}"
 	# Yocto Build / Rust Host linker