@synsci/openscience 2.0.27-test.93.1 → 2.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/openscience CHANGED
@@ -35,6 +35,28 @@ function detectMusl(platform = os.platform()) {
35
35
  }
36
36
  }
37
37
 
38
+ function cpuSupportsAvx2(platform = os.platform(), arch = os.arch(), linuxInfo) {
39
+ if (arch !== "x64") return undefined
40
+ if (platform === "linux") {
41
+ const info = (() => {
42
+ if (linuxInfo !== undefined) return linuxInfo
43
+ try {
44
+ return fs.readFileSync("/proc/cpuinfo", "utf8")
45
+ } catch {
46
+ return undefined
47
+ }
48
+ })()
49
+ if (!info) return undefined
50
+ const flags = /^(?:flags|features)\s*:\s*(.+)$/im.exec(info)?.[1]
51
+ if (!flags) return undefined
52
+ return flags.toLowerCase().split(/\s+/).includes("avx2")
53
+ }
54
+ if (platform !== "darwin") return undefined
55
+ const result = childProcess.spawnSync("sysctl", ["-n", "machdep.cpu.leaf7_features"], { encoding: "utf8" })
56
+ if (result.status !== 0) return undefined
57
+ return result.stdout.toLowerCase().split(/\s+/).includes("avx2")
58
+ }
59
+
38
60
  function expectedPlatformPackages(platform, arch, musl) {
39
61
  const suffix = musl ? "-musl" : ""
40
62
  const name = `openscience-${platform}-${arch}${suffix}`
@@ -104,7 +126,8 @@ function run(target) {
104
126
  console.error(
105
127
  `openscience was terminated by ${result.signal}. The prebuilt native binary may be ` +
106
128
  `incompatible with this host (platform ${os.platform()}, arch ${os.arch()}). ` +
107
- `Some ARM64 hosts (e.g. 64KB page-size kernels) cannot run the prebuilt binary. ` +
129
+ `Some ARM64 hosts (e.g. 64KB page-size kernels) and x86-64 hosts without AVX2 ` +
130
+ `cannot run the optimized prebuilt binary. ` +
108
131
  `Try reinstalling, set OPENSCIENCE_BIN_PATH to a compatible binary, or report at ` +
109
132
  `https://github.com/synthetic-sciences/openscience/issues`,
110
133
  )
@@ -128,17 +151,20 @@ function isBinary(p) {
128
151
  }
129
152
 
130
153
  // Rank matching platform packages instead of trusting readdir order (which
131
- // is filesystem-dependent): right libc first, exact name before suffixed
132
- // variants like -baseline, wrong libc only as a last resort.
133
- function variantRank(prefix, entry, preferMusl) {
154
+ // is filesystem-dependent): right libc first, then the CPU-compatible build,
155
+ // with wrong-libc packages only as a last resort.
156
+ function variantRank(prefix, entry, preferMusl, preferBaseline = false) {
134
157
  const entryMusl = entry.includes("-musl")
135
158
  if (entryMusl !== preferMusl) return 0
136
- return entry === prefix || entry === prefix + "-musl" ? 2 : 1
159
+ const entryBaseline = entry.includes("-baseline")
160
+ return entryBaseline === preferBaseline ? 2 : 1
137
161
  }
138
- function matchingVariants(prefix, entries, preferMusl) {
162
+ function matchingVariants(prefix, entries, preferMusl, preferBaseline = false) {
139
163
  return entries
140
164
  .filter((entry) => entry.startsWith(prefix))
141
- .sort((a, b) => variantRank(prefix, b, preferMusl) - variantRank(prefix, a, preferMusl))
165
+ .sort(
166
+ (a, b) => variantRank(prefix, b, preferMusl, preferBaseline) - variantRank(prefix, a, preferMusl, preferBaseline),
167
+ )
142
168
  }
143
169
 
144
170
  function main() {
@@ -158,6 +184,7 @@ function main() {
158
184
  const base = "openscience-" + platform + "-" + arch
159
185
  const scopedBase = "openscience-" + platform + "-" + arch
160
186
  const musl = detectMusl()
187
+ const baseline = cpuSupportsAvx2(os.platform(), os.arch()) === false
161
188
 
162
189
  // Search this install's node_modules for the matching platform package.
163
190
  // This must come before ~/.openscience or Homebrew fallbacks; otherwise an npm
@@ -168,7 +195,7 @@ function main() {
168
195
  if (fs.existsSync(modules)) {
169
196
  try {
170
197
  const entries = fs.readdirSync(modules)
171
- for (const entry of matchingVariants(base, entries, musl)) {
198
+ for (const entry of matchingVariants(base, entries, musl, baseline)) {
172
199
  const candidate = path.join(modules, entry, "bin", binary)
173
200
  if (isBinary(candidate)) run(candidate)
174
201
  }
@@ -176,7 +203,7 @@ function main() {
176
203
  const scoped = path.join(modules, "@synsci")
177
204
  if (fs.existsSync(scoped)) {
178
205
  const scopedEntries = fs.readdirSync(scoped)
179
- for (const entry of matchingVariants(scopedBase, scopedEntries, musl)) {
206
+ for (const entry of matchingVariants(scopedBase, scopedEntries, musl, baseline)) {
180
207
  const candidate = path.join(scoped, entry, "bin", binary)
181
208
  if (isBinary(candidate)) run(candidate)
182
209
  }
@@ -201,6 +228,7 @@ function main() {
201
228
  }
202
229
 
203
230
  module.exports = {
231
+ cpuSupportsAvx2,
204
232
  detectMusl,
205
233
  exitCodeForResult,
206
234
  expectedPlatformPackages,
package/package.json CHANGED
@@ -7,23 +7,23 @@
7
7
  "preinstall": "node ./preinstall.mjs || exit 0",
8
8
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs || exit 0"
9
9
  },
10
- "version": "2.0.27-test.93.1",
10
+ "version": "2.0.28",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/synthetic-sciences/openscience.git"
14
14
  },
15
15
  "optionalDependencies": {
16
16
  "@synsci/atlas": "^0.13.2",
17
- "@synsci/openscience-windows-x64": "2.0.27-test.93.1",
18
- "@synsci/openscience-darwin-x64": "2.0.27-test.93.1",
19
- "@synsci/openscience-darwin-x64-baseline": "2.0.27-test.93.1",
20
- "@synsci/openscience-linux-x64-baseline": "2.0.27-test.93.1",
21
- "@synsci/openscience-linux-x64-musl": "2.0.27-test.93.1",
22
- "@synsci/openscience-linux-arm64-musl": "2.0.27-test.93.1",
23
- "@synsci/openscience-windows-x64-baseline": "2.0.27-test.93.1",
24
- "@synsci/openscience-linux-x64-baseline-musl": "2.0.27-test.93.1",
25
- "@synsci/openscience-linux-arm64": "2.0.27-test.93.1",
26
- "@synsci/openscience-darwin-arm64": "2.0.27-test.93.1",
27
- "@synsci/openscience-linux-x64": "2.0.27-test.93.1"
17
+ "@synsci/openscience-windows-x64": "2.0.28",
18
+ "@synsci/openscience-darwin-x64": "2.0.28",
19
+ "@synsci/openscience-darwin-x64-baseline": "2.0.28",
20
+ "@synsci/openscience-linux-x64-baseline": "2.0.28",
21
+ "@synsci/openscience-linux-x64-musl": "2.0.28",
22
+ "@synsci/openscience-linux-arm64-musl": "2.0.28",
23
+ "@synsci/openscience-windows-x64-baseline": "2.0.28",
24
+ "@synsci/openscience-linux-x64-baseline-musl": "2.0.28",
25
+ "@synsci/openscience-linux-arm64": "2.0.28",
26
+ "@synsci/openscience-darwin-arm64": "2.0.28",
27
+ "@synsci/openscience-linux-x64": "2.0.28"
28
28
  }
29
29
  }
package/postinstall.mjs CHANGED
@@ -57,6 +57,28 @@ function detectMusl(platform) {
57
57
  }
58
58
  }
59
59
 
60
+ function cpuSupportsAvx2(platform, arch, linuxInfo) {
61
+ if (arch !== "x64") return undefined
62
+ if (platform === "linux") {
63
+ const info = (() => {
64
+ if (linuxInfo !== undefined) return linuxInfo
65
+ try {
66
+ return fs.readFileSync("/proc/cpuinfo", "utf8")
67
+ } catch {
68
+ return undefined
69
+ }
70
+ })()
71
+ if (!info) return undefined
72
+ const flags = /^(?:flags|features)\s*:\s*(.+)$/im.exec(info)?.[1]
73
+ if (!flags) return undefined
74
+ return flags.toLowerCase().split(/\s+/).includes("avx2")
75
+ }
76
+ if (platform !== "darwin") return undefined
77
+ const result = childProcess.spawnSync("sysctl", ["-n", "machdep.cpu.leaf7_features"], { encoding: "utf8" })
78
+ if (result.status !== 0) return undefined
79
+ return result.stdout.toLowerCase().split(/\s+/).includes("avx2")
80
+ }
81
+
60
82
  function linuxKernelProblem(platform, release = os.release()) {
61
83
  if (platform !== "linux") return undefined
62
84
  const match = /^(\d+)\.(\d+)/.exec(release)
@@ -84,11 +106,19 @@ function linuxArm64PageSizeProblem(platform, arch, detectedPageSize) {
84
106
  ].join("; ")
85
107
  }
86
108
 
87
- function platformPackageNames(platform, arch, musl = detectMusl(platform)) {
109
+ function platformPackageNames(
110
+ platform,
111
+ arch,
112
+ musl = detectMusl(platform),
113
+ preferBaseline = cpuSupportsAvx2(platform, arch) === false,
114
+ ) {
88
115
  const base = `openscience-${platform}-${arch}`
89
116
  const variants = musl ? [`${base}-musl`] : [base]
90
117
  if (arch === "x64") variants.push(musl ? `${base}-baseline-musl` : `${base}-baseline`)
91
- return variants.flatMap((name) => [`@synsci/${name}`, name])
118
+ const ranked = preferBaseline
119
+ ? variants.sort((a, b) => Number(b.includes("-baseline")) - Number(a.includes("-baseline")))
120
+ : variants
121
+ return ranked.flatMap((name) => [`@synsci/${name}`, name])
92
122
  }
93
123
 
94
124
  function findBinary() {
@@ -186,6 +216,7 @@ function main() {
186
216
  }
187
217
 
188
218
  export {
219
+ cpuSupportsAvx2,
189
220
  detectMusl,
190
221
  detectPlatformAndArch,
191
222
  findBinary,