From 6b59ed35a2d08fedd8b77e4c70d10bf22a0ce1e1 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Thu, 10 Feb 2022 16:29:25 +0100 Subject: [PATCH] package/pkg-cargo: allow building in a sub-directory 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. Signed-off-by: Yann E. MORIN Cc: Thomas Petazzoni Signed-off-by: Peter Korsgaard --- docs/manual/adding-packages-cargo.txt | 5 +++++ package/pkg-cargo.mk | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/manual/adding-packages-cargo.txt b/docs/manual/adding-packages-cargo.txt index 5343fbd4e6..e18fd9ce23 100644 --- a/docs/manual/adding-packages-cargo.txt +++ b/docs/manual/adding-packages-cargo.txt @@ -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 diff --git a/package/pkg-cargo.mk b/package/pkg-cargo.mk index 66bea513e0..8b246abfed 100644 --- a/package/pkg-cargo.mk +++ b/package/pkg-cargo.mk @@ -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 _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) \