feat: add AVX2 support detection for x64 Linux systems#167
Conversation
There was a problem hiding this comment.
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/cpuinfoinsidegetAvx2. - Warn when AVX2 detection fails.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WalkthroughgetAvx2 now performs Linux x64-specific detection: it reads Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ 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). 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. Comment |
There was a problem hiding this comment.
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.
⛔ Files ignored due to path filters (2)
dist/cache-save/index.jsis excluded by!**/dist/**dist/setup/index.jsis excluded by!**/dist/**
📒 Files selected for processing (1)
src/utils.ts
c3a56ce to
0c4abf5
Compare
There was a problem hiding this comment.
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.
⛔ Files ignored due to path filters (2)
dist/cache-save/index.jsis excluded by!**/dist/**dist/setup/index.jsis excluded by!**/dist/**
📒 Files selected for processing (1)
src/utils.ts
| // 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
🧹 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.
| // 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.
|
Thanks! |
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.