Skip to content

Commit fa4ceaf

Browse files
committed
Deploy new nightly language servers
1 parent 037c3e9 commit fa4ceaf

File tree

2 files changed

+93
-91
lines changed

2 files changed

+93
-91
lines changed

editors/code/src/ctx.ts

+68-46
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ interface LastClientError {
2525
export class Ctx {
2626
readonly context: vscode.ExtensionContext;
2727
readonly config: Config;
28-
readonly state: PersistentState;
28+
readonly state: PersistentState;
2929
readonly statusBar: vscode.StatusBarItem;
30-
30+
3131
// Stored initialization error. Cleared when reloaded.
3232
lastClientError: LastClientError | null;
3333
client: lc.LanguageClient | null;
34-
commands: {[key:string]: lc.Disposable};
34+
commands: { [key: string]: lc.Disposable };
3535
stopped: boolean;
3636

3737
constructor(context: vscode.ExtensionContext) {
3838
this.context = context;
3939
this.config = new Config(context);
40-
this.state = new PersistentState(context.globalState);
40+
this.state = new PersistentState(context.globalState);
4141
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
4242
this.lastClientError = null;
4343
this.client = null;
@@ -75,7 +75,7 @@ export class Ctx {
7575
}
7676

7777
this.setupStatusBar();
78-
}
78+
}
7979

8080
command(name: string, callback: (...args: any[]) => any) {
8181
if (!this.commands[name]) {
@@ -152,11 +152,11 @@ export class Ctx {
152152
let [code, out, err]: [number | null, string, string] = await new Promise((resolve, _) => {
153153
let stdout = "";
154154
let stderr = "";
155-
155+
156156
cargoVersion.stdout.on("data", (chunk) => {
157157
stdout += chunk;
158158
});
159-
159+
160160
cargoVersion.stderr.on("data", (chunk) => {
161161
stderr += chunk;
162162
});
@@ -211,7 +211,7 @@ export class Ctx {
211211
child.stderr.setEncoding('utf8');
212212
child.stdout.setEncoding('utf8');
213213
let out = rl.createInterface(child.stdout, child.stdin);
214-
214+
215215
this.statusBar.text = `rune: cargo build -p ${name}`;
216216
this.statusBar.tooltip = `rune: building package ${name}, to use as rune language server`;
217217
this.statusBar.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
@@ -273,10 +273,10 @@ export class Ctx {
273273

274274
if (explicitPath) {
275275
if (explicitPath.startsWith("~/")) {
276-
return { kind: "languageserver", path: os.homedir() + explicitPath.slice("~".length) };
276+
return { kind: "cli", path: os.homedir() + explicitPath.slice("~".length) };
277277
}
278278

279-
return { kind: "languageserver", path: explicitPath };
279+
return { kind: "cli", path: explicitPath };
280280
}
281281

282282
const cargoPackage = this.config.serverCargoPackage;
@@ -297,24 +297,25 @@ export class Ctx {
297297
return null;
298298
}
299299

300-
return { kind: "languageserver", path };
300+
return { kind: "cli", path };
301301
}
302-
302+
303303
async downloadServer(): Promise<string | null> {
304-
// unknown platform => no download available
305-
const platform = detectPlatform();
304+
const platformArch = detectPlatform();
306305

307-
if (!platform) {
306+
if (!platformArch) {
308307
return null;
309308
}
310-
309+
310+
const [platform, arch] = platformArch;
311+
311312
// platform specific binary name / path
312313
const ext = platform === "windows" ? ".exe" : "";
313314
const bin = `rune-languageserver-${platform}${ext}`;
314315
const serverDir = vscode.Uri.joinPath(this.context.extensionUri, "server");
315316
const dest = vscode.Uri.joinPath(serverDir, bin);
316317
const destExists = await uriExists(dest);
317-
318+
318319
// Only check for updates once every two hours.
319320
let now = (new Date()).getTime() / 1000;
320321
let lastCheck = this.state.lastCheck;
@@ -324,19 +325,27 @@ export class Ctx {
324325
if (destExists && !timedOut) {
325326
return dest.fsPath;
326327
}
327-
328+
328329
// fetch new release info
329330
await this.state.updateLastCheck(now);
330331

331332
const release = await fetchRelease("nightly", null);
332-
const artifact = release.assets.find(artifact => artifact.name === `rune-languageserver-${platform}.gz`);
333-
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
334-
333+
334+
const platform_only = `rune-languageserver-${platform}.gz`;
335+
const platform_arch = `rune-languageserver-${platform}-${arch}.gz`;
336+
337+
const artifact = release.assets.find(artifact => artifact.name === platform_only || artifact.name === platform_arch);
338+
339+
if (!artifact) {
340+
log.warn(`Bad release: ${JSON.stringify(release)}`);
341+
return null;
342+
}
343+
335344
// no new release
336345
if (destExists && this.state.releaseId === artifact.id) {
337346
return dest.fsPath;
338347
}
339-
348+
340349
// ask for update
341350
if (this.config.updatesAskBeforeDownload) {
342351
const userResponse = await vscode.window.showInformationMessage(
@@ -347,20 +356,20 @@ export class Ctx {
347356
return dest.fsPath;
348357
}
349358
}
350-
359+
351360
// delete old server version
352361
try {
353362
await vscode.workspace.fs.delete(dest);
354363
} catch (exception) {
355364
log.debug("Delete of old server binary failed", exception);
356365
}
357-
366+
358367
// create server dir if missing
359368
if (!await uriExists(serverDir)) {
360369
log.debug(`Creating server dir: ${serverDir}`);
361370
await vscode.workspace.fs.createDirectory(serverDir);
362371
}
363-
372+
364373
// download new version
365374
await download({
366375
url: artifact.browser_download_url,
@@ -372,11 +381,11 @@ export class Ctx {
372381

373382
await this.state.updateReleaseId(release.id);
374383
return dest.fsPath;
375-
}
376-
384+
}
385+
377386
serverPath(): string | null {
378387
return process.env.__RUNE_LSP_SERVER_DEBUG ?? this.config.serverPath;
379-
}
388+
}
380389

381390
setupStatusBar() {
382391
this.statusBar.text = "rune";
@@ -455,22 +464,35 @@ export class Ctx {
455464
/**
456465
* Function used to detect the platform we are on.
457466
*/
458-
function detectPlatform(): String | undefined {
459-
if (process.arch === "x64") {
460-
switch (process.platform) {
461-
case "win32":
462-
return "windows";
463-
case "linux":
464-
return "linux";
465-
case "darwin":
466-
return "macos";
467-
}
468-
}
469-
470-
vscode.window.showErrorMessage(
471-
`Unfortunately we don't support your platform yet.
472-
You can open an issue about that [here](https://github.com/rune-rs/rune/issues).
473-
Please include (platform: ${process.platform}, arch: ${process.arch}).`
474-
);
475-
return undefined;
467+
function detectPlatform(): [String, String] | undefined {
468+
let platform = null;
469+
let arch = null;
470+
471+
switch (process.platform) {
472+
case "win32":
473+
platform = "windows";
474+
case "linux":
475+
platform = "linux";
476+
case "darwin":
477+
platform = "macos";
478+
}
479+
480+
switch (process.arch) {
481+
case "x64":
482+
arch = "x86_64";
483+
case "arm64":
484+
arch = "aarch64";
485+
}
486+
487+
if (!platform || !arch) {
488+
vscode.window.showErrorMessage(
489+
`Unfortunately we don't support your platform yet.
490+
You can open an issue about that [here](https://github.com/rune-rs/rune/issues).
491+
Please include (platform: ${process.platform}, arch: ${process.arch}).`
492+
);
493+
494+
return undefined;
495+
}
496+
497+
return [platform, arch];
476498
}

tools/builder/src/main.rs

+25-45
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
//! A utility project for building and packaging Rune binaries.
22
3-
use anyhow::{anyhow, bail, Context as _, Result};
4-
use regex::Regex;
53
use std::env;
6-
use std::env::consts;
4+
use std::env::consts::{self, EXE_EXTENSION};
75
use std::ffi::OsStr;
86
use std::fmt;
97
use std::fs;
108
use std::io;
119
use std::path::{Path, PathBuf};
1210
use std::process::Command;
1311

12+
use anyhow::{anyhow, bail, Context as _, Result};
13+
use regex::Regex;
14+
1415
fn main() -> Result<()> {
1516
let mut it = env::args();
1617
it.next();
@@ -39,16 +40,7 @@ fn main() -> Result<()> {
3940
Build::Version(version)
4041
};
4142

42-
if cfg!(target_os = "windows") {
43-
do_build(build, "windows", ".exe")?;
44-
} else if cfg!(target_os = "linux") {
45-
do_build(build, "linux", "")?;
46-
} else if cfg!(target_os = "macos") {
47-
do_build(build, "macos", "")?;
48-
} else {
49-
bail!("unsupported operating system: {}", consts::OS);
50-
}
51-
43+
do_build(build)?;
5244
Ok(())
5345
}
5446

@@ -197,10 +189,13 @@ where
197189
Ok(())
198190
}
199191

200-
fn create_gz(output: &Path, input: &Path) -> Result<()> {
192+
fn create_gz(output: impl AsRef<Path>, input: impl AsRef<Path>) -> Result<()> {
201193
use flate2::write::GzEncoder;
202194
use flate2::Compression;
203195

196+
let output = output.as_ref();
197+
let input = input.as_ref();
198+
204199
println!("building: {}", output.display());
205200

206201
let input = fs::File::open(input)?;
@@ -214,24 +209,7 @@ fn create_gz(output: &Path, input: &Path) -> Result<()> {
214209
Ok(())
215210
}
216211

217-
/// Copy an iterator of files to the given directory.
218-
fn copy_files<I, S, N>(dest: &Path, sources: I) -> Result<()>
219-
where
220-
I: IntoIterator<Item = (S, N)>,
221-
S: AsRef<Path>,
222-
N: AsRef<str>,
223-
{
224-
for (s, name) in sources {
225-
let s = s.as_ref();
226-
let name = name.as_ref();
227-
228-
fs::copy(s, dest.join(name))?;
229-
}
230-
231-
Ok(())
232-
}
233-
234-
fn do_build(build: Build, suffix: &str, ext: &str) -> Result<()> {
212+
fn do_build(build: Build) -> Result<()> {
235213
let readme = PathBuf::from("README.md");
236214
let release_dir = PathBuf::from("target").join("release");
237215
let upload = Path::new("dist");
@@ -240,8 +218,8 @@ fn do_build(build: Build, suffix: &str, ext: &str) -> Result<()> {
240218
fs::create_dir_all(upload).context("creating upload directory")?;
241219
}
242220

243-
let rune = release_dir.join(format!("rune{}", ext));
244-
let rune_languageserver = release_dir.join(format!("rune-languageserver{}", ext));
221+
let rune = release_dir.join(format!("rune{EXE_EXTENSION}"));
222+
let rune_languageserver = release_dir.join(format!("rune-languageserver{EXE_EXTENSION}"));
245223

246224
if !rune.is_file() {
247225
println!("building: {}", rune.display());
@@ -259,22 +237,24 @@ fn do_build(build: Build, suffix: &str, ext: &str) -> Result<()> {
259237
.context("building .zip")?;
260238

261239
if build.is_channel() {
262-
// Create rune-languageserver gzip.
240+
// Create rune-languageserver gzips.
263241
create_gz(
264-
&upload.join(format!("rune-languageserver-{}.gz", consts::OS)),
242+
upload.join(format!(
243+
"rune-languageserver-{os}-{arch}.gz",
244+
os = consts::OS,
245+
arch = consts::ARCH
246+
)),
265247
&rune_languageserver,
266248
)
267249
.context("building rune-languageserver .gz")?;
268250

269-
// Copy files to be uploaded.
270-
copy_files(
271-
upload,
272-
vec![(
273-
rune_languageserver,
274-
format!("rune-languageserver-{}{}", suffix, ext),
275-
)],
276-
)
277-
.context("copying raw files to upload")?;
251+
if consts::ARCH == "x86_64" {
252+
create_gz(
253+
upload.join(format!("rune-languageserver-{os}.gz", os = consts::OS)),
254+
&rune_languageserver,
255+
)
256+
.context("building rune-languageserver .gz")?;
257+
}
278258
}
279259

280260
Ok(())

0 commit comments

Comments
 (0)