Skip to content

feat: add AVX2 support detection for x64 Linux systems#167

Merged
xhyrom merged 1 commit into
oven-sh:mainfrom
GoForceX:feat/avx2-detect
Feb 28, 2026
Merged

feat: add AVX2 support detection for x64 Linux systems#167
xhyrom merged 1 commit into
oven-sh:mainfrom
GoForceX:feat/avx2-detect

Conversation

@GoForceX

Copy link
Copy Markdown
Contributor

Add a mechanism to read /proc/cpuinfo and get AVX2 capability of the system, and choose the correct build afterwards.
Closes #166.

Have tested on both AVX2 capable and incapable server.
Only test failure is in setup-bun from (self-hosted, download url) since it explicitly provides a url to a AVX2-required version.

Copilot AI review requested due to automatic review settings February 28, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds runtime AVX2 capability detection for Linux x64 so setup-bun can pick the correct (baseline vs AVX2) Bun release asset and avoid failures on older CPUs (per #166).

Changes:

  • Add Linux x64 AVX2 detection by reading /proc/cpuinfo inside getAvx2.
  • Warn when AVX2 detection fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils.ts Outdated
Comment thread src/utils.ts
Comment thread src/utils.ts Outdated
Comment thread src/utils.ts
@coderabbitai

coderabbitai Bot commented Feb 28, 2026

Copy link
Copy Markdown

Walkthrough

getAvx2 now performs Linux x64-specific detection: it reads /proc/cpuinfo to check for the "avx2" flag and returns false when not found. File-read errors are logged as warnings; behavior for other platforms and existing fallbacks is unchanged.

Changes

Cohort / File(s) Summary
CPU Capability Detection
src/utils.ts
Adds Linux x64-specific AVX2 detection in getAvx2 by reading /proc/cpuinfo and checking for "avx2". Returns false if absent; logs a warning on read failure. Existing Windows/ARM64 and general fallback logic remain unchanged.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding AVX2 support detection for x64 Linux systems.
Description check ✅ Passed The description is directly related to the changeset, explaining the AVX2 detection mechanism and test results.
Linked Issues check ✅ Passed The PR implements the preferred solution from issue #166: detecting CPU AVX2 capabilities by reading /proc/cpuinfo before download.
Out of Scope Changes check ✅ Passed All changes in src/utils.ts are scoped to implementing AVX2 detection for x64 Linux systems, directly addressing the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils.ts`:
- Around line 107-112: The AVX2 detection try/catch currently only warns on
error and then returns avx2 ?? true, which lets failures default to true; change
the fallback to fail-closed by returning avx2 ?? false and keep/upgrade the log
inside the catch (the try/catch around AVX2 detection and the avx2 variable) so
that when detection throws we log the error and the function returns false
instead of true.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0ff83bf and c3a56ce.

⛔ Files ignored due to path filters (2)
  • dist/cache-save/index.js is excluded by !**/dist/**
  • dist/setup/index.js is excluded by !**/dist/**
📒 Files selected for processing (1)
  • src/utils.ts

Comment thread src/utils.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils.ts`:
- Around line 101-111: The warning message in the AVX2 detection block (inside
src/utils.ts where avx2 is checked and readFileSync("/proc/cpuinfo") is used)
lacks the caught error details; modify the catch block to include the caught
error information when calling warning (e.g., include error.message or the error
object) so the log shows the failure reason while preserving the current
fail-closed return false behavior.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c3a56ce and 0c4abf5.

⛔ Files ignored due to path filters (2)
  • dist/cache-save/index.js is excluded by !**/dist/**
  • dist/setup/index.js is excluded by !**/dist/**
📒 Files selected for processing (1)
  • src/utils.ts

Comment thread src/utils.ts
Comment on lines +101 to +111
// Check AVX2 support on x64 Linux
if (os === "linux" && arch === "x64" && avx2 === undefined) {
try {
const cpuInfo = readFileSync("/proc/cpuinfo", "utf8");
const hasAvx2 = cpuInfo.includes("avx2");
return hasAvx2;
} catch (error) {
warning(`Failed to detect AVX2 support.`);
return false;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

LGTM! Fail-closed behavior correctly implemented.

The AVX2 detection logic is sound: it only activates for Linux x64 when avx2 is not explicitly set, and correctly returns false on detection failure (addressing the concern from the previous review).

One minor suggestion: consider including the error details in the warning message for easier debugging when detection fails.

💡 Optional: include error details in warning
     } catch (error) {
-      warning(`Failed to detect AVX2 support.`);
+      warning(`Failed to detect AVX2 support: ${error}`);
       return false;
     }

,

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Check AVX2 support on x64 Linux
if (os === "linux" && arch === "x64" && avx2 === undefined) {
try {
const cpuInfo = readFileSync("/proc/cpuinfo", "utf8");
const hasAvx2 = cpuInfo.includes("avx2");
return hasAvx2;
} catch (error) {
warning(`Failed to detect AVX2 support.`);
return false;
}
}
// Check AVX2 support on x64 Linux
if (os === "linux" && arch === "x64" && avx2 === undefined) {
try {
const cpuInfo = readFileSync("/proc/cpuinfo", "utf8");
const hasAvx2 = cpuInfo.includes("avx2");
return hasAvx2;
} catch (error) {
warning(`Failed to detect AVX2 support: ${error}`);
return false;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils.ts` around lines 101 - 111, The warning message in the AVX2
detection block (inside src/utils.ts where avx2 is checked and
readFileSync("/proc/cpuinfo") is used) lacks the caught error details; modify
the catch block to include the caught error information when calling warning
(e.g., include error.message or the error object) so the log shows the failure
reason while preserving the current fail-closed return false behavior.

@xhyrom xhyrom left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@xhyrom xhyrom merged commit 4c32875 into oven-sh:main Feb 28, 2026
87 checks passed
@xhyrom

xhyrom commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

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.

regression: setup-bun fails on older CPUs without AVX/AVX2 capability

3 participants