Skip to content

Commit

Permalink
Improve platform architecture management for Vyper compiler (#1776)
Browse files Browse the repository at this point in the history
* Only log Vyper downloaded on success

* add architecture checks for vyper compiler on mac and improve logging
  • Loading branch information
manuelwedler committed Jan 2, 2025
1 parent d554973 commit 401b8ea
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
32 changes: 22 additions & 10 deletions packages/lib-sourcify/test/compiler/vyperCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { logDebug, logError, logWarn } from '../../src/lib/logger';
const HOST_VYPER_REPO = 'https://github.com/vyperlang/vyper/releases/download/';

export function findVyperPlatform(): string | false {
if (process.platform === 'darwin') {
if (
process.platform === 'darwin' &&
(process.arch === 'x64' || process.arch === 'arm64')
) {
return 'darwin';
}
if (process.platform === 'linux' && process.arch === 'x64') {
Expand All @@ -37,13 +40,20 @@ export async function useVyperCompiler(
vyperJsonInput: VyperJsonInput,
): Promise<VyperOutput> {
const vyperPlatform = findVyperPlatform();
let vyperPath;
if (vyperPlatform) {
vyperPath = await getVyperExecutable(vyperRepoPath, vyperPlatform, version);
if (!vyperPlatform) {
throw new Error('Vyper is not supported on this machine.');
}

const vyperPath = await getVyperExecutable(
vyperRepoPath,
vyperPlatform,
version,
);

if (!vyperPath) {
throw new Error('Vyper path not found');
throw new Error(
'Vyper path not found. Maybe an incorrect version was provided.',
);
}

let compiled: string | undefined;
Expand Down Expand Up @@ -102,11 +112,13 @@ export async function getVyperExecutable(
version,
fileName,
);
logDebug('Downloaded vyper', {
version,
vyperPath,
platform,
});
if (success) {
logDebug('Downloaded vyper', {
version,
vyperPath,
platform,
});
}
if (success && !validateVyperPath(vyperPath)) {
logError('Cannot validate vyper', {
version,
Expand Down
32 changes: 22 additions & 10 deletions services/server/src/server/services/compiler/local/vyperCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { asyncExec, fetchWithBackoff } from "./common";
const HOST_VYPER_REPO = "https://github.com/vyperlang/vyper/releases/download/";

export function findVyperPlatform(): string | false {
if (process.platform === "darwin") {
if (
process.platform === "darwin" &&
(process.arch === "x64" || process.arch === "arm64")
) {
return "darwin";
}
if (process.platform === "linux" && process.arch === "x64") {
Expand All @@ -37,13 +40,20 @@ export async function useVyperCompiler(
vyperJsonInput: VyperJsonInput,
): Promise<VyperOutput> {
const vyperPlatform = findVyperPlatform();
let vyperPath;
if (vyperPlatform) {
vyperPath = await getVyperExecutable(vyperRepoPath, vyperPlatform, version);
if (!vyperPlatform) {
throw new Error("Vyper is not supported on this machine.");
}

const vyperPath = await getVyperExecutable(
vyperRepoPath,
vyperPlatform,
version,
);

if (!vyperPath) {
throw new Error("Vyper path not found");
throw new Error(
"Vyper path not found. Maybe an incorrect version was provided.",
);
}

let compiled: string | undefined;
Expand Down Expand Up @@ -112,11 +122,13 @@ export async function getVyperExecutable(
version,
fileName,
);
logger.debug("Downloaded vyper", {
version,
vyperPath,
platform,
});
if (success) {
logger.debug("Downloaded vyper", {
version,
vyperPath,
platform,
});
}
if (success && !validateVyperPath(vyperPath)) {
logger.error("Cannot validate vyper", {
version,
Expand Down

0 comments on commit 401b8ea

Please sign in to comment.