diff mbox series

[v2,3/3] package/rust: provide RUSTFLAGS for cargo

Message ID 20240229224122.1085300-3-romain.naour@smile.fr
State Changes Requested
Headers show
Series [v2,1/3] package/rust/rust.mk: add missing host-zlib dependency | expand

Commit Message

Romain Naour Feb. 29, 2024, 10:41 p.m. UTC
While building the rust toolchain, the build system endup using
cargo (from [...]/output/build/host-rust-bin-1.74.1/cargo/bin/cargo)
to build some tool like rustdoc-tool.

But the host-rust package doesn't use the cargo infractructure (since
it provide cargo binary) and some cargo environment varialble [1] is
not set to crosscompile cargo packages in the rust toolchain.

For exemple, we usually set RUSTFLAGS="-C link-arg=-Wl,-rpath,$(HOST_DIR)/lib"
to force cargo using libraries provided by Buildroot in $(HOST_DIR)/lib.

RUSTFLAGS is actually needed to find zlib library (host-zlib) to link
rustdoc-tool when zlib is not installed on the host.

Fixes:

  error: could not compile `rustdoc-tool` (bin "rustdoc_tool_binary") due to previous error

[1] https://gitlab.com/buildroot.org/buildroot/-/blob/2024.02-rc1/package/pkg-cargo.mk?ref_type=tags#L167

Signed-off-by: Romain Naour <romain.naour@smile.fr>
---
v2: no change
---
 package/rust/rust.mk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Yann E. MORIN March 2, 2024, 9:45 p.m. UTC | #1
Romain, All,

On 2024-02-29 23:41 +0100, Romain Naour spake thusly:
> While building the rust toolchain, the build system endup using
> cargo (from [...]/output/build/host-rust-bin-1.74.1/cargo/bin/cargo)
> to build some tool like rustdoc-tool.
> 
> But the host-rust package doesn't use the cargo infractructure (since
> it provide cargo binary) and some cargo environment varialble [1] is
> not set to crosscompile cargo packages in the rust toolchain.
> 
> For exemple, we usually set RUSTFLAGS="-C link-arg=-Wl,-rpath,$(HOST_DIR)/lib"
> to force cargo using libraries provided by Buildroot in $(HOST_DIR)/lib.
> 
> RUSTFLAGS is actually needed to find zlib library (host-zlib) to link
> rustdoc-tool when zlib is not installed on the host.
> 
> Fixes:
> 
>   error: could not compile `rustdoc-tool` (bin "rustdoc_tool_binary") due to previous error
> 
> [1] https://gitlab.com/buildroot.org/buildroot/-/blob/2024.02-rc1/package/pkg-cargo.mk?ref_type=tags#L167
> 
> Signed-off-by: Romain Naour <romain.naour@smile.fr>
> ---
> v2: no change
> ---
>  package/rust/rust.mk | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/package/rust/rust.mk b/package/rust/rust.mk
> index 4903060368..394fbfa4ca 100644
> --- a/package/rust/rust.mk
> +++ b/package/rust/rust.mk
> @@ -70,7 +70,9 @@ define HOST_RUST_CONFIGURE_CMDS
>  endef
>  
>  define HOST_RUST_BUILD_CMDS
> -	cd $(@D); $(HOST_MAKE_ENV) $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
> +	cd $(@D); $(HOST_MAKE_ENV) \
> +		RUSTFLAGS="$(addprefix -C link-args=,$(HOST_LDFLAGS))" \

Why don't we jsut pass $(HOST_PKG_CARGO_ENV)? That one also contains
CARGO_HOME=$(DL_DIR)/br-cargo-home so I think it might make sense to
pass, no?

Regards,
Yann E. MORIN.

