Skip to content

Commit

Permalink
Update coursier version, support arm64 (#26)
Browse files Browse the repository at this point in the history
Update coursier version to  support arm64
  • Loading branch information
etspaceman authored Jun 4, 2024
1 parent c34600f commit 1880119
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 12 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ Error in `Log(Extension Host)` channel:
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
```

This happens because the extension exchange with the language server via std in/out of the child process. If any of the code that runs in the language server prints to the standard out, VS Code will complain (unless it is specifically formatted that way).
This happens because the extension exchange with the language server via std in/out of the child process. If any of the code that runs in the language server prints to the standard out, VS Code will complain (unless it is specifically formatted that way).

Error in `Log(Remote Extension Host)` channel when downloading Coursier:

```
Failed to establish a socket connection to proxies extension
```

This happens when using the extension in a remote environment (e.g. devcontainers), and the proxy support is set to `override`. This can be resolved by setting this to `off`.

See this related [github issue](https://github.com/microsoft/vscode-pull-request-github/issues/4624#issuecomment-1845285077) for more information.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"activationEvents": [
"onLanguage:smithy"
],
"extensionKind": [
"workspace"
],
"main": "./out/src/extension",
"contributes": {
"configuration": {
Expand Down Expand Up @@ -105,6 +108,7 @@
"concat-map": "^0.0.2",
"follow-redirects": "^1.14.9",
"semver": "^7.5.0",
"unzip-stream": "^0.3.4",
"vscode-languageclient": "^8.0.0"
},
"devDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion src/coursier/coursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export function getCoursierExecutable(extensionPath: string): Promise<string> {
return downloadCoursierIfRequired(
extensionPath,
process.platform,
"v2.0.13"
process.arch,
// Have to use a commit hash for now since the launchers repository is untagged
// See https://github.com/coursier/coursier/issues/2998
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
);
}
});
Expand Down
34 changes: 28 additions & 6 deletions src/coursier/download-coursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { https } from "follow-redirects";
import { IncomingMessage } from "http";
import * as fs from "fs";
import { access, mkdir } from "fs/promises";
import * as zlib from "zlib";
import * as unzip from "unzip-stream";

export function downloadCoursierIfRequired(
extensionPath: string,
platform: string,
versionPath: string
arch: String,
versionPath: string,
versionPathArm64: String
): Promise<string> {
function binPath(filename: string) {
return path.join(extensionPath, filename);
Expand All @@ -23,20 +27,34 @@ export function downloadCoursierIfRequired(

const supportedTargets = {
darwin: {
url: `https://github.com/coursier/coursier/releases/download/${versionPath}/cs-x86_64-apple-darwin`,
url: `https://github.com/coursier/launchers/raw/${versionPath}/cs-x86_64-apple-darwin.gz`,
bin: binPath("coursier"),
},
linux: {
url: `https://github.com/coursier/coursier/releases/download/${versionPath}/cs-x86_64-pc-linux`,
url: `https://github.com/coursier/launchers/raw/${versionPath}/cs-x86_64-pc-linux.gz`,
bin: binPath("coursier"),
},
win32: {
url: `https://github.com/coursier/coursier/releases/download/${versionPath}/cs-x86_64-pc-win32.exe`,
url: `https://github.com/coursier/launchers/raw/${versionPath}/cs-x86_64-pc-win32.zip`,
bin: binPath("coursier.exe"),
},
};

const target = supportedTargets[platform];
const supportedTargetsArm64 = {
darwin: {
url: `https://github.com/VirtusLab/coursier-m1/releases/download/${versionPathArm64}/cs-aarch64-apple-darwin.gz`,
bin: binPath("coursier"),
},
linux: {
url: `https://github.com/VirtusLab/coursier-m1/releases/download/${versionPathArm64}/cs-aarch64-pc-linux.gz`,
bin: binPath("coursier"),
},
};

const target =
arch === "arm64"
? supportedTargetsArm64[platform]
: supportedTargets[platform];
if (target === undefined) {
return Promise.reject(`Unsupported platform ${platform}.`);
} else {
Expand Down Expand Up @@ -78,7 +96,11 @@ function downloadFile(url: string, targetFile: string): Promise<string> {
flags: "wx",
mode: 0o755,
});
response.pipe(file);
targetFile.endsWith(".exe")
? response.pipe(unzip.Parse()).on("entry", (entry) => {
entry.pipe(file);
})
: response.pipe(zlib.createUnzip()).pipe(file);

file.on("finish", () => {
console.log(`Finished downloaded file at ${targetFile}`);
Expand Down
38 changes: 36 additions & 2 deletions tests/coursier/download-coursier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,35 @@ import { join } from "path";
const dir = join(tmpdir(), p);
rmSync(dir, { recursive: true, force: true });
mkdirSync(dir, { recursive: true });
return downloadCoursierIfRequired(dir, p, "v2.0.13").then((x) => {
return downloadCoursierIfRequired(
dir,
p,
"x64",
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
).then((x) => {
expect(existsSync(x)).toBeTruthy();
accessSync(x, constants.X_OK);
});
},
25 * 1000
);
});

["darwin", "linux"].forEach((p) => {
test(
`download on platform: ${p}`,
() => {
const dir = join(tmpdir(), p);
rmSync(dir, { recursive: true, force: true });
mkdirSync(dir, { recursive: true });
return downloadCoursierIfRequired(
dir,
p,
"arm64",
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
).then((x) => {
expect(existsSync(x)).toBeTruthy();
accessSync(x, constants.X_OK);
});
Expand All @@ -21,6 +49,12 @@ import { join } from "path";

test(`fails on unknown platform`, () => {
return expect(
downloadCoursierIfRequired(tmpdir(), "unsupported", "v2.0.13")
downloadCoursierIfRequired(
tmpdir(),
"unsupported",
"x64",
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
)
).rejects.toEqual("Unsupported platform unsupported.");
});
12 changes: 10 additions & 2 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1880119

Please sign in to comment.