@gajae-code/natives 0.14.0 → 0.14.1
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/native/index.d.ts +1 -1
- package/native/index.js +1 -1
- package/native/loader-state.d.ts +5 -0
- package/native/loader-state.js +49 -8
- package/package.json +6 -6
package/native/index.d.ts
CHANGED
|
@@ -501,7 +501,7 @@ export declare function __piNativesPublishOutcomeV1(): void
|
|
|
501
501
|
* `packages/natives/native/index.js` (which derives the name from
|
|
502
502
|
* `package.json#version`).
|
|
503
503
|
*/
|
|
504
|
-
export declare function
|
|
504
|
+
export declare function __piNativesV0_14_1(): void
|
|
505
505
|
|
|
506
506
|
/**
|
|
507
507
|
* Apply conservative pre-execution rewrites to a bash command.
|
package/native/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export const Shell = nativeBindings.Shell;
|
|
|
30
30
|
|
|
31
31
|
// functions
|
|
32
32
|
export const __piNativesPublishOutcomeV1 = nativeBindings.__piNativesPublishOutcomeV1;
|
|
33
|
-
export const
|
|
33
|
+
export const __piNativesV0_14_1 = nativeBindings.__piNativesV0_14_1;
|
|
34
34
|
export const applyBashFixups = nativeBindings.applyBashFixups;
|
|
35
35
|
export const applyOwnerOnlyFdSecurity = nativeBindings.applyOwnerOnlyFdSecurity;
|
|
36
36
|
export const applyOwnerOnlyPathSecurity = nativeBindings.applyOwnerOnlyPathSecurity;
|
package/native/loader-state.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ export interface DetectCompiledBinaryInput {
|
|
|
18
18
|
|
|
19
19
|
export function detectCompiledBinary(input: DetectCompiledBinaryInput): boolean;
|
|
20
20
|
|
|
21
|
+
export function detectWin32Avx2Support(
|
|
22
|
+
probe?: () => boolean | undefined,
|
|
23
|
+
command?: (file: string, args: string[]) => string | null,
|
|
24
|
+
): boolean;
|
|
25
|
+
|
|
21
26
|
export interface GetAddonFilenamesInput {
|
|
22
27
|
tag: string;
|
|
23
28
|
arch: string;
|
package/native/loader-state.js
CHANGED
|
@@ -248,7 +248,11 @@ export function cachedEmbeddedExtractionIsFresh({ targetPath, embeddedPath, size
|
|
|
248
248
|
|
|
249
249
|
function runCommand(command, args) {
|
|
250
250
|
try {
|
|
251
|
-
|
|
251
|
+
// `windowsHide` keeps probes console-less: from a detached, console-less
|
|
252
|
+
// parent (e.g. the SDK broker) spawning a console app like powershell.exe
|
|
253
|
+
// would otherwise allocate and flash a visible console window per call
|
|
254
|
+
// (#4652). It is ignored on POSIX.
|
|
255
|
+
const result = childProcess.spawnSync(command, args, { encoding: "utf-8", windowsHide: true });
|
|
252
256
|
if (result.error) return null;
|
|
253
257
|
if (result.status !== 0) return null;
|
|
254
258
|
return (result.stdout || "").trim();
|
|
@@ -257,6 +261,49 @@ function runCommand(command, args) {
|
|
|
257
261
|
}
|
|
258
262
|
}
|
|
259
263
|
|
|
264
|
+
// `IsProcessorFeaturePresent(PF_AVX2_INSTRUCTIONS_AVAILABLE)` — the kernel's
|
|
265
|
+
// authoritative AVX2 answer (also honors OS emulation policy), usable without
|
|
266
|
+
// a subprocess on every supported Windows build.
|
|
267
|
+
const WIN32_PF_AVX2_INSTRUCTIONS_AVAILABLE = 40;
|
|
268
|
+
|
|
269
|
+
// In-process `kernel32.dll!IsProcessorFeaturePresent` probe. Returns undefined
|
|
270
|
+
// when it cannot run (non-Bun runtime, FFI unavailable, or call failure) so the
|
|
271
|
+
// caller can fall back to a hidden PowerShell probe.
|
|
272
|
+
function probeWin32Avx2InProcess() {
|
|
273
|
+
if (typeof Bun === "undefined") return undefined;
|
|
274
|
+
try {
|
|
275
|
+
// Not a static import: loader-state is plain JS that must also parse
|
|
276
|
+
// under Node, where "bun:ffi" does not exist.
|
|
277
|
+
const { dlopen } = createRequire(import.meta.url)("bun:ffi");
|
|
278
|
+
const kernel32 = dlopen("kernel32.dll", {
|
|
279
|
+
IsProcessorFeaturePresent: { args: ["i32"], returns: "bool" },
|
|
280
|
+
});
|
|
281
|
+
return Boolean(kernel32.symbols.IsProcessorFeaturePresent(WIN32_PF_AVX2_INSTRUCTIONS_AVAILABLE));
|
|
282
|
+
} catch {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Hidden PowerShell fallback. `Add-Type` P/Invoke works on both stock Windows
|
|
288
|
+
// PowerShell 5.1 (.NET Framework, which has no System.Runtime.Intrinsics) and
|
|
289
|
+
// pwsh 7+. Any probe failure fails safe to `false` (baseline variant).
|
|
290
|
+
function probeWin32Avx2ViaPowerShell(run = runCommand) {
|
|
291
|
+
const output = run("powershell.exe", [
|
|
292
|
+
"-NoProfile",
|
|
293
|
+
"-NonInteractive",
|
|
294
|
+
"-Command",
|
|
295
|
+
"Add-Type -Namespace GjcNative -Name Cpu -MemberDefinition '[DllImport(\"kernel32.dll\")] public static extern bool IsProcessorFeaturePresent(int feature);'; " +
|
|
296
|
+
`[GjcNative.Cpu]::IsProcessorFeaturePresent(${WIN32_PF_AVX2_INSTRUCTIONS_AVAILABLE})`,
|
|
297
|
+
]);
|
|
298
|
+
return output !== null && output.toLowerCase() === "true";
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function detectWin32Avx2Support(probe = probeWin32Avx2InProcess, run = runCommand) {
|
|
302
|
+
const probed = probe();
|
|
303
|
+
if (probed !== undefined) return probed;
|
|
304
|
+
return probeWin32Avx2ViaPowerShell(run);
|
|
305
|
+
}
|
|
306
|
+
|
|
260
307
|
function getVariantOverride() {
|
|
261
308
|
const value = process.env.PI_NATIVE_VARIANT;
|
|
262
309
|
if (!value) return null;
|
|
@@ -288,13 +335,7 @@ function detectAvx2Support() {
|
|
|
288
335
|
}
|
|
289
336
|
|
|
290
337
|
if (process.platform === "win32") {
|
|
291
|
-
|
|
292
|
-
"-NoProfile",
|
|
293
|
-
"-NonInteractive",
|
|
294
|
-
"-Command",
|
|
295
|
-
"[System.Runtime.Intrinsics.X86.Avx2]::IsSupported",
|
|
296
|
-
]);
|
|
297
|
-
return output && output.toLowerCase() === "true";
|
|
338
|
+
return detectWin32Avx2Support();
|
|
298
339
|
}
|
|
299
340
|
|
|
300
341
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gajae-code/natives",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Native Rust bindings for grep, clipboard, image processing, syntax highlighting, PTY, and shell operations via N-API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://gajae-code.com",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"README.md"
|
|
62
62
|
],
|
|
63
63
|
"optionalDependencies": {
|
|
64
|
-
"@gajae-code/natives-darwin-arm64": "0.14.
|
|
65
|
-
"@gajae-code/natives-darwin-x64": "0.14.
|
|
66
|
-
"@gajae-code/natives-linux-arm64": "0.14.
|
|
67
|
-
"@gajae-code/natives-linux-x64": "0.14.
|
|
68
|
-
"@gajae-code/natives-win32-x64": "0.14.
|
|
64
|
+
"@gajae-code/natives-darwin-arm64": "0.14.1",
|
|
65
|
+
"@gajae-code/natives-darwin-x64": "0.14.1",
|
|
66
|
+
"@gajae-code/natives-linux-arm64": "0.14.1",
|
|
67
|
+
"@gajae-code/natives-linux-x64": "0.14.1",
|
|
68
|
+
"@gajae-code/natives-win32-x64": "0.14.1"
|
|
69
69
|
},
|
|
70
70
|
"exports": {
|
|
71
71
|
".": {
|