Skip to contentSkip to conversation

package/pkg-cargo: allow packages to define download environment

PATCH In review [email protected] 2 participants 10 messages Feb 10, 2022 – Mar 7, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v3 1/5 package/pkg-cargo: allow packages to define download environment

From: "Yann E. MORIN" <[email protected]>

Currently, the cargo infrastructure forcibly sets the package _DL_ENV variable, instead of appending to it, which prevents packages from providing their own download environment variables.

We fix that by using an append-assignment.

Note: when introduced, that variable was explicitly not documented, and is supposed to only be used by packages infrastructures. However, that variable exists, and it can be (ab)used by br2-external packages (most probably to ill effects, but heh!). We anyway leave it undocumented, like _ROOTFS_PRE_CMD_HOOKS.

---
 package/pkg-cargo.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/pkg-cargo.mk +1 -1
index e74a8358bc..66bea513e0 100644
@@ -69,7 +69,7 @@ define inner-cargo-package
 $(2)_DOWNLOAD_DEPENDENCIES += host-rustc
 
 $(2)_DOWNLOAD_POST_PROCESS = cargo
-$(2)_DL_ENV = CARGO_HOME=$$(HOST_DIR)/share/cargo
+$(2)_DL_ENV += CARGO_HOME=$$(HOST_DIR)/share/cargo
 
 # Due to vendoring, it is pretty likely that not all licenses are
 # listed in <pkg>_LICENSE.
Signature · 20 lines
2.25.1


_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]> writes:

From: "Yann E. MORIN" <[email protected]>
Currently, the cargo infrastructure forcibly sets the package _DL_ENV variable, instead of appending to it, which prevents packages from providing their own download environment variables.

We fix that by using an append-assignment.

Note: when introduced, that variable was explicitly not documented, and is supposed to only be used by packages infrastructures. However, that variable exists, and it can be (ab)used by br2-external packages (most probably to ill effects, but heh!). We anyway leave it undocumented, like _ROOTFS_PRE_CMD_HOOKS.

Quoted 3 lines

Committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH v3 2/5 package/pkg-cargo: allow building in a sub-directory

In reply to a message not in the archive

From: "Yann E. MORIN" <[email protected]>

Some packages have their rust sources as a sub-directory, rather than at the root of the source tree.

Do like we do for autotools-package, and use the package's _SRCDIR rather than the top-level directory $(@D).

Additionally, in such a situation, it is more than probable that the Cargo.toml is also present in that sub-directory, so use that when vendoring the package.

Cc Thomas Petazzoni <[email protected]>

---
Changes v2 -> v3:
- always consider Cargo.toml to be in _SUBDIR (Thomas)
- add _SUBDIR to the manual (Thomas)

Changes v1 -> v2:
- fix conditional (inverted logic)
- fix syntax in conditional (missing comma)

---
 docs/manual/adding-packages-cargo.txt |  5 +++++
 package/pkg-cargo.mk                  | 13 +++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)
docs/manual/adding-packages-cargo.txt +5 -0
index 5343fbd4e6..e18fd9ce23 100644
@@ -73,6 +73,11 @@ A few additional variables, specific to the Cargo infrastructure, can
 also be defined. Many of them are only useful in very specific cases,
 typical packages will therefore only use a few of them.
 
+* +FOO_SUBDIR+ may contain the name of a subdirectory inside the package
+  that contains the Cargo.toml file. This is useful, if for example, it
+  is not at the root of the tree extracted by the tarball. If
+  +HOST_FOO_SUBDIR+ is not specified, it defaults to +FOO_SUBDIR+.
+
 * +FOO_CARGO_ENV+ can be used to pass additional variables in the
   environment of +cargo+ invocations. It used at both build and
   installation time
package/pkg-cargo.mk +9 -4
index 66bea513e0..8b246abfed 100644
@@ -71,6 +71,11 @@ $(2)_DOWNLOAD_DEPENDENCIES += host-rustc
 $(2)_DOWNLOAD_POST_PROCESS = cargo
 $(2)_DL_ENV += CARGO_HOME=$$(HOST_DIR)/share/cargo
 
