Skip to content

Conversation

@quinnjr
Copy link
Contributor

@quinnjr quinnjr commented Jan 4, 2026

Summary

Major refactoring of the SCons build system for improved maintainability, reduced cyclomatic complexity, and automatic R library detection.

Motivation

The original SConstruct file had grown complex and difficult to maintain, with hardcoded paths, nested conditionals, and duplicated code. This refactoring addresses these issues while also improving the R configuration experience.

Changes

🏗️ SConstruct Improvements

  • Reorganized into clear sections with constants, functions, and a main entry point
  • Broke down monolithic build logic into well-named, single-purpose functions
  • Replaced individual option registration calls with data-driven configuration
  • Extracted platform-specific logic into dedicated functions
  • Separated configuration and build phases for clarity

📉 Reduced Cyclomatic Complexity

  • Split large functions into smaller, focused helpers
  • Used data-driven approaches instead of nested conditionals
  • Eliminated conditionals inside loops where possible
  • Created lookup tables for repeated configuration patterns

🔍 R Library Auto-Detection

  • Added automatic detection of R, Rcpp, and RInside installation paths
  • Detection priority chain:
    1. Environment variables (R_HOME, RCPP_INCLUDE_DIR, RINSIDE_INCLUDE_DIR, RINSIDE_LIB_DIR)
    2. Query R/Rscript directly using R.home() and system.file()
    3. Fallback to common installation paths
  • Added CheckRPackages SCons test for R package verification
  • Build now fails with helpful error message if R packages are missing
  • Prints detection results during configuration for transparency

📦 build_support.py Enhancements

  • Added RConfig dataclass for R configuration management
  • Added detect_r_config() for automatic R library detection
  • Added check_r_packages() for R package verification
  • Split Python version detection into single-purpose functions
  • Added get_perl_ldopts() helper function

⚙️ build_config.py Enhancements

  • Added pre-computed boolean platform flags (is_darwin, is_linux, is_alpine)
  • Split platform detection into focused helper functions
  • Added type hints throughout

Testing

The refactored build system maintains backward compatibility with existing build commands:

scons                    # Build with default options
scons --without-python   # Disable Python support
scons --with-cuda        # Enable CUDA support
scons -c                 # Clean build artifacts

Co-authored-by

Co-authored-by: Claude noreply@anthropic.com

…tection

## Summary

Major refactoring of the SCons build system for improved maintainability,
reduced cyclomatic complexity, and better R library detection.

## Changes

### SConstruct Improvements
- Reorganized into clear sections with constants, functions, and main entry point
- Broke down monolithic build logic into well-named, single-purpose functions
- Replaced hardcoded option registration with data-driven configuration
- Extracted platform-specific logic into dedicated functions
- Separated configuration and build phases for clarity

### Reduced Cyclomatic Complexity
- Split large functions into smaller, focused helpers
- Used data-driven approaches instead of nested conditionals
- Eliminated conditionals in loops where possible
- Created lookup tables for repeated configuration patterns

### R Library Auto-Detection
- Added automatic detection of R, Rcpp, and RInside paths
- Detection priority: environment variables → R/Rscript queries → fallback paths
- Added CheckRPackages SCons test for package verification
- Build now fails with helpful message if R packages are missing
- Prints detection results during configuration

### build_support.py Enhancements
- Added RConfig dataclass for R configuration management
- Added detect_r_config() for automatic R library detection
- Added check_r_packages() for R package verification
- Split Python version detection into single-purpose functions
- Added get_perl_ldopts() helper function

### build_config.py Enhancements
- Added pre-computed boolean platform flags (is_darwin, is_linux, is_alpine)
- Split platform detection into focused helper functions
- Added type hints throughout

Co-authored-by: Claude <noreply@anthropic.com>
@quinnjr
Copy link
Contributor Author

quinnjr commented Jan 4, 2026

⚠️ Note: This PR should not be merged until the PR for Java and Rust language support changes has been merged first, as there will be merge conflicts between the two branches.

Please merge the Java/Rust support PR before this one to avoid conflicts in the SConstruct and build support files.

@quinnjr quinnjr marked this pull request as draft January 4, 2026 18:42
- Resolve merge conflicts in SConstruct and build_support.py
- Integrate Java language support from upstream into cleaned-up structure
- Add configure_java() function following the modular pattern
- Add --without-java option to OPTIONS list
- Add build_java_plugins() to compile Java plugins when Java is enabled
- Add _compile_java_plugins_in_folder() helper to find and compile *Plugin.java files
- Compile all .java files in plugin directory using javac
- Add JavaConfig dataclass for Java installation paths
- Detect JAVA_HOME from environment, javac/java symlinks,
  update-alternatives, and fallback paths
- Support AlmaLinux/RHEL, Debian/Ubuntu, Arch Linux, and macOS
- Find JNI include directories and libjvm library path
- Add CheckJava() SCons custom test for Java configuration
- Add detect_java_config() for programmatic Java detection
@quinnjr quinnjr marked this pull request as ready for review January 17, 2026 21:46
- Remove -D prefix from WITH_PERL and WITH_R in CPPDEFINES
  SCons automatically adds -D when generating compiler flags, so
  -DWITH_PERL would result in -D-DWITH_PERL (invalid)
- Fix Export() call that passed a dict when env_cuda was None
  Export() expects a string, not a dictionary
Previously HAVE_PYTHON was unconditionally added to CPPDEFINES,
causing compilation to fail when --without-python was specified
because Py.cxx would still try to include Python.h.

Now HAVE_PYTHON is only added when configure_python() successfully
enables Python support.
- Add user R library path (~R/library) to fallback search paths
- Update _run_r_command to include R_LIBS_USER environment variable
  so Rscript can find user-installed packages (Rcpp, RInside)
- Fix GCC-specific compiler flags for clang compatibility:
  - Use basename check to distinguish g++ from clang++
  - Only add -fno-gnu-unique and --param=ssp-buffer-size=4 for GCC
  - Fix --export-dynamic to -Wl,--export-dynamic for linker
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