Remove vendored Windows binaries (#9318)

Signed-off-by: jh-block <jhugo@block.xyz>
This commit is contained in:
jh-block
2026-05-19 14:25:32 +02:00
committed by GitHub
parent bdb7d214e7
commit 1997799a4a
10 changed files with 165 additions and 79 deletions
+2
View File
@@ -5,6 +5,8 @@ src/bin/goosed
src/bin/goose-npm/
/src/bin/*.exe
/src/bin/*.cmd
/src/platform/windows/bin/*.dll
/src/platform/windows/bin/*.exe
/playwright-report/
/test-results/
/src/bin/temporal-service
+127 -7
View File
@@ -1,9 +1,19 @@
const fs = require('fs');
const crypto = require('crypto');
const https = require('https');
const os = require('os');
const path = require('path');
const { execFileSync } = require('child_process');
// Paths
const srcBinDir = path.join(__dirname, '..', 'src', 'bin');
const platformWinDir = path.join(__dirname, '..', 'src', 'platform', 'windows', 'bin');
const uvVersion = '0.11.11';
const uvDownloadUrl = `https://github.com/astral-sh/uv/releases/download/${uvVersion}/uv-x86_64-pc-windows-msvc.zip`;
const uvBinaryHashes = {
'uv.exe': 'b1645e948603c12dd741987d0c072471195e18dd299b42334477ceac694f0af8',
'uvx.exe': '0305c488dc29c16df1483c02a902d21a6798b0744f8e9eb34271d6b3e4bf6e2a',
};
// Platform-specific file patterns
const windowsFiles = [
@@ -49,6 +59,106 @@ function matchesPattern(filename, patterns) {
});
}
function sha256(filePath) {
const hash = crypto.createHash('sha256');
hash.update(fs.readFileSync(filePath));
return hash.digest('hex');
}
function hasExpectedHash(filePath, expectedHash) {
return fs.existsSync(filePath) && sha256(filePath) === expectedHash;
}
function downloadFile(url, destPath, redirectsRemaining = 5) {
return new Promise((resolve, reject) => {
https.get(url, response => {
if (
response.statusCode >= 300 &&
response.statusCode < 400 &&
response.headers.location &&
redirectsRemaining > 0
) {
response.resume();
downloadFile(response.headers.location, destPath, redirectsRemaining - 1)
.then(resolve)
.catch(reject);
return;
}
if (response.statusCode !== 200) {
response.resume();
reject(new Error(`Failed to download ${url}: HTTP ${response.statusCode}`));
return;
}
const file = fs.createWriteStream(destPath);
response.pipe(file);
file.on('finish', () => file.close(resolve));
file.on('error', reject);
}).on('error', reject);
});
}
function extractZip(zipPath, destDir) {
if (process.platform === 'win32') {
execFileSync(
'powershell.exe',
[
'-NoProfile',
'-ExecutionPolicy',
'Bypass',
'-Command',
`Expand-Archive -LiteralPath '${zipPath.replace(/'/g, "''")}' -DestinationPath '${destDir.replace(/'/g, "''")}' -Force`,
],
{ stdio: 'inherit' }
);
return;
}
execFileSync('unzip', ['-q', zipPath, '-d', destDir], { stdio: 'inherit' });
}
async function ensureWindowsUvBinaries() {
const allPresent = Object.entries(uvBinaryHashes).every(([name, expectedHash]) =>
hasExpectedHash(path.join(srcBinDir, name), expectedHash)
);
if (allPresent) {
console.log(`Pinned uv ${uvVersion} binaries already present`);
return;
}
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'goose-uv-'));
const zipPath = path.join(tmpDir, 'uv.zip');
const extractDir = path.join(tmpDir, 'extract');
fs.mkdirSync(extractDir, { recursive: true });
try {
console.log(`Downloading uv ${uvVersion} from ${uvDownloadUrl}`);
await downloadFile(uvDownloadUrl, zipPath);
extractZip(zipPath, extractDir);
for (const [name, expectedHash] of Object.entries(uvBinaryHashes)) {
const extractedPath = path.join(extractDir, name);
if (!fs.existsSync(extractedPath)) {
throw new Error(`Downloaded uv archive did not contain ${name}`);
}
const actualHash = sha256(extractedPath);
if (actualHash !== expectedHash) {
throw new Error(
`${name} checksum mismatch for uv ${uvVersion}: expected ${expectedHash}, got ${actualHash}`
);
}
fs.copyFileSync(extractedPath, path.join(srcBinDir, name));
console.log(`Copied pinned ${name}`);
}
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
}
// Helper function to clean directory of cross-platform files
function cleanBinDirectory(targetPlatform) {
console.log(`Cleaning bin directory for ${targetPlatform} build...`);
@@ -95,7 +205,7 @@ function cleanBinDirectory(targetPlatform) {
}
// Helper function to copy platform-specific files
function copyPlatformFiles(targetPlatform) {
async function copyPlatformFiles(targetPlatform) {
if (targetPlatform === 'win32') {
console.log('Copying Windows-specific files...');
@@ -109,10 +219,15 @@ function copyPlatformFiles(targetPlatform) {
fs.mkdirSync(srcBinDir, { recursive: true });
}
// Copy Windows-specific files
// Copy Windows-specific scripts and authored support files.
const files = fs.readdirSync(platformWinDir, { withFileTypes: true });
files.forEach(file => {
if (file.name === 'README.md' || file.name === '.gitignore') {
if (
file.name === 'README.md' ||
file.name === '.gitignore' ||
file.name.endsWith('.exe') ||
file.name.endsWith('.dll')
) {
return;
}
@@ -127,17 +242,19 @@ function copyPlatformFiles(targetPlatform) {
console.log(`Copied: ${file.name}`);
}
});
await ensureWindowsUvBinaries();
}
}
// Main function
function preparePlatformBinaries() {
async function preparePlatformBinaries() {
const targetPlatform = process.env.ELECTRON_PLATFORM || process.platform;
console.log(`Preparing binaries for platform: ${targetPlatform}`);
// First copy platform-specific files if needed
copyPlatformFiles(targetPlatform);
await copyPlatformFiles(targetPlatform);
// Then clean up cross-platform files
cleanBinDirectory(targetPlatform);
@@ -147,7 +264,10 @@ function preparePlatformBinaries() {
// Run if called directly
if (require.main === module) {
preparePlatformBinaries();
preparePlatformBinaries().catch(error => {
console.error(error);
process.exit(1);
});
}
module.exports = { preparePlatformBinaries };
module.exports = { preparePlatformBinaries };
@@ -1,6 +1,6 @@
# Windows-Specific Binaries
# Windows-Specific Runtime Files
This directory contains Windows-specific binaries and scripts that are only included during Windows builds.
This directory contains Windows-specific scripts that are only included during Windows builds.
## Components
@@ -9,13 +9,13 @@ This directory contains Windows-specific binaries and scripts that are only incl
- `npx.cmd` - Wrapper script that ensures Node.js is installed and uses system npx
### Windows Binaries
- `*.dll` files - Required Windows dynamic libraries
- `*.exe` files - Windows executables
- `uv.exe` and `uvx.exe` are downloaded from the pinned Astral uv release during packaging.
- Compiled `.exe` and `.dll` files are generated or fetched during the build and are not committed.
## Build Process
These files are generated during the Windows build process by:
Windows runtime files are prepared during the build process by:
1. `prepare-windows-npm.sh` - Creates Node.js installation scripts
2. `copy-windows-dlls.js` - Copies all Windows-specific files to the output directory
2. `prepare-platform-binaries.js` - Downloads pinned uv binaries and copies Windows-specific files to `src/bin`
None of these files should be committed to the repository - they are generated fresh during each Windows build.
Binary file not shown.
Binary file not shown.
Binary file not shown.