Skip to content

Commit 8383e7e

Browse files
committed
fix(tests): add missing await to async operations in optimize tests
- Add await to promises.mkdir() call - Add await to promises.copyFile() call for package.json - Fixes race condition where file copy happened before directory creation - Resolves 3 unhandled rejection errors in test suite
1 parent b4df037 commit 8383e7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+8822
-32
lines changed

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Makefile for Socket Mach-O compression tools
2+
CXX := /usr/bin/clang++
3+
CXXFLAGS := -std=c++17 -O3 -Wall -Wextra -mmacosx-version-min=11.0
4+
LDFLAGS := -lcompression
5+
6+
all: socket_macho_compress socket_macho_decompress
7+
8+
socket_macho_compress: socket_macho_compress.cc
9+
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS)
10+
@echo "✅ Built socket_macho_compress"
11+
12+
socket_macho_decompress: socket_macho_decompress.cc
13+
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS)
14+
@echo "✅ Built socket_macho_decompress"
15+
16+
clean:
17+
rm -f socket_macho_compress socket_macho_decompress
18+
@echo "✅ Cleaned"
19+
20+
.PHONY: all clean

docs/wasm-build-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ ls -lh socket_ai_bg.wasm*
325325
- **wasm-pack**: https://rustwasm.github.io/wasm-pack/
326326
- **wasm-opt (Binaryen)**: https://github.com/WebAssembly/binaryen
327327
- **sccache**: https://github.com/mozilla/sccache
328-
- **Ultrathink learnings**: `.claude/wasm-optimization-summary.md`
328+
- **Implementation details**: `.claude/wasm-optimization-summary.md`
329329

330330
---
331331

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@
197197
"// WASM": "",
198198
"wasm:build": "node scripts/wasm/build-unified-wasm.mjs",
199199
"wasm:build:dev": "node scripts/wasm/build-unified-wasm.mjs --dev",
200+
"wasm:optimize": "node scripts/wasm/optimize-embedded-wasm.mjs",
201+
"wasm:optimize:aggressive": "node scripts/wasm/optimize-embedded-wasm.mjs --aggressive",
200202
"wasm:benchmark": "node scripts/wasm/benchmark-build.mjs",
201203
"wasm:setup": "node scripts/wasm/setup-build-env.mjs",
202204
"// Maintenance": "",

