diff options
| author | Veetaha <veetaha2@gmail.com> | 2020-06-21 15:58:34 +0300 |
|---|---|---|
| committer | Veetaha <veetaha2@gmail.com> | 2020-07-07 23:30:11 +0300 |
| commit | f92bfb580780cda02f9ba8a935538f984d8a4c0d (patch) | |
| tree | fbf0e24250cc36eaa122904e78cd7cb50fe1c665 /editors/code/src | |
| parent | 980a67f44629ed67a54b603aaf9d015a81d61f7a (diff) | |
| download | rust-f92bfb580780cda02f9ba8a935538f984d8a4c0d.tar.gz rust-f92bfb580780cda02f9ba8a935538f984d8a4c0d.zip | |
Gzip artifacts
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com> 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
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/main.ts | 17 | ||||
| -rw-r--r-- | editors/code/src/net.ts | 16 |
2 files changed, 17 insertions, 16 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index eda95ae5c43..bd99d696ad8 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -274,13 +274,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string }; if (config.package.releaseTag === null) return "rust-analyzer"; - let binaryName: string | undefined = undefined; + let platform: string | undefined; if (process.arch === "x64" || process.arch === "ia32") { - if (process.platform === "linux") binaryName = "rust-analyzer-linux"; - if (process.platform === "darwin") binaryName = "rust-analyzer-mac"; - if (process.platform === "win32") binaryName = "rust-analyzer-windows.exe"; + if (process.platform === "linux") platform = "linux"; + if (process.platform === "darwin") platform = "mac"; + if (process.platform === "win32") platform = "windows"; } - if (binaryName === undefined) { + if (platform === undefined) { vscode.window.showErrorMessage( "Unfortunately we don't ship binaries for your platform yet. " + "You need to manually clone rust-analyzer repository and " + @@ -291,8 +291,8 @@ async function getServer(config: Config, state: PersistentState): Promise<string ); return undefined; } - - const dest = path.join(config.globalStoragePath, binaryName); + const ext = platform === "windows" ? ".exe" : ""; + const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`); const exists = await fs.stat(dest).then(() => true, () => false); if (!exists) { await state.updateServerVersion(undefined); @@ -309,7 +309,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string } const release = await fetchRelease(config.package.releaseTag); - const artifact = release.assets.find(artifact => artifact.name === binaryName); + const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); // 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 url: artifact.browser_download_url, dest, progressTitle: "Downloading rust-analyzer server", + gunzip: true, mode: 0o755 }); diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 86609288262..53c9e91cd17 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts @@ -3,6 +3,7 @@ import * as vscode from "vscode"; import * as stream from "stream"; import * as crypto from "crypto"; import * as fs from "fs"; +import * as zlib from "zlib"; import * as util from "util"; import * as path from "path"; import { log, assert } from "./util"; @@ -65,6 +66,7 @@ interface DownloadOpts { url: string; dest: string; mode?: number; + gunzip?: boolean; } export async function download(opts: DownloadOpts) { @@ -82,7 +84,7 @@ export async function download(opts: DownloadOpts) { }, async (progress, _cancellationToken) => { let lastPercentage = 0; - await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => { + await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => { const newPercentage = (readBytes / totalBytes) * 100; progress.report({ message: newPercentage.toFixed(0) + "%", @@ -97,16 +99,11 @@ export async function download(opts: DownloadOpts) { await fs.promises.rename(tempFile, opts.dest); } -/** - * Downloads file from `url` and stores it at `destFilePath` with `mode` (unix permissions). - * `onProgress` callback is called on recieveing each chunk of bytes - * to track the progress of downloading, it gets the already read and total - * amount of bytes to read as its parameters. - */ async function downloadFile( url: string, destFilePath: fs.PathLike, mode: number | undefined, + gunzip: boolean, onProgress: (readBytes: number, totalBytes: number) => void ): Promise<void> { const res = await fetch(url); @@ -130,7 +127,10 @@ async function downloadFile( }); const destFileStream = fs.createWriteStream(destFilePath, { mode }); - await pipeline(res.body, destFileStream); + const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; + + await pipeline(srcStream, destFileStream); + await new Promise<void>(resolve => { destFileStream.on("close", resolve); destFileStream.destroy(); |
