@@ -1729,6 +1729,50 @@ def _min_config_contents(self, header):
17291729
17301730 return "" .join (chunks )
17311731
1732+ def write_rustcfg (self , filename = None ):
1733+ r"""
1734+ Write out rustcfg flags as a response file, matching the format used
1735+ by include/generated/rustc_cfg in the kernel.
1736+
1737+ filename (default: None):
1738+ Path to write respone file to.
1739+
1740+ If None (the default), the path in the environment variable
1741+ KCONFIG_RUSTCCFG is used if set, and "include/generated/rustc_cfg"
1742+ otherwise. This is compatible with the C tools.
1743+ """
1744+ if filename is None :
1745+ filename = os .getenv ("KCONFIG_RUSTCCFG" ,
1746+ "include/generated/rustc_cfg" )
1747+
1748+ if self ._write_if_changed (filename , self ._rustcfg_contents ()):
1749+ return "Kconfig cfg saved to '{}" .format (filename )
1750+ return "No changes to Kconfig cfg in '{}'" .format (filename )
1751+
1752+ def _rustcfg_contents (self ):
1753+ chunks = []
1754+ add = chunks .append
1755+
1756+ for sym in self .unique_defined_syms :
1757+ if not sym .choice and \
1758+ sym .visibility <= expr_value (sym .rev_dep ):
1759+ continue
1760+
1761+ val = sym .str_value
1762+ if sym .orig_type in _BOOL_TRISTATE :
1763+ # We do not care about disabled ones, would be a comment
1764+ if val == "n" :
1765+ continue
1766+ add ("--cfg={}{}\n "
1767+ .format (self .config_prefix , sym .name ))
1768+ elif sym .orig_type == HEX :
1769+ if not val .lower ().startswith ("0x" ):
1770+ val = "0x{}" .format (val );
1771+ add ("--cfg={}{}={}\n "
1772+ .format (self .config_prefix , sym .name , escape (val )))
1773+
1774+ return "" .join (chunks )
1775+
17321776 def sync_deps (self , path ):
17331777 """
17341778 Creates or updates a directory structure that can be used to avoid
0 commit comments