packages/build-infra/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Build Infrastructure
2+
3+
Shared build utilities for building third-party dependencies from source.
4+
5+
## Purpose
6+
7+
This package provides reusable build infrastructure used by all from-source packages:
8+
- `smol-node` - Custom Node.js runtime
9+
- `onnx-runtime` - ONNX Runtime WASM
10+
- `codet5-models` - CodeT5 model conversion/optimization
11+
- `yoga-layout` - Yoga Layout WASM
12+
13+
## Exports
14+
15+
### Command Execution
16+
```javascript
17+
import { exec, execCapture } from '@socketsecurity/build-infra/lib/build-exec'
18+
19+
// Execute command with stdio inheritance
20+
await exec('cmake --build build', { stdio: 'inherit' })
21+
22+
// Execute and capture output
23+
const { stdout, stderr, code } = await execCapture('git rev-parse HEAD')
24+
```
25+
26+
### Build Helpers
27+
```javascript
28+
import {
29+
checkDiskSpace,
30+
checkCompiler,
31+
checkPythonVersion,
32+
estimateBuildTime,
33+
formatDuration,
34+
smokeTestBinary,
35+
} from '@socketsecurity/build-infra/lib/build-helpers'
36+
37+
// Check prerequisites
38+
await checkDiskSpace(5 * 1024 * 1024 * 1024) // 5 GB
39+
await checkCompiler('clang++')
40+
await checkPythonVersion('3.8')
41+
42+
// Smoke test binary
43+
await smokeTestBinary('./build/node', ['--version'])
44+
```
45+
46+
### Pretty Output
47+
```javascript
48+
import {
49+
printHeader,
50+
printStep,
51+
printSubstep,
52+
printSuccess,
53+
printError,
54+
printWarning,
55+
} from '@socketsecurity/build-infra/lib/build-output'
56+
57+
printHeader('Build Node.js from Source')
58+
printStep('Cloning repository')
59+
printSubstep('Fetching v24.10.0')
60+
printSuccess('Build complete!')
61+
```
62+
63+
### CMake Builder
64+
```javascript
65+
import { CMakeBuilder } from '@socketsecurity/build-infra/lib/cmake-builder'
66+
67+
const cmake = new CMakeBuilder(sourceDir, buildDir)
68+
69+
await cmake.configure({
70+
'CMAKE_BUILD_TYPE': 'Release',
71+
'CMAKE_C_FLAGS': '-Oz -flto=thin',
72+
})
73+
74+
await cmake.build({ parallel: true })
75+
```
76+
77+
### Emscripten Builder
78+
```javascript
79+
import { EmscriptenBuilder } from '@socketsecurity/build-infra/lib/emscripten-builder'
80+
81+
const emcc = new EmscriptenBuilder(sourceDir, buildDir)
82+
83+
await emcc.build({
84+
sources: ['src/**/*.cpp'],
85+
output: 'output.wasm',
86+
flags: ['-Oz', '-flto', '--no-entry'],
87+
includes: ['-Iinclude'],
88+
})
89+
```
90+
91+
### Patch Validator
92+
```javascript
93+
import {
94+
validatePatch,
95+
applyPatch,
96+
applyPatchDirectory,
97+
testPatchApplication,
98+
} from '@socketsecurity/build-infra/lib/patch-validator'
99+
100+
// Apply all patches in directory
101+
await applyPatchDirectory('./patches/socket', './source')
102+
103+
// Apply single patch
104+
await applyPatch('./patches/001-fix.patch', './source')
105+
```
106+
107+
### Checkpoint Manager
108+
```javascript
109+
import {
110+
createCheckpoint,
111+
hasCheckpoint,
112+
cleanCheckpoint,
113+
getCheckpointData,
114+
} from '@socketsecurity/build-infra/lib/checkpoint-manager'
115+
116+
// Save build state
117+
await createCheckpoint('onnx-runtime', 'configured', { version: '1.20.1' })
118+
119+
// Check if step already done
120+
if (await hasCheckpoint('onnx-runtime', 'built')) {
121+
console.log('Already built, skipping...')
122+
}
123+
124+
// Clean checkpoints
125+
await cleanCheckpoint('onnx-runtime')
126+
```
127+
128+
## Pattern
129+
130+
All from-source packages follow this pattern:
131+
132+
1. **Check prerequisites** (disk space, compilers, etc.)
133+
2. **Clone/download source**
134+
3. **Apply custom patches**
135+
4. **Configure build** (CMake, Emscripten, etc.)
136+
5. **Build** with custom flags
137+
6. **Optimize** (wasm-opt, strip, etc.)
138+
7. **Verify** output
139+
8. **Export** artifacts
140+
141+
This package provides the infrastructure for steps 1-7.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Command Execution Utilities
3+
*
4+
* Provides utilities for executing shell commands with proper error handling,
5+
* output capture, and logging.
6+
*/
7+
8+
import { spawn } from '@socketsecurity/lib/spawn'
9+
10+
/**
11+
* Execute command and inherit stdio.
12+
*
13+
* @param {string} command - Command to execute
14+
* @param {object} options - Spawn options
15+
* @returns {Promise<void>}
16+
*/
17+
export async function exec(command, options = {}) {
18+
const result = await spawn(command, [], {
19+
shell: true,
20+
stdio: options.stdio || 'pipe',
21+
stdioString: true,
22+
stripAnsi: false,
23+
...options,
24+
})
25+
26+
if (result.status !== 0) {
27+
const error = new Error(`Command failed with exit code ${result.status}: ${command}`)
28+
error.stdout = result.stdout
29+
error.stderr = result.stderr
30+
error.code = result.status
31+
throw error
32+
}
33+
34+
return result
35+
}
36+
37+
/**
38+
* Execute command and capture output.
39+
*
40+
* @param {string} command - Command to execute
41+
* @param {object} options - Spawn options
42+
* @returns {Promise<{stdout: string, stderr: string, code: number}>}
43+
*/
44+
export async function execCapture(command, options = {}) {
45+
const result = await spawn(command, [], {
46+
shell: true,
47+
stdio: 'pipe',
48+
stdioString: true,
49+
stripAnsi: false,
50+
...options,
51+
})
52+
53+
return {
54+
stdout: result.stdout ?? '',
55+
stderr: result.stderr ?? '',
56+
code: result.status ?? 0,
57+
}
58+
}

0 commit comments

Comments
 (0)