+# If building in a sub directory, use that to find the Cargo.toml
+ifneq ($$($(2)_SUBDIR),)
+$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_SUBDIR)/Cargo.toml
+endif
+
 # Due to vendoring, it is pretty likely that not all licenses are
 # listed in <pkg>_LICENSE.
 $(2)_LICENSE += , vendored dependencies licenses probably not listed
@@ -97,7 +102,7 @@ $(2)_LICENSE += , vendored dependencies licenses probably not listed
 ifndef $(2)_BUILD_CMDS
 ifeq ($(4),target)
 define $(2)_BUILD_CMDS
-	cd $$(@D) && \
+	cd $$($$(PKG)_SRCDIR) && \
 	$$(TARGET_MAKE_ENV) \
 		$$(TARGET_CONFIGURE_OPTS) \
 		$$(PKG_CARGO_ENV) \
@@ -111,7 +116,7 @@ define $(2)_BUILD_CMDS
 endef
 else # ifeq ($(4),target)
 define $(2)_BUILD_CMDS
-	cd $$(@D) && \
+	cd $$($$(PKG)_SRCDIR) && \
 	$$(HOST_MAKE_ENV) \
 		RUSTFLAGS="$$(addprefix -C link-args=,$$(HOST_LDFLAGS))" \
 		$$(HOST_CONFIGURE_OPTS) \
@@ -133,7 +138,7 @@ endif # ifndef $(2)_BUILD_CMDS
 #
 ifndef $(2)_INSTALL_TARGET_CMDS
 define $(2)_INSTALL_TARGET_CMDS
-	cd $$(@D) && \
+	cd $$($$(PKG)_SRCDIR) && \
 	$$(TARGET_MAKE_ENV) \
 		$$(TARGET_CONFIGURE_OPTS) \
 		$$(PKG_CARGO_ENV) \
@@ -152,7 +157,7 @@ endif
 
 ifndef $(2)_INSTALL_CMDS
 define $(2)_INSTALL_CMDS
-	cd $$(@D) && \
+	cd $$($$(PKG)_SRCDIR) && \
 	$$(HOST_MAKE_ENV) \
 		RUSTFLAGS="$$(addprefix -C link-args=,$$(HOST_LDFLAGS))" \
 		$$(HOST_CONFIGURE_OPTS) \
Signature · 20 lines
2.25.1


_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Re: [Buildroot] [PATCH 2/5 v3] package/pkg-cargo: allow building in a sub-directory

Quoted 13 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]> writes:

From: "Yann E. MORIN" <[email protected]>
Some packages have their rust sources as a sub-directory, rather than at the root of the source tree.

Do like we do for autotools-package, and use the package's _SRCDIR rather than the top-level directory $(@D).

Additionally, in such a situation, it is more than probable that the Cargo.toml is also present in that sub-directory, so use that when vendoring the package.

Quoted 7 lines
Cc Thomas Petazzoni <[email protected]>

---
Changes v2 -> v3:
- always consider Cargo.toml to be in _SUBDIR (Thomas)
- add _SUBDIR to the manual (Thomas)

Committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

PATCH v3 3/5 package/pkg-cargo: host-rustc is also a build dependency

In reply to a message not in the archive

From: "Yann E. MORIN" <[email protected]>

Currently, host-rustc is a download dependency, because we need cargo for the vendoring during the download step.

However, when using a package in override-srcdir, there is no download step, so host-rustc is not pulled in as a dependency which breaks running the build of a single package from scratch:

    $ make clean
    $ make my-rust-package
    [...]
    [...] cargo build --offline --release --manifest-path Cargo.toml --locked
    /bin/sh: cargo: command not found

We fix that by adding host-rustc as a standard dependency too.

---
 package/pkg-cargo.mk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
package/pkg-cargo.mk +3 -1
index 8b246abfed..6f5125f1d4 100644
@@ -65,8 +65,10 @@ HOST_PKG_CARGO_ENV = \
 
 define inner-cargo-package
 
-# We need host-rustc to run cargo
+# We need host-rustc to run cargo at download time (for vendoring),
+# and at build and install time.
 $(2)_DOWNLOAD_DEPENDENCIES += host-rustc
+$(2)_DEPENDENCIES += host-rustc
 
 $(2)_DOWNLOAD_POST_PROCESS = cargo
 $(2)_DL_ENV += CARGO_HOME=$$(HOST_DIR)/share/cargo