> +		$(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
>  endef
>  
>  HOST_RUST_INSTALL_OPTS = \
> -- 
> 2.43.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Romain Naour March 2, 2024, 9:54 p.m. UTC | #2
Hello Yann,

Le 02/03/2024 à 22:45, Yann E. MORIN a écrit :
> Romain, All,
> 
> On 2024-02-29 23:41 +0100, Romain Naour spake thusly:
>> While building the rust toolchain, the build system endup using
>> cargo (from [...]/output/build/host-rust-bin-1.74.1/cargo/bin/cargo)
>> to build some tool like rustdoc-tool.
>>
>> But the host-rust package doesn't use the cargo infractructure (since
>> it provide cargo binary) and some cargo environment varialble [1] is
>> not set to crosscompile cargo packages in the rust toolchain.
>>
>> For exemple, we usually set RUSTFLAGS="-C link-arg=-Wl,-rpath,$(HOST_DIR)/lib"
>> to force cargo using libraries provided by Buildroot in $(HOST_DIR)/lib.
>>
>> RUSTFLAGS is actually needed to find zlib library (host-zlib) to link
>> rustdoc-tool when zlib is not installed on the host.
>>
>> Fixes:
>>
>>   error: could not compile `rustdoc-tool` (bin "rustdoc_tool_binary") due to previous error
>>
>> [1] https://gitlab.com/buildroot.org/buildroot/-/blob/2024.02-rc1/package/pkg-cargo.mk?ref_type=tags#L167
>>
>> Signed-off-by: Romain Naour <romain.naour@smile.fr>
>> ---
>> v2: no change
>> ---
>>  package/rust/rust.mk | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/package/rust/rust.mk b/package/rust/rust.mk
>> index 4903060368..394fbfa4ca 100644
>> --- a/package/rust/rust.mk
>> +++ b/package/rust/rust.mk
>> @@ -70,7 +70,9 @@ define HOST_RUST_CONFIGURE_CMDS
>>  endef
>>  
>>  define HOST_RUST_BUILD_CMDS
>> -	cd $(@D); $(HOST_MAKE_ENV) $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
>> +	cd $(@D); $(HOST_MAKE_ENV) \
>> +		RUSTFLAGS="$(addprefix -C link-args=,$(HOST_LDFLAGS))" \
> 
> Why don't we jsut pass $(HOST_PKG_CARGO_ENV)? That one also contains
> CARGO_HOME=$(DL_DIR)/br-cargo-home so I think it might make sense to
> pass, no?

I didn't verify if CARGO_HOME is really missing. Also HOST_PKG_CARGO_ENV is
defined by the cargo package infra (pkg-cargo.mk) while host-rust is a
host-generic package.

Otherwise, I'm agree. We should use $(HOST_PKG_CARGO_ENV)

Best regards,
Romain


> 
> Regards,
> Yann E. MORIN.
> 
>> +		$(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
>>  endef
>>  
>>  HOST_RUST_INSTALL_OPTS = \
>> -- 
>> 2.43.2
>>
>> _______________________________________________
>> buildroot mailing list
>> buildroot@buildroot.org
>> https://lists.buildroot.org/mailman/listinfo/buildroot
>
Yann E. MORIN March 2, 2024, 10:06 p.m. UTC | #3
Romain, All,

On 2024-03-02 22:54 +0100, Romain Naour spake thusly:
> Le 02/03/2024 à 22:45, Yann E. MORIN a écrit :
> > On 2024-02-29 23:41 +0100, Romain Naour spake thusly:
> >> While building the rust toolchain, the build system endup using
> >> cargo (from [...]/output/build/host-rust-bin-1.74.1/cargo/bin/cargo)
> >> to build some tool like rustdoc-tool.
[--SNIP--]
> >> diff --git a/package/rust/rust.mk b/package/rust/rust.mk
> >> index 4903060368..394fbfa4ca 100644
> >> --- a/package/rust/rust.mk
> >> +++ b/package/rust/rust.mk
> >> @@ -70,7 +70,9 @@ define HOST_RUST_CONFIGURE_CMDS
> >>  endef
> >>  
> >>  define HOST_RUST_BUILD_CMDS
> >> -	cd $(@D); $(HOST_MAKE_ENV) $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
> >> +	cd $(@D); $(HOST_MAKE_ENV) \
> >> +		RUSTFLAGS="$(addprefix -C link-args=,$(HOST_LDFLAGS))" \
> > Why don't we jsut pass $(HOST_PKG_CARGO_ENV)? That one also contains
> > CARGO_HOME=$(DL_DIR)/br-cargo-home so I think it might make sense to
> > pass, no?
> I didn't verify if CARGO_HOME is really missing. Also HOST_PKG_CARGO_ENV is
> defined by the cargo package infra (pkg-cargo.mk) while host-rust is a
> host-generic package.
> 
> Otherwise, I'm agree. We should use $(HOST_PKG_CARGO_ENV)

OK, great, thanks! Will you test and respin a new iteration?

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/package/rust/rust.mk b/package/rust/rust.mk
index 4903060368..394fbfa4ca 100644
--- a/package/rust/rust.mk
+++ b/package/rust/rust.mk
@@ -70,7 +70,9 @@  define HOST_RUST_CONFIGURE_CMDS
 endef
 
 define HOST_RUST_BUILD_CMDS
-	cd $(@D); $(HOST_MAKE_ENV) $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
+	cd $(@D); $(HOST_MAKE_ENV) \
+		RUSTFLAGS="$(addprefix -C link-args=,$(HOST_LDFLAGS))" \
+		$(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) x.py build
 endef
 
 HOST_RUST_INSTALL_OPTS = \