Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve platform architecture management for Vyper compiler #1776

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check anything for windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also checked Windows. I ran the file command to check for which architectures the three binary types are.

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 @@
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")

Check warning on line 15 in services/server/src/server/services/compiler/local/vyperCompiler.ts

View check run for this annotation

Codecov / codecov/patch

services/server/src/server/services/compiler/local/vyperCompiler.ts#L15

Added line #L15 was not covered by tests
) {
return "darwin";
}
if (process.platform === "linux" && process.arch === "x64") {
Expand All @@ -37,13 +40,20 @@
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.");

Check warning on line 44 in services/server/src/server/services/compiler/local/vyperCompiler.ts

View check run for this annotation

Codecov / codecov/patch

services/server/src/server/services/compiler/local/vyperCompiler.ts#L44

Added line #L44 was not covered by tests
}

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.",
);

Check warning on line 56 in services/server/src/server/services/compiler/local/vyperCompiler.ts

View check run for this annotation

Codecov / codecov/patch

services/server/src/server/services/compiler/local/vyperCompiler.ts#L54-L56

Added lines #L54 - L56 were not covered by tests
}

let compiled: string | undefined;
Expand Down Expand Up @@ -112,11 +122,13 @@
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