Skip to content

Use portable $(python) preprocessor for Kconfig#719

Merged
jserv merged 1 commit intomasterfrom
portable-kconfig
Mar 1, 2026
Merged

Use portable $(python) preprocessor for Kconfig#719
jserv merged 1 commit intomasterfrom
portable-kconfig

Conversation

@jserv
Copy link
Copy Markdown
Contributor

@jserv jserv commented Mar 1, 2026

This replaces $(shell,...) call with portable $(python,...) preprocessor function from Kconfiglib for boolean environment detection. $(python) built-in evaluates Python code in-process and returns "y"/"n" without spawning a shell, eliminating POSIX shell dependencies (2>/dev/null, || echo) and improving Windows portability.

Simple checks (SDL2, SDL2_mixer) are inlined directly using the run()/shutil.which() helpers available in the $(python,...) namespace. Complex checks (compiler type, LLVM 18, RISC-V toolchain) delegate to detect-env.py via run(sys.executable, ...) with exit-code signaling.


Summary by cubic

Switch Kconfig detection to the portable $(python,...) preprocessor to remove POSIX shell dependencies and improve Windows support. Simple checks run in-process; complex checks call detect-env.py and signal results via exit codes.

  • Refactors
    • Replace $(shell,...) with $(python,assert ...) for boolean symbols (emcc, clang/gcc, SDL2, SDL2_mixer, LLVM 18, RISC-V toolchain).
    • Inline SDL2/SDL2_mixer checks using shutil.which/pkg-config; avoid spawning a shell.
    • Derive COMPILER_TYPE from CC_IS_EMCC/CLANG/GCC with Kconfig defaults; fallback to "Unknown".
    • Delegate complex checks to tools/detect-env.py via run(sys.executable, ...); exit 0/1 drives y/n.
    • Update detect-env.py: exit-code booleans, lazy compiler probing, and capture stderr in --version for emcc.

Written for commit 2a635b4. Summary will update on new commits.

cubic-dev-ai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Details
Benchmark suite Current: 2a635b4 Previous: 8092c66 Ratio
Dhrystone 1554 DMIPS 1535.333 DMIPS 0.99
CoreMark 1108.112 iterations/sec 1110.937 iterations/sec 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@jserv jserv added this to the release-2026.2 milestone Mar 1, 2026
Replace all $(shell,...) calls with the portable $(python,...) preprocessor
function from Kconfiglib.  The $(python,...) built-in evaluates Python code
in-process and returns "y"/"n" without spawning a shell, eliminating POSIX
shell dependencies (2>/dev/null, ||, echo) for cross-platform portability.

Simple checks (SDL2, SDL2_mixer) are inlined directly using the run() and
shutil.which() helpers available in the $(python,...) namespace.  Complex
checks (compiler type, LLVM 18, RISC-V toolchain) delegate to detect-env.py
via run(sys.executable, ...) with exit-code signaling.  COMPILER_TYPE is
derived from the CC_IS_CLANG/CC_IS_GCC/CC_IS_EMCC booleans using pure
Kconfig conditionals, eliminating the last $(shell,...) call.

detect-env.py changes:
- Boolean flags now use exit codes (0/1) via bool_exit() instead of
  printing "y"/"n", matching the run() convention in $(python,...).
- Compiler probing is lazy: --have-sdl2, --have-llvm18, etc. no longer
  pay the cost of running CC --version when they don't need it.
- get_compiler_version() captures both stdout and stderr to handle
  emcc variants that emit version info on stderr.

Reference: sysprog21/Kconfiglib#47
@jserv jserv force-pushed the portable-kconfig branch from 6dca3b9 to 2a635b4 Compare March 1, 2026 08:32
@jserv jserv merged commit 93a04ca into master Mar 1, 2026
32 checks passed
@jserv jserv deleted the portable-kconfig branch March 1, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant