Skip to content

Commit 5275a49

Browse files
committed
fix #25: Support ARM64 and other platforms
1 parent 31a047f commit 5275a49

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

__tests__/main.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ process.env["RUNNER_TEMP"] = tempDir;
1414
process.env["RUNNER_TOOL_CACHE"] = toolDir;
1515
import * as installer from "../src/installer";
1616

17+
describe("filename tests", () => {
18+
const tests = [
19+
["protoc-3.20.2-linux-x86_32.zip", "linux", ""],
20+
["protoc-3.20.2-linux-x86_64.zip", "linux", "x64"],
21+
["protoc-3.20.2-linux-aarch_64.zip", "linux", "arm64"],
22+
["protoc-3.20.2-linux-ppcle_64.zip", "linux", "ppc64"],
23+
["protoc-3.20.2-linux-s390_64.zip", "linux", "s390x"],
24+
["protoc-3.20.2-osx-aarch_64.zip", "darwin", "arm64"],
25+
["protoc-3.20.2-osx-x86_64.zip", "darwin", "x64"]
26+
];
27+
for (const [expected, plat, arch] of tests) {
28+
it(`downloads ${expected} correctly`, () => {
29+
const actual = installer.getFileName("3.20.2", plat, arch);
30+
expect(expected).toBe(actual);
31+
});
32+
}
33+
});
34+
1735
describe("installer tests", () => {
1836
beforeEach(async function() {
1937
await io.rmRF(toolDir);

src/installer.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function getProtoc(
9191

9292
async function downloadRelease(version: string): Promise<string> {
9393
// Download
94-
let fileName: string = getFileName(version);
94+
let fileName: string = getFileName(version, osPlat, osArch);
9595
let downloadUrl: string = util.format(
9696
"https://github.com/protocolbuffers/protobuf/releases/download/%s/%s",
9797
version,
@@ -114,7 +114,48 @@ async function downloadRelease(version: string): Promise<string> {
114114
return await tc.cacheDir(extPath, "protoc", version);
115115
}
116116

117-
function getFileName(version: string): string {
117+
/**
118+
*
119+
* @param osArch - A string identifying the operating system platform for which the Node.js binary was compiled.
120+
* See https://nodejs.org/api/os.html#osplatform for possible values.
121+
* @returns Suffix for the protoc filename.
122+
*/
123+
function fileNameSuffix(osArch: string): string {
124+
switch (osArch) {
125+
case "x64": {
126+
return "x86_64";
127+
}
128+
case "arm64": {
129+
return "aarch_64";
130+
}
131+
case "s390x": {
132+
return "s390_64";
133+
}
134+
case "ppc64": {
135+
return "ppcle_64";
136+
}
137+
default: {
138+
return "x86_32";
139+
}
140+
}
141+
}
142+
143+
/**
144+
* Returns the filename of the protobuf compiler.
145+
*
146+
* @param version - The version to download
147+
* @param osPlat - The operating system platform for which the Node.js binary was compiled.
148+
* See https://nodejs.org/api/os.html#osplatform for more.
149+
* @param osArch - The operating system CPU architecture for which the Node.js binary was compiled.
150+
* See https://nodejs.org/api/os.html#osplatform for more.
151+
* @returns The filename of the protocol buffer for the given release, platform and architecture.
152+
*
153+
*/
154+
export function getFileName(
155+
version: string,
156+
osPlat: string,
157+
osArch: string
158+
): string {
118159
// to compose the file name, strip the leading `v` char
119160
if (version.startsWith("v")) {
120161
version = version.slice(1, version.length);
@@ -126,13 +167,13 @@ function getFileName(version: string): string {
126167
return util.format("protoc-%s-win%s.zip", version, arch);
127168
}
128169

129-
const arch: string = osArch == "x64" ? "x86_64" : "x86_32";
170+
const suffix = fileNameSuffix(osArch);
130171

131172
if (osPlat == "darwin") {
132-
return util.format("protoc-%s-osx-%s.zip", version, arch);
173+
return util.format("protoc-%s-osx-%s.zip", version, suffix);
133174
}
134175

135-
return util.format("protoc-%s-linux-%s.zip", version, arch);
176+
return util.format("protoc-%s-linux-%s.zip", version, suffix);
136177
}
137178

138179
// Retrieve a list of versions scraping tags from the Github API

0 commit comments

Comments
 (0)