@@ -91,7 +91,7 @@ export async function getProtoc(
91
91
92
92
async function downloadRelease ( version : string ) : Promise < string > {
93
93
// Download
94
- let fileName : string = getFileName ( version ) ;
94
+ let fileName : string = getFileName ( version , osPlat , osArch ) ;
95
95
let downloadUrl : string = util . format (
96
96
"https://github.com/protocolbuffers/protobuf/releases/download/%s/%s" ,
97
97
version ,
@@ -114,7 +114,48 @@ async function downloadRelease(version: string): Promise<string> {
114
114
return await tc . cacheDir ( extPath , "protoc" , version ) ;
115
115
}
116
116
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 {
118
159
// to compose the file name, strip the leading `v` char
119
160
if ( version . startsWith ( "v" ) ) {
120
161
version = version . slice ( 1 , version . length ) ;
@@ -126,13 +167,13 @@ function getFileName(version: string): string {
126
167
return util . format ( "protoc-%s-win%s.zip" , version , arch ) ;
127
168
}
128
169
129
- const arch : string = osArch == "x64" ? "x86_64" : "x86_32" ;
170
+ const suffix = fileNameSuffix ( osArch ) ;
130
171
131
172
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 ) ;
133
174
}
134
175
135
- return util . format ( "protoc-%s-linux-%s.zip" , version , arch ) ;
176
+ return util . format ( "protoc-%s-linux-%s.zip" , version , suffix ) ;
136
177
}
137
178
138
179
// Retrieve a list of versions scraping tags from the Github API
0 commit comments