Signature · 20 lines
2.25.1


_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#6 lore raw

Re: [Buildroot] [PATCH 3/5 v3] package/pkg-cargo: host-rustc is also a build dependency

Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]> writes:

From: "Yann E. MORIN" <[email protected]>
Currently, host-rustc is a download dependency, because we need cargo for the vendoring during the download step.

However, when using a package in override-srcdir, there is no download step, so host-rustc is not pulled in as a dependency which breaks running the build of a single package from scratch:

    $ make clean
    $ make my-rust-package
    [...]
    [...] cargo build --offline --release --manifest-path Cargo.toml --locked
    /bin/sh: cargo: command not found
Quoted 5 lines

We fix that by adding host-rustc as a standard dependency too.

Committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#7 lore raw

PATCH v3 4/5 package/pkg-golang: allow packages to define download environment

In reply to a message not in the archive

From: "Yann E. MORIN" <[email protected]>

Currently, the golang infrastructure forcibly sets the package _DL_ENV variable, instead of appending to it, which prevents packages from providing their own download environment variables.

We fix that by using an append-assignment.

Note: when introduced, that variable was explicitly not documented, and is supposed to only be used by packages infrastructures. However, that variable exists, and it can be (ab)used by br2-external packages (most probably to ill effects, but heh!). We anyway leave it undocumented, like _ROOTFS_PRE_CMD_HOOKS.

---
 package/pkg-golang.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/pkg-golang.mk +1 -1
index 35bcb1673b..69eae02830 100644
@@ -83,7 +83,7 @@ endef
 $(2)_POST_PATCH_HOOKS += $(2)_GEN_GOMOD
 
 $(2)_DOWNLOAD_POST_PROCESS = go
-$(2)_DL_ENV = \
+$(2)_DL_ENV += \
 	$(HOST_GO_COMMON_ENV) \
 	GOPROXY=direct \
 	BR_GOMOD=$$($(2)_GOMOD)
Signature · 20 lines
2.25.1


_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#8 lore raw

Re: [Buildroot] [PATCH 4/5 v3] package/pkg-golang: allow packages to define download environment

Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]> writes:

From: "Yann E. MORIN" <[email protected]>
Currently, the golang infrastructure forcibly sets the package _DL_ENV variable, instead of appending to it, which prevents packages from providing their own download environment variables.

We fix that by using an append-assignment.

Note: when introduced, that variable was explicitly not documented, and is supposed to only be used by packages infrastructures. However, that variable exists, and it can be (ab)used by br2-external packages (most probably to ill effects, but heh!). We anyway leave it undocumented, like _ROOTFS_PRE_CMD_HOOKS.

Quoted 6 lines

Committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#9 lore raw

PATCH v3 5/5 package/pkg-golang: host-go is also a build dependency

In reply to a message not in the archive

From: "Yann E. MORIN" <[email protected]>

Currently, host-go is a download dependency, because we need go for the vendoring during the download step.

However, when using a package in override-srcdir, there is no download step, so host-go is not pulled in as a dependency, which will break the build of a single package from scratch.

We fix that by adding host-go as a standard dependency too.

---
 package/pkg-golang.mk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
package/pkg-golang.mk +3 -1
index 69eae02830..ddefdf1214 100644
@@ -47,8 +47,10 @@ $(2)_BUILD_OPTS += \
 	-trimpath \
 	-p $(PARALLEL_JOBS)
 
-# Target packages need the Go compiler on the host.
+# Target packages need the Go compiler on the host at download time (for
+# vendoring), and at build and install time.
 $(2)_DOWNLOAD_DEPENDENCIES += host-go
+$(2)_DEPENDENCIES += host-go
 
 $(2)_BUILD_TARGETS ?= .
 
Signature · 20 lines
2.25.1


_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#10 lore raw

Re: [Buildroot] [PATCH 5/5 v3] package/pkg-golang: host-go is also a build dependency

Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]> writes:

From: "Yann E. MORIN" <[email protected]>
Currently, host-go is a download dependency, because we need go for the vendoring during the download step.

However, when using a package in override-srcdir, there is no download step, so host-go is not pulled in as a dependency, which will break the build of a single package from scratch.

Quoted 8 lines

We fix that by adding host-go as a standard dependency too.

Committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot