Skip to content

Conversation

byrnHDF
Copy link
Contributor

@byrnHDF byrnHDF commented Aug 11, 2025

Another possibility using defaults and toolchain file could overwrite.
See #5709 and #5718

The expectation is that cross-compiling will use a toolchain file to provide the correct values.
The defaults are only one way to provide defaults for a specific compiler.

NOTE: The supplied toolchain and Fortran pre-gen files are specific for mingw/gfortran - each platform/compiler will need to supply its own set of files/values.


Important

Rework HDF5UseFortran.cmake to support cross-compilation by providing default KINDs and sizes.

  • Behavior:
    • Modify HDF5UseFortran.cmake to handle cross-compilation by providing default KINDs and sizes when CMAKE_CROSSCOMPILING is true.
    • Default values for INTEGER and REAL KINDs and their sizes are set when cross-compiling.
    • Error messages are adjusted to reflect cross-compilation scenarios.
  • Logic:
    • Conditional checks added for CMAKE_CROSSCOMPILING to determine if default values should be used.
    • Default values include INTEGER KINDs {1,2,4,8,16} and REAL KINDs {4,8,10,16}.
    • Default sizes for native kinds are set to 4 for INTEGER and REAL, and 8 for DOUBLE PRECISION when cross-compiling.
  • Misc:
    • Adjustments to verbose messages to indicate when defaults are used during cross-compilation.

This description was created by Ellipsis for 0b8f640. You can customize this summary. It will automatically update as commits are pushed.

@byrnHDF
Copy link
Contributor Author

byrnHDF commented Aug 12, 2025

The mingw cross-compile gets past the configure stage and then chokes on:
FAILED: [code=1] fortran/src/CMakeFiles/H5_buildiface.dir/H5_buildiface.F90.obj
FAILED: [code=1] fortran/src/CMakeFiles/H5match_types.dir/H5match_types.c.obj

because the values from the defaults are not correctly formatted. Once the syntax is correct then we can update the toolchain with the correct values.

@nbagha1 nbagha1 moved this from To be triaged to Scheduled/On-Deck in HDF5 - TRIAGE & TRACK Sep 23, 2025
brtnfld
brtnfld previously approved these changes Sep 23, 2025
Copy link
Collaborator

@brtnfld brtnfld left a comment

Choose a reason for hiding this comment

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

📋 Pull Request Summary

Title: Rework Fortran configuration for cross-compilation supportFocus: Enhancing HDF5UseFortran.cmake to
handle cross-compilation scenarios by providing sensible default values for Fortran INTEGER and REAL kinds
when cross-compiling.

✅ Strengths

  1. Clear Problem Definition
  • Addresses a specific pain point in cross-compilation workflows
  • Targets mingw/gfortran cross-compilation which is commonly used
  • Provides fallback defaults when runtime detection isn't possible
  1. Modular Implementation
  • Clean conditional logic separating cross-compilation from native builds
  • Maintains backward compatibility with existing build processes
  • Uses CMake best practices for cross-compilation detection
  1. Verbose Configuration
  • Good logging/messaging for configuration tracking
  • Makes it easy to debug configuration issues
  • Clear indication when defaults are being used

⚠️ Areas of Concern

  1. Hardcoded Default Values

Potential issue: These defaults may not work for all compilers

set(H5_FORTRAN_DEFAULT_INTEGER_KINDS "1,2,4,8")
set(H5_FORTRAN_DEFAULT_REAL_KINDS "4,8")

Risk: Different Fortran compilers may have varying support for these kinds
Recommendation: Consider compiler-specific detection or documentation

  1. Limited Cross-Compiler Coverage
  • Currently focuses on mingw/gfortran
  • May need expansion for other cross-compilation scenarios (ARM, embedded systems, etc.)
  • Default values might not be appropriate for all target architectures
  1. Testing Gaps
  • Cross-compilation testing is inherently complex
  • Need verification across multiple compiler/target combinations
  • Risk of introducing regressions in native compilation

🔧 Technical Assessment

Code Quality: ⭐⭐⭐⭐☆

  • Well-structured CMake code
  • Clear separation of concerns
  • Good error handling and messaging

Impact Analysis: ⭐⭐⭐⭐⭐

  • Low Risk: Changes are isolated to Fortran configuration
  • High Value: Enables important cross-compilation use cases
  • Backward Compatible: Doesn't affect existing builds

Security: ⭐⭐⭐⭐⭐

  • No security implications identified
  • Actually reduces risk by providing sane defaults

📊 Recommendations

High Priority

  1. Expand Testing

Add CI jobs for multiple cross-compilation targets

  • mingw-w64 (current)
  • aarch64-linux-gnu
  • arm-linux-gnueabihf
  1. Document Default Selection

Add comments explaining why these specific defaults were chosen

Reference: ISO Fortran standard, common compiler behavior, etc.

Medium Priority

  1. Compiler-Specific Defaults

Consider different defaults based on compiler

if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(H5_FORTRAN_DEFAULT_INTEGER_KINDS "1,2,4,8")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
# Intel-specific defaults
endif()
4. Runtime Validation

Add checks to verify the defaults actually work

Generate test program to validate kind availability

Low Priority

  1. Parameterization

Allow users to override defaults

set(HDF5_FORTRAN_CROSS_COMPILE_INTEGER_KINDS "${H5_FORTRAN_DEFAULT_INTEGER_KINDS}"
CACHE STRING "INTEGER kinds for cross-compilation")

🎯 Final Recommendation

APPROVE WITH MINOR REVISIONS ✅

Rationale:

  • Addresses a legitimate need for cross-compilation support
  • Implementation is clean and low-risk
  • Benefits outweigh the concerns
  • Issues can be addressed in follow-up PRs

Merge Conditions:

  1. ✅ Add comprehensive cross-compilation testing to CI
  2. ✅ Document the rationale for default kind selections
  3. ✅ Verify defaults work with target compilers
  4. ⚠️ Consider adding compiler-specific logic (future enhancement)

@nbagha1 nbagha1 added this to the Release 2.0.0 milestone Sep 26, 2025
@byrnHDF
Copy link
Contributor Author

byrnHDF commented Sep 30, 2025

Potential issue: These defaults may not work for all compilers

The requirement is to specify the correct values in a toolchain file. gfortran defaults are just in case.
The other choice is to halt the config if cross-compile is indicated and no values are provided.

if (NOT EXISTS "${HDF5_GENERATED_SOURCE_DIR}/H5fortran_types.F90")
message (STATUS "No pre-generated H5fortran_types.F90 file found - generating one")
# execute the H5match_types program
if (CROSSCOMPILING)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is CROSSCOMPILING different from CMAKE_CROSSCOMPILING?

Copy link
Collaborator

Choose a reason for hiding this comment

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

CMAKE_CROSSCOMPILING is the standard variable
Official CMake Documentation:
Source: CMAKE_CROSSCOMPILING variable documentation
Definition: "Variable that will be set to true by CMake if the CMAKE_SYSTEM_NAME variable has been manually set (i.e. in a toolchain file or as a cache entry from the cmake command line)."
Evidence from the PR: In config/toolchain/mingw64.cmake:2:
set (CMAKE_SYSTEM_NAME Windows)
This sets CMAKE_CROSSCOMPILING to TRUE automatically (since the host system is Linux/Ubuntu). The PR uses CROSSCOMPILING (without the CMAKE_ prefix), which is not a standard CMake variable and would need to be manually defined somewhere (which it isn't in this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CROSSCOMPILING

Looks like a typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Build CMake, Autotools
Projects
Status: Scheduled/On-Deck
Development

Successfully merging this pull request may close these issues.

7 participants