Skip to content

Commit d62db5f

Browse files
authored
Support platforms without upstream ccache/sccache releases (#439)
Introduce UnknownPackage to handle platform/arch combinations (e.g. linux-riscv64) that lack upstream binary releases. When install-method is "detect", fall back to locally installed ccache/sccache instead of failing. Move the detect-and-skip logic from runInner into UnknownPackage.install so all install paths go through the same Package interface.
1 parent 05e1c04 commit d62db5f

5 files changed

Lines changed: 68 additions & 7 deletions

File tree

dist/restore/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39060,6 +39060,7 @@ __nccwpck_require__.d(__webpack_exports__, {
3906039060
INSTALL_METHOD: () => (/* binding */ INSTALL_METHOD),
3906139061
PLATFORM: () => (/* binding */ PLATFORM),
3906239062
Package: () => (/* binding */ Package),
39063+
UnknownPackage: () => (/* binding */ UnknownPackage),
3906339064
VARIANT: () => (/* binding */ VARIANT),
3906439065
"default": () => (/* binding */ src_restore),
3906539066
selectMethod: () => (/* binding */ selectMethod),
@@ -86649,6 +86650,7 @@ var ARCH;
8664986650
(function (ARCH) {
8665086651
ARCH["X86_64"] = "x86_64";
8665186652
ARCH["AARCH64"] = "aarch64";
86653+
ARCH["RISCV64"] = "riscv64";
8665286654
})(ARCH || (ARCH = {}));
8665386655
var PLATFORM;
8665486656
(function (PLATFORM) {
@@ -86809,6 +86811,23 @@ class Package {
8680986811
}
8681086812
}
8681186813
}
86814+
class UnknownPackage {
86815+
constructor(variant, arch, platform) {
86816+
this.variant = variant;
86817+
this.arch = arch;
86818+
this.platform = platform;
86819+
}
86820+
async install(method) {
86821+
if (method === INSTALL_METHOD.DETECT && await which(this.variant)) {
86822+
// If the install method is "detect" and the package is already installed,
86823+
// don't try to install it. This is to bypass architectures that are not
86824+
// released in upstream projects (linux-riscv64 for ccache/ccache for example).
86825+
}
86826+
else {
86827+
throw new Error(`No metadata found for combination: variant=${this.variant}, arch=${this.arch}, platform=${this.platform}`);
86828+
}
86829+
}
86830+
}
8681286831
// platform/stuff helpers //
8681386832
function detectPlatform() {
8681486833
switch (external_process_namespaceObject.platform) {
@@ -86828,6 +86847,8 @@ function detectArchKey() {
8682886847
return "x86_64";
8682986848
case "arm64":
8683086849
return "aarch64";
86850+
case "riscv64":
86851+
return "riscv64";
8683186852
default:
8683286853
throw new Error(`Unsupported architecture: ${external_process_namespaceObject.arch}`);
8683386854
}
@@ -86843,7 +86864,8 @@ function selectPackage(variant) {
8684386864
const allMetadata = JSON.parse(rawData);
8684486865
const entry = allMetadata[variant]?.[archKey]?.[platform];
8684586866
if (!entry) {
86846-
throw new Error(`No metadata found for combination: variant=${variant}, arch=${archKey}, platform=${platform}`);
86867+
warning(`No metadata found for combination: variant=${variant}, arch=${archKey}, platform=${platform}`);
86868+
return new UnknownPackage(variant, archKey, platform);
8684786869
}
8684886870
return new Package(variant, archKey, platform, entry);
8684986871
}

dist/restore/metadata.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
"dir": "sccache-v0.14.0-aarch64-apple-darwin",
8282
"artifact": "sccache-v0.14.0-aarch64-apple-darwin.tar.gz"
8383
}
84+
},
85+
"riscv64": {
86+
"linux": {
87+
"url": "https://github.com/mozilla/sccache/releases/download/v0.14.0/sccache-v0.14.0-riscv64gc-unknown-linux-musl.tar.gz",
88+
"sha256": "67973734f48edfeb07dcc1adf174c4034dbcc1eb66cfae58076f3546684b9300",
89+
"dir": "sccache-v0.14.0-riscv64gc-unknown-linux-musl",
90+
"artifact": "sccache-v0.14.0-riscv64gc-unknown-linux-musl.tar.gz"
91+
}
8492
}
8593
}
8694
}

metadata/generate.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ package_info() {
6565
*) _bad_platform "$platform" ;;
6666
esac
6767

68-
pkg_name="sccache-$version-$arch-$suffix"
68+
if [ "$arch" = "riscv64" ]; then
69+
# sccache uses `riscv64gc` as arch name
70+
pkg_name="sccache-$version-riscv64gc-$suffix"
71+
else
72+
pkg_name="sccache-$version-$arch-$suffix"
73+
fi
6974
fi
7075

7176
artifact="$pkg_name.$ext"

metadata/metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"linux": "v0.14.0",
2222
"windows": "v0.14.0",
2323
"darwin": "v0.14.0"
24+
},
25+
"riscv64": {
26+
"linux": "v0.14.0"
2427
}
2528
}
2629
}

src/restore.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export enum VARIANT {
1717
export enum ARCH {
1818
X86_64 = "x86_64",
1919
AARCH64 = "aarch64",
20+
RISCV64 = "riscv64",
2021
}
2122

2223
export enum PLATFORM {
@@ -205,6 +206,27 @@ export class Package {
205206
}
206207
}
207208

209+
export class UnknownPackage {
210+
constructor(
211+
public readonly variant: VARIANT,
212+
public readonly arch: ARCH,
213+
public readonly platform: PLATFORM) { }
214+
215+
async install(method: INSTALL_METHOD): Promise<void> {
216+
if (method === INSTALL_METHOD.DETECT && await io.which(this.variant)) {
217+
// If the install method is "detect" and the package is already installed,
218+
// don't try to install it. This is to bypass architectures that are not
219+
// released in upstream projects (linux-riscv64 for ccache/ccache for example).
220+
} else {
221+
throw new Error(
222+
`No metadata found for combination: variant=${this.variant}, arch=${this.arch}, platform=${this.platform}`
223+
);
224+
}
225+
}
226+
}
227+
228+
type MaybePackage = Package | UnknownPackage;
229+
208230
// platform/stuff helpers //
209231
function detectPlatform(): PLATFORM {
210232
switch (process.platform) {
@@ -219,18 +241,20 @@ function detectPlatform(): PLATFORM {
219241
}
220242
}
221243

222-
function detectArchKey(): "x86_64" | "aarch64" {
244+
function detectArchKey(): "x86_64" | "aarch64" | "riscv64" {
223245
switch (process.arch) {
224246
case "x64":
225247
return "x86_64";
226248
case "arm64":
227249
return "aarch64";
250+
case "riscv64":
251+
return "riscv64";
228252
default:
229253
throw new Error(`Unsupported architecture: ${process.arch}`);
230254
}
231255
}
232256

233-
export function selectPackage(variant: VARIANT): Package {
257+
export function selectPackage(variant: VARIANT): MaybePackage {
234258
const platform = detectPlatform()
235259
const archKey = detectArchKey()
236260

@@ -246,9 +270,8 @@ export function selectPackage(variant: VARIANT): Package {
246270
const entry: PackageMetadata = allMetadata[variant]?.[archKey]?.[platform];
247271

248272
if (!entry) {
249-
throw new Error(
250-
`No metadata found for combination: variant=${variant}, arch=${archKey}, platform=${platform}`
251-
);
273+
core.warning(`No metadata found for combination: variant=${variant}, arch=${archKey}, platform=${platform}`)
274+
return new UnknownPackage(variant, archKey as ARCH, platform as PLATFORM);
252275
}
253276

254277
return new Package(variant, archKey as ARCH, platform as PLATFORM, entry);

0 commit comments

Comments
 (0)