MCPcopy Create free account
hub / github.com/anomalyco/opencode / supportsAvx2

Function supportsAvx2

packages/opencode/script/postinstall.mjs:31–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29const targetBinary = path.join(__dirname, "bin", "opencode.exe")
30
31function supportsAvx2() {
32 if (arch !== "x64") return false
33
34 if (platform === "linux") {
35 try {
36 return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
37 } catch {
38 return false
39 }
40 }
41
42 if (platform === "darwin") {
43 try {
44 const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
45 encoding: "utf8",
46 timeout: 1500,
47 })
48 if (result.status !== 0) return false
49 return (result.stdout || "").trim() === "1"
50 } catch {
51 return false
52 }
53 }
54
55 if (platform === "windows") {
56 const command =
57 '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
58
59 for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
60 try {
61 const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
62 encoding: "utf8",
63 timeout: 3000,
64 windowsHide: true,
65 })
66 if (result.status !== 0) continue
67 const output = (result.stdout || "").trim().toLowerCase()
68 if (output === "true" || output === "1") return true
69 if (output === "false" || output === "0") return false
70 } catch {
71 continue
72 }
73 }
74 }
75
76 return false
77}
78
79function isMusl() {
80 if (platform !== "linux") return false

Callers 1

packageNamesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected