Skip to content

riscv: add bash configure script support for riscv#1904

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
Ag-Cu:riscv_dev
May 1, 2025
Merged

riscv: add bash configure script support for riscv#1904
Dead2 merged 1 commit intozlib-ng:developfrom
Ag-Cu:riscv_dev

Conversation

@Ag-Cu
Copy link
Copy Markdown

@Ag-Cu Ag-Cu commented Apr 15, 2025

Summary by CodeRabbit

  • New Features

    • Added build and configuration support for the RISC-V 64-bit architecture, including detection and enabling of RISC-V Vector Extension (RVV) optimizations.
  • Chores

    • Introduced a new Makefile to manage RISC-V vector extension source files and build targets.
    • Updated the configuration process to automatically detect and enable RVV support when available, with an option to disable it.
    • Extended continuous integration workflows to include RISC-V 64-bit cross-compilation and testing with and without RVV support.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2025

"""

Walkthrough

The changes introduce support for the RISC-V 64-bit architecture and its Vector Extension (RVV) into the build system. A new Makefile for RISC-V is added, specifying compilation rules for RVV-optimized source files and handling both regular and position-independent object files. The configure script is updated to detect the RISC-V architecture, test for RVV support, and adjust build variables and object lists accordingly. If RVV is available, appropriate compiler flags and source files are included in the build. The GitHub Actions workflows are extended to include RISCV64 cross-compilation and testing configurations. Standard cleaning and build targets are defined for the new architecture.

Changes

File(s) Change Summary
arch/riscv/Makefile.in Added new Makefile for RISC-V, defining build rules for RVV-optimized sources, compiler flags, and clean targets.
configure Extended to detect riscv64 architecture, test for RVV support, add --without-rvv option, and update build variables and object file lists accordingly.
.github/workflows/configure.yml Added three new RISCV64 build matrix entries with various RVV and optimization configurations for CI testing.
.github/workflows/pkgcheck.yml Added new RISCV64 matrix entry for package checking with RISC-V cross-compilation toolchain and required packages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigureScript
    participant Compiler
    participant Makefile

    User->>ConfigureScript: Run configure
    ConfigureScript->>Compiler: Detect architecture (riscv64)
    Compiler-->>ConfigureScript: Returns architecture info
    ConfigureScript->>Compiler: Test compile with -march=rv64gcv for RVV
    Compiler-->>ConfigureScript: Success/Failure
    alt RVV supported
        ConfigureScript->>ConfigureScript: Set HAVE_RVV=1, update flags, add RVV objects
    else RVV not supported
        ConfigureScript->>ConfigureScript: Set HAVE_RVV=0, skip RVV objects
    end
    ConfigureScript->>Makefile: Generate/adjust Makefile with appropriate targets and flags
    User->>Makefile: Build project (make)
    Makefile->>Compiler: Compile RVV and other source files as needed
Loading

Suggested labels

Continuous Integration, Architecture

Suggested reviewers

  • Dead2
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecfaf89 and e65c14f.

📒 Files selected for processing (4)
  • .github/workflows/configure.yml (1 hunks)
  • .github/workflows/pkgcheck.yml (1 hunks)
  • arch/riscv/Makefile.in (1 hunks)
  • configure (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • arch/riscv/Makefile.in
  • .github/workflows/pkgcheck.yml
  • configure
  • .github/workflows/configure.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
arch/riscv/Makefile.in (1)

6-11: Consider default values for build variables.

Currently, CC, CFLAGS, and SFLAGS are defined but not initialized to defaults. If the build environment fails to provide them, it may cause confusion.

An example approach:

-CC=
-CFLAGS=
-SFLAGS=
+CC ?= gcc
+CFLAGS ?= -O2
+SFLAGS ?= -O2
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00a3168 and 0fc4607.

📒 Files selected for processing (2)
  • arch/riscv/Makefile.in (1 hunks)
  • configure (2 hunks)
🔇 Additional comments (6)
configure (2)

346-347: Looks consistent with other architectures.

Introducing a riscv64) case under the existing ARCH detection logic aligns well with the structure used for other architectures. No immediate issues spotted with syntax or logic here.


1972-2004:

Details

❓ Verification inconclusive

Verify backward compatibility with older RISC-V compilers.

While the RVV detection and flag application look correct, ensure that compilers lacking -march=rv64gcv support gracefully proceed (or fall back) rather than failing outright.

Would you like to confirm compatibility by compiling this snippet against an older RISC-V GCC toolchain?


🏁 Script executed:

#!/bin/bash
# Checking if older RISC-V compilers gracefully ignore or fail on -march=rv64gcv
echo 'int main(){return 0;}' > old_riscv_test.c
"$CC" -march=rv64gcv $CFLAGS -o /dev/null old_riscv_test.c 2>&1

Length of output: 171


Action Required: Validate Compatibility with Older RISC-V Compilers

It appears that the compatibility test using the -march=rv64gcv flag didn’t run as intended because the $CC variable wasn’t set (resulting in a "command not found" error). This makes it unclear whether older RISC-V compilers would gracefully ignore the flag or fall back properly. Please ensure that a valid, older RISC-V GCC toolchain is specified (by setting $CC) and re-run the check, or manually verify that unsupported compilers proceed without failure.

arch/riscv/Makefile.in (4)

1-5: License headers are clearly stated.

The inclusion of the copyright and distribution notice is explicit and straightforward.


19-24: Solid grouping of object files.

Bundling all .o and .lo targets together under the all target is a clear and concise approach, ensuring consistent build steps for both static and PIC artifacts.


26-55: Compilation rules appear correct.

Each object file is compiled both normally and with -DPIC for position-independent usage. This is standard practice for producing static and shared libraries.


56-63: Cleanup targets are comprehensive.

The mostlyclean, clean, and distclean targets effectively address temporary files, object files, coverage data, and Makefile removal, aligning with typical GNU conventions.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Apr 15, 2025

This needs CI run added to verify there is no errors or will be regressions.

@Ag-Cu Ag-Cu force-pushed the riscv_dev branch 2 times, most recently from 9a5f11d to 072c719 Compare April 15, 2025 13:10
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
configure (1)

1649-1656: Consider using a defined constant for RVV capability detection.

The code uses a bit shift operation (1 << ('V' - 'A')) to check for the RISC-V Vector extension capability bit. Using a predefined constant like HWCAP_ISA_V (if available in standard headers) might be more maintainable and less error-prone across different systems.

-    return (hwcap & (1 << ('V' - 'A')));  // HWCAP_ISA_V
+    // Use the defined constant if available, otherwise fall back to bit calculation
+    #ifdef HWCAP_ISA_V
+        return (hwcap & HWCAP_ISA_V);
+    #else
+        return (hwcap & (1 << ('V' - 'A')));  // HWCAP_ISA_V
+    #endif
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a5f11d and 072c719.

📒 Files selected for processing (2)
  • arch/riscv/Makefile.in (1 hunks)
  • configure (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • arch/riscv/Makefile.in
🔇 Additional comments (8)
configure (8)

102-102: New build flag for RVV support added correctly.

The new buildrvv=1 flag follows the same pattern as other architecture-specific build flags.


121-121: New compiler flag variable for RVV added correctly.

The rvvflag= variable is properly initialized as an empty string, consistent with other architecture-specific compiler flags.


175-175: Help text added for the new command-line option.

The help text for --without-rvv follows the established pattern and clearly describes its purpose.


212-212: Command-line option handling added properly.

The --without-rvv option processing is correctly implemented, setting buildrvv=0 when specified.


350-351: RISC-V architecture detection added correctly.

Detection for riscv64 architecture is properly implemented in the compiler detection phase.


1615-1663: RVV compiler flag detection function is comprehensive.

The check_rvv_compiler_flag function correctly:

  1. Tests for RVV-related march flags in order of preference
  2. Verifies RVV intrinsics compilation using the RISC-V vector header
  3. Checks for runtime detection support via auxiliary vector

The implementation follows the same pattern as other architecture-specific detection functions in the script.


2026-2050: RISC-V architecture-specific configuration is well implemented.

The implementation correctly:

  1. Sets QEMU_ARCH=riscv64 for cross-compilation
  2. Configures the architecture directory as arch/riscv
  3. Calls check_rvv_compiler_flag when optimizations are enabled
  4. Adds the appropriate RVV-specific object files when supported
  5. Appends +rvv to the architecture string

This follows the pattern established for other architectures and properly enables RVV optimizations when available.


1615-2050: Add CI testing for RISC-V configuration.

As mentioned in PR comments, ensure that CI testing is set up for the RISC-V architecture support to verify that these changes work correctly and don't introduce regressions.

This could be tested by setting up a RISC-V build environment in CI or using emulation to verify the build process with various RVV-related options.

@Ag-Cu
Copy link
Copy Markdown
Author

Ag-Cu commented Apr 15, 2025

This needs CI run added to verify there is no errors or will be regressions.

Hi, I have fixed some issues, tested in qemu and it seems working fine, so how can I get CI run for this MR?

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Apr 15, 2025

This needs CI run added to verify there is no errors or will be regressions.

Hi, I have fixed some issues, tested in qemu and it seems working fine, so how can I get CI run for this MR?

Edit /.github/workflows/configure.yml ... You can use other entries in that same file, and equivalent entry in /.github/workflows/cmake.yml as guide.

@Dead2
Copy link
Copy Markdown
Member

Dead2 commented Apr 15, 2025

Consider also adding it to pkgcheck.yml, that way it will build using both CMake and Configure and throw an error if they end up being different.
This helps avoid bugs, different default, missing detection, etc between the two.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.96%. Comparing base (e4a31e0) to head (e65c14f).
Report is 12 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1904      +/-   ##
===========================================
- Coverage    83.42%   81.96%   -1.47%     
===========================================
  Files          144      146       +2     
  Lines        12948    13269     +321     
  Branches      2857     2944      +87     
===========================================
+ Hits         10802    10876      +74     
- Misses        1202     1446     +244     
- Partials       944      947       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ag-Cu Ag-Cu force-pushed the riscv_dev branch 3 times, most recently from 7d1fc6a to 785ce99 Compare April 16, 2025 10:59
@Ag-Cu Ag-Cu requested a review from mtl1979 April 17, 2025 02:09
Copy link
Copy Markdown
Member

@nmoinvaz nmoinvaz left a comment

Choose a reason for hiding this comment

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

LGTM

@Ag-Cu Ag-Cu requested a review from mtl1979 April 21, 2025 07:32
@Ag-Cu
Copy link
Copy Markdown
Author

Ag-Cu commented Apr 21, 2025

Hi, Any more comments here?

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Apr 24, 2025

Hi, Any more comments here?

Still fails CI... configure seems to have extra white-space causing lint to fail...

Copy link
Copy Markdown
Member

@Dead2 Dead2 left a comment

Choose a reason for hiding this comment

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

LGTM

@Dead2 Dead2 merged commit 830995f into zlib-ng:develop May 1, 2025
140 of 146 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants