Skip to contentSkip to conversation

cargo: Rename MANIFEST_PATH -> CARGO_MANIFEST_PATH

PATCH New Alex Kiernan 1 participant 4 messages Dec 8, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 cargo: Rename MANIFEST_PATH -> CARGO_MANIFEST_PATH

This variable is a piece of recipe configurable interface, scope it with the class name to make that clear.

---

(no changes since v1)

 meta/classes-recipe/cargo.bbclass        | 4 ++--
 meta/classes-recipe/cargo_common.bbclass | 2 +-
 meta/classes-recipe/ptest-cargo.bbclass  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
meta/classes-recipe/cargo.bbclass +2 -2
index 8c0b92df8d33..96a74e2ef1ec 100644
@@ -35,7 +35,7 @@ export RUST_BACKTRACE = "1"
 CARGO_SRC_DIR ??= ""
 
 # The actual path to the Cargo.toml
-MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
+CARGO_MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
 
 RUSTFLAGS ??= ""
 BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
@@ -44,7 +44,7 @@ BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
 # and will require an up to date Cargo.lock file.
 # This force the package being built to already ship a Cargo.lock, in the end
 # this is what we want, at least, for reproducibility of the build.
-CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${MANIFEST_PATH}"
+CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${CARGO_MANIFEST_PATH}"
 
 # This is based on the content of CARGO_BUILD_FLAGS and generally will need to
 # change if CARGO_BUILD_FLAGS changes.
meta/classes-recipe/cargo_common.bbclass +1 -1
index b732a1bd9538..bf298e96c745 100644
@@ -161,7 +161,7 @@ python cargo_common_do_patch_paths() {
     # here is better than letting cargo tell (in case the file is missing)
     # "Cargo.lock should be modified but --frozen was given"
 
-    manifest_path = d.getVar("MANIFEST_PATH", True)
+    manifest_path = d.getVar("CARGO_MANIFEST_PATH", True)
     lockfile = os.path.join(os.path.dirname(manifest_path), "Cargo.lock")
     if not os.path.exists(lockfile):
         bb.fatal(f"{lockfile} file doesn't exist")
meta/classes-recipe/ptest-cargo.bbclass +1 -1
index ff57be852508..c46df362bfee 100644
@@ -15,7 +15,7 @@ python do_compile_ptest_cargo() {
     cargo = bb.utils.which(d.getVar("PATH"), d.getVar("CARGO", True))
     cargo_build_flags = d.getVar("CARGO_BUILD_FLAGS", True)
     rust_flags = d.getVar("RUSTFLAGS", True)
-    manifest_path = d.getVar("MANIFEST_PATH", True)
+    manifest_path = d.getVar("CARGO_MANIFEST_PATH", True)
     project_manifest_path = os.path.normpath(manifest_path)
     manifest_dir = os.path.dirname(manifest_path)
 
Signature · 1 line
2.39.0
#1 lore raw

PATCH v2 2/4 cargo: Move CARGO_MANIFEST_PATH/CARGO_SRC_DIR to cargo_common

cargo_common_do_configure uses CARGO_MANIFEST_PATH (which depends on CARGO_SRC_DIR), but their definition was in cargo.bbclass.

---

Changes in v2:
- Drop change from default to weak-defaults

 meta/classes-recipe/cargo.bbclass        | 7 -------
 meta/classes-recipe/cargo_common.bbclass | 7 +++++++
 2 files changed, 7 insertions(+), 7 deletions(-)
meta/classes-recipe/cargo.bbclass +0 -7
index 96a74e2ef1ec..0829a58dd90f 100644
@@ -30,13 +30,6 @@ B = "${WORKDIR}/build"
 # where the issue occured
 export RUST_BACKTRACE = "1"
 
-# The directory of the Cargo.toml relative to the root directory, per default
-# assume there's a Cargo.toml directly in the root directory
-CARGO_SRC_DIR ??= ""
-
-# The actual path to the Cargo.toml
-CARGO_MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
-
 RUSTFLAGS ??= ""
 BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
 # --frozen flag will prevent network access (which is required since only
meta/classes-recipe/cargo_common.bbclass +7 -0
index bf298e96c745..509aa195c5fa 100644
@@ -33,6 +33,13 @@ CARGO_DISABLE_BITBAKE_VENDORING ?= "0"
 # Used by libstd-rs to point to the vendor dir included in rustc src
 CARGO_VENDORING_DIRECTORY ?= "${CARGO_HOME}/bitbake"
 
+# The directory of the Cargo.toml relative to the root directory, per default
+# assume there's a Cargo.toml directly in the root directory
+CARGO_SRC_DIR ??= ""
+
+# The actual path to the Cargo.toml
+CARGO_MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
+
 CARGO_RUST_TARGET_CCLD ?= "${RUST_TARGET_CCLD}"
 cargo_common_do_configure () {
 	mkdir -p ${CARGO_HOME}/bitbake
Signature · 1 line
2.39.0
#2 lore raw

PATCH v2 3/4 rust: cargo: Convert single-valued variables to weak defaults

In reply to Alex Kiernan

All of these variables are single-valued, so we can use weak-defaults for them and only see the final assignment after parsing.

---

Changes in v2:
- New in v2

 meta/classes-recipe/cargo_common.bbclass | 6 +++---
 meta/classes-recipe/rust-common.bbclass  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
meta/classes-recipe/cargo_common.bbclass +3 -3
index 509aa195c5fa..48cdd69bca13 100644
@@ -28,10 +28,10 @@ export PKG_CONFIG_ALLOW_CROSS = "1"
 # Don't instruct cargo to use crates downloaded by bitbake. Some rust packages,
 # for example the rust compiler itself, come with their own vendored sources.
 # Specifying two [source.crates-io] will not work.
-CARGO_DISABLE_BITBAKE_VENDORING ?= "0"
+CARGO_DISABLE_BITBAKE_VENDORING ??= "0"
 
 # Used by libstd-rs to point to the vendor dir included in rustc src
-CARGO_VENDORING_DIRECTORY ?= "${CARGO_HOME}/bitbake"
+CARGO_VENDORING_DIRECTORY ??= "${CARGO_HOME}/bitbake"
 
 # The directory of the Cargo.toml relative to the root directory, per default
 # assume there's a Cargo.toml directly in the root directory
@@ -40,7 +40,7 @@ CARGO_SRC_DIR ??= ""
 # The actual path to the Cargo.toml
 CARGO_MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
 
-CARGO_RUST_TARGET_CCLD ?= "${RUST_TARGET_CCLD}"
+CARGO_RUST_TARGET_CCLD ??= "${RUST_TARGET_CCLD}"
 cargo_common_do_configure () {
 	mkdir -p ${CARGO_HOME}/bitbake
 
meta/classes-recipe/rust-common.bbclass +2 -2
index ae96d9c5b1ff..6940093e59bf 100644
@@ -16,8 +16,8 @@ FILES:${PN}-dbg += "${rustlibdir}/.debug"
 RUSTLIB = "-L ${STAGING_DIR_HOST}${rustlibdir}"
 RUST_DEBUG_REMAP = "--remap-path-prefix=${WORKDIR}=${TARGET_DBGSRC_DIR}"
 RUSTFLAGS += "${RUSTLIB} ${RUST_DEBUG_REMAP}"
-RUSTLIB_DEP ?= "libstd-rs"
-RUST_PANIC_STRATEGY ?= "unwind"
+RUSTLIB_DEP ??= "libstd-rs"
+RUST_PANIC_STRATEGY ??= "unwind"
 
 def target_is_armv7(d):
     '''Determine if target is armv7'''
Signature · 1 line
2.39.0
#3 lore raw

PATCH v2 4/4 cargo: Add CARGO_LOCK_PATH for path to Cargo.lock

In reply to Alex Kiernan

When building a workspace enabled project, the Cargo.lock is found at the root of the project, not alongside the Cargo.toml. Expose CARGO_LOCK_PATH so it can be explicitly configured.

---

Changes in v2:
- Change CARGO_LOCK_PATH to a weak-default

 meta/classes-recipe/cargo_common.bbclass | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/classes-recipe/cargo_common.bbclass +4 -2
index 48cdd69bca13..0fb443edbdde 100644
@@ -40,6 +40,9 @@ CARGO_SRC_DIR ??= ""
 # The actual path to the Cargo.toml
 CARGO_MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
 
+# Path to Cargo.lock
+CARGO_LOCK_PATH ??= "${@ os.path.join(os.path.dirname(d.getVar('CARGO_MANIFEST_PATH', True)), 'Cargo.lock')}"
+
 CARGO_RUST_TARGET_CCLD ??= "${RUST_TARGET_CCLD}"
 cargo_common_do_configure () {
 	mkdir -p ${CARGO_HOME}/bitbake
@@ -168,8 +171,7 @@ python cargo_common_do_patch_paths() {
     # here is better than letting cargo tell (in case the file is missing)
     # "Cargo.lock should be modified but --frozen was given"
 
-    manifest_path = d.getVar("CARGO_MANIFEST_PATH", True)
-    lockfile = os.path.join(os.path.dirname(manifest_path), "Cargo.lock")
+    lockfile = d.getVar("CARGO_LOCK_PATH", True)
     if not os.path.exists(lockfile):
         bb.fatal(f"{lockfile} file doesn't exist")
 
Signature · 1 line
2.39.0