diff mbox series

[14/20] devtool: ide-sdk: remap Cargo sources for BitBake builds

Message ID 20261026-devtool-ide-sdk-cargo-v1-14-d4504e124d07@savoirfairelinux.com
State New
Headers show
Series devtool: ide-sdk: add support for Rust recipes | expand

Commit Message

Enguerrand de Ribaucourt Oct. 26, 2026, 8:55 a.m. UTC
With devtool modify, Cargo sources can live outside WORKDIR, so the
standard Rust remaps leave the workspace path in DWARF and package QA
rejects the debug package. Append a workspace-specific remap to
RUST_DEBUG_REMAP in a managed bbappend section so repeated ide-sdk runs
restore and reparse it.

AI-Generated: Uses GitHub Copilot
Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
---
 scripts/lib/devtool/ide_sdk.py | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/scripts/lib/devtool/ide_sdk.py b/scripts/lib/devtool/ide_sdk.py
index f22a98cedf..9fd95f0a63 100755
--- a/scripts/lib/devtool/ide_sdk.py
+++ b/scripts/lib/devtool/ide_sdk.py
@@ -823,6 +823,7 @@  class RecipeModified:
     VALID_BASH_ENV_NAME_CHARS = re.compile(r"^[a-zA-Z0-9_]*$")
 
     MARKER = '# devtool ide-sdk: clangd toolchain support'
+    CARGO_REMAP_MARKER = '# devtool ide-sdk: Cargo source debug remap'
 
     # PROVIDES of recipes that are deployed via do_deploy (e.g. to
     # DEPLOY_DIR_IMAGE) rather than installed into the rootfs, so adding them
@@ -943,13 +944,14 @@  class RecipeModified:
                 content = f.read()
             originals[name] = content
             stripped = cls._strip_marker_section(content, cls.MARKER)
+            stripped = cls._strip_marker_section(stripped, cls.CARGO_REMAP_MARKER)
             if stripped != content:
                 with open(bbappend, 'w') as f:
                     f.write(stripped)
         return originals
 
     def update_bbappend(self):
-        """Add DEPENDS on clang-native when clangd is used as only the IntelliSense engine"""
+        """Add workspace-only IDE dependencies and Cargo debug path remaps."""
         wants_clang_native = (
             self.build_tool.is_c_cpp
             and self.ide_sdk_intellisense == 'clangd'
@@ -962,28 +964,44 @@  class RecipeModified:
         else:
             parsed_content = ''
 
-        if not wants_clang_native:
+        new_sections = []
+        if wants_clang_native:
+            new_sections.append(
+                self.MARKER + '\nDEPENDS:append = " clang-native"\n')
+        if self.build_tool is BuildTool.CARGO:
+            new_sections.append(
+                self.CARGO_REMAP_MARKER
+                + '\nRUST_DEBUG_REMAP:append = " '
+                '--remap-path-prefix=${S}=${TARGET_DBGSRC_DIR}"\n')
+
+        if not new_sections:
             if self.MARKER in original_content:
                 logger.info(
                     "Removed clangd toolchain support from %s: no longer needed", self.bbappend)
             return False
 
-        new_section = self.MARKER + '\nDEPENDS:append = " clang-native"\n'
         new_content = parsed_content
-        if new_content and not new_content.endswith('\n'):
-            new_content += '\n'
-        new_content += new_section
+        for section in new_sections:
+            if new_content and not new_content.endswith('\n'):
+                new_content += '\n'
+            new_content += section
 
-        if new_content == original_content:
+        # Managed sections were stripped before parsing, so compare against
+        # what BitBake parsed rather than the saved pre-strip contents.
+        if new_content == parsed_content:
             return False
 
         appends_dir = os.path.dirname(self.bbappend)
         os.makedirs(appends_dir, exist_ok=True)
         with open(self.bbappend, 'w') as f:
             f.write(new_content)
-        logger.info(
-            "Updated %s: added DEPENDS on clang-native, needed to stage clangd "
-            "for IDE_SDK_INTELLISENSE=\"clangd\"", self.bbappend)
+        if wants_clang_native:
+            logger.info(
+                "Updated %s: added DEPENDS on clang-native, needed to stage clangd "
+                "for IDE_SDK_INTELLISENSE=\"clangd\"", self.bbappend)
+        if self.build_tool is BuildTool.CARGO:
+            logger.info(
+                "Updated %s: remapped Cargo external sources for debug info", self.bbappend)
         return True
 
     def initialize(self, config, workspace, tinfoil):