Skip to content

Commit

Permalink
fix(cubestore-driver): Download x86-darwin for arm64-apple (for Roset…
Browse files Browse the repository at this point in the history
…ta2)
  • Loading branch information
ovr committed Mar 22, 2021
1 parent 9e1317c commit 562ea1a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
23 changes: 1 addition & 22 deletions rust/js-wrapper/download.ts
Expand Up @@ -11,7 +11,7 @@ import { Octokit } from '@octokit/core';
import * as path from 'path';
import { mkdirpSync } from 'fs-extra';

import { detectLibc } from './utils';
import { getTarget } from './utils';

type ByteProgressCallback = (info: { progress: number, eta: number, speed: string }) => void;

Expand Down Expand Up @@ -108,27 +108,6 @@ export async function downloadAndExtractFile(url: string) {
bar.stop();
}

export function getTarget(): string {
if (process.arch !== 'x64') {
throw new Error(
`You are using ${process.arch} architecture which is not supported by Cube Store`,
);
}

switch (process.platform) {
case 'win32':
return 'x86_64-pc-windows-gnu';
case 'linux':
return `x86_64-unknown-linux-${detectLibc()}`;
case 'darwin':
return 'x86_64-apple-darwin';
default:
throw new Error(
`You are using ${process.env} which is not supported by Cube Store`,
);
}
}

async function fetchRelease(version: string) {
const client = new Octokit();

Expand Down
1 change: 1 addition & 0 deletions rust/js-wrapper/index.ts
@@ -1 +1,2 @@
export * from './process';
export { isCubeStoreSupported } from './utils';
8 changes: 0 additions & 8 deletions rust/js-wrapper/process.ts
Expand Up @@ -87,14 +87,6 @@ async function startProcess(pathToExecutable: string, config: Readonly<StartProc
});
}

export function isCubeStoreSupported(): boolean {
if (process.arch !== 'x64') {
return false;
}

return ['win32', 'darwin', 'linux'].includes(process.platform);
}

export class CubeStoreHandler {
protected cubeStore: ChildProcess | null = null;

Expand Down
35 changes: 35 additions & 0 deletions rust/js-wrapper/utils.ts
@@ -1,5 +1,6 @@
import colors from '@oclif/color';
import { spawnSync } from 'child_process';
import process from 'process';

export const displayWarning = (message: string) => {
console.log(`${colors.yellow('Warning.')} ${message}`);
Expand Down Expand Up @@ -46,3 +47,37 @@ export function detectLibc() {

return 'gnu';
}

export function getTarget(): string {
if (process.arch === 'x64') {
switch (process.platform) {
case 'win32':
return 'x86_64-pc-windows-gnu';
case 'linux':
return `x86_64-unknown-linux-${detectLibc()}`;
case 'darwin':
return 'x86_64-apple-darwin';
default:
throw new Error(
`You are using ${process.env} platform which is not supported by Cube Store`,
);
}
}

if (process.arch === 'arm64' && process.platform === 'darwin') {
// Rosetta 2 is required
return 'x86_64-apple-darwin';
}

throw new Error(
`You are using ${process.arch} architecture on ${process.platform} platform which is not supported by Cube Store`,
);
}

export function isCubeStoreSupported(): boolean {
if (process.arch === 'x64') {
return ['win32', 'darwin', 'linux'].includes(process.platform);
}

return process.arch === 'arm64' && process.platform === 'darwin';
}

0 comments on commit 562ea1a

Please sign in to comment.