Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit a42bc0c

Browse files
committed
Gzip artifacts
Co-authored-by: bjorn3 <[email protected]> Override miniz_oxide to build it with optimizations Building this crate with optimizations decreases the gzipping part of `cargo xtask dist` from `30-40s` down to `3s`, the overhead for `rustc` to apply optimizations is miserable on this background
1 parent f4c9ac5 commit a42bc0c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

rust-analyzer/editors/code/src/main.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
274274
};
275275
if (config.package.releaseTag === null) return "rust-analyzer";
276276

277-
let binaryName: string | undefined = undefined;
277+
let platform: string | undefined;
278278
if (process.arch === "x64" || process.arch === "ia32") {
279-
if (process.platform === "linux") binaryName = "rust-analyzer-linux";
280-
if (process.platform === "darwin") binaryName = "rust-analyzer-mac";
281-
if (process.platform === "win32") binaryName = "rust-analyzer-windows.exe";
279+
if (process.platform === "linux") platform = "linux";
280+
if (process.platform === "darwin") platform = "mac";
281+
if (process.platform === "win32") platform = "windows";
282282
}
283-
if (binaryName === undefined) {
283+
if (platform === undefined) {
284284
vscode.window.showErrorMessage(
285285
"Unfortunately we don't ship binaries for your platform yet. " +
286286
"You need to manually clone rust-analyzer repository and " +
@@ -291,8 +291,8 @@ async function getServer(config: Config, state: PersistentState): Promise<string
291291
);
292292
return undefined;
293293
}
294-
295-
const dest = path.join(config.globalStoragePath, binaryName);
294+
const ext = platform === "windows" ? ".exe" : "";
295+
const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`);
296296
const exists = await fs.stat(dest).then(() => true, () => false);
297297
if (!exists) {
298298
await state.updateServerVersion(undefined);
@@ -309,7 +309,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
309309
}
310310

311311
const release = await fetchRelease(config.package.releaseTag);
312-
const artifact = release.assets.find(artifact => artifact.name === binaryName);
312+
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
313313
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
314314

315315
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
@@ -321,6 +321,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
321321
url: artifact.browser_download_url,
322322
dest,
323323
progressTitle: "Downloading rust-analyzer server",
324+
gunzip: true,
324325
mode: 0o755
325326
});
326327

rust-analyzer/editors/code/src/net.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as vscode from "vscode";
33
import * as stream from "stream";
44
import * as crypto from "crypto";
55
import * as fs from "fs";
6+
import * as zlib from "zlib";
67
import * as util from "util";
78
import * as path from "path";
89
import { log, assert } from "./util";
@@ -65,6 +66,7 @@ interface DownloadOpts {
6566
url: string;
6667
dest: string;
6768
mode?: number;
69+
gunzip?: boolean;
6870
}
6971

7072
export async function download(opts: DownloadOpts) {
@@ -82,7 +84,7 @@ export async function download(opts: DownloadOpts) {
8284
},
8385
async (progress, _cancellationToken) => {
8486
let lastPercentage = 0;
85-
await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => {
87+
await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => {
8688
const newPercentage = (readBytes / totalBytes) * 100;
8789
progress.report({
8890
message: newPercentage.toFixed(0) + "%",
@@ -97,16 +99,11 @@ export async function download(opts: DownloadOpts) {
9799
await fs.promises.rename(tempFile, opts.dest);
98100
}
99101

100-
/**
101-
* Downloads file from `url` and stores it at `destFilePath` with `mode` (unix permissions).
102-
* `onProgress` callback is called on recieveing each chunk of bytes
103-
* to track the progress of downloading, it gets the already read and total
104-
* amount of bytes to read as its parameters.
105-
*/
106102
async function downloadFile(
107103
url: string,
108104
destFilePath: fs.PathLike,
109105
mode: number | undefined,
106+
gunzip: boolean,
110107
onProgress: (readBytes: number, totalBytes: number) => void
111108
): Promise<void> {
112109
const res = await fetch(url);
@@ -130,7 +127,10 @@ async function downloadFile(
130127
});
131128

132129
const destFileStream = fs.createWriteStream(destFilePath, { mode });
133-
await pipeline(res.body, destFileStream);
130+
const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body;
131+
132+
await pipeline(srcStream, destFileStream);
133+
134134
await new Promise<void>(resolve => {
135135
destFileStream.on("close", resolve);
136136
destFileStream.destroy();

0 commit comments

Comments
 (0)