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

Commit e4cb0f3

Browse files
bors[bot]Veetaha
andauthored
Merge #4972
4972: Gzip artifacts r=Veetaha a=Veetaha [Here is the test release](https://github.com/Veetaha/rust-analyzer/releases/tag/2020-06-21) Change in size: `~ 25 MB -> ~ 8 MB (gzipped)` The time to gzip during the dist build takes a somewhat considerable amount of time tho. Having already compiled artifacts this takes in debug mode: ``` ~/dev/rust-analyzer (feat/gzip-binaries) $ time cargo xtask dist Finished dev [unoptimized] target(s) in 0.06s Running `target/debug/xtask dist` > cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release Finished release [optimized] target(s) in 0.05s > strip ./target/release/rust-analyzer real 0m34.331s user 0m34.245s sys 0m0.078s ``` In release mode this is much faster: ``` ~/dev/rust-analyzer (feat/gzip-binaries) $ time cargo run -p xtask --release -- dist Finished release [optimized] target(s) in 0.04s Running `target/release/xtask dist` > cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release Finished release [optimized] target(s) in 0.06s > strip ./target/release/rust-analyzer real 0m2.401s ``` **[UPD]** adding a profile override for `miniz_oxide` does the thing to ensure good performrance We might need to notify all other ra plugins' maintainers about the change in our GH releases if we merge this PR, or we could leave uncompressed files along with gzipped for a while until everyone migrates. Co-authored-by: Veetaha <[email protected]>
2 parents f4c9ac5 + a42bc0c commit e4cb0f3

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)