Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Native loading strategy to support TRUFFLE_NATIVE_SOLC_PATH #6007

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/compile-solidity/src/compilerSupplier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export class CompilerSupplier {
private version: string;
private docker: boolean;
private strategyOptions: StrategyOptions;
private nativePath: string;

constructor({ events, solcConfig }) {
const { version, docker, compilerRoots, dockerTagsUrl, spawn } = solcConfig;
const { version, docker, compilerRoots, dockerTagsUrl, spawn, nativePath } =
solcConfig;
this.version = version ? version : defaultSolcVersion;
this.docker = docker;
this.nativePath = nativePath;
this.strategyOptions = {};
if (version) this.strategyOptions.version = this.version;
if (dockerTagsUrl) this.strategyOptions.dockerTagsUrl = dockerTagsUrl;
Expand All @@ -44,7 +47,7 @@ export class CompilerSupplier {
if (useDocker) {
strategy = new Docker(this.strategyOptions);
} else if (useNative) {
strategy = new Native();
strategy = new Native(this.nativePath);
} else if (useSpecifiedLocal) {
strategy = new Local();
} else if (isValidVersionRange) {
Expand Down Expand Up @@ -83,7 +86,7 @@ export class CompilerSupplier {
if (useDocker) {
strategy = new Docker(this.strategyOptions);
} else if (useNative) {
strategy = new Native();
strategy = new Native(this.nativePath);
} else if (useSpecifiedLocal) {
strategy = new Local();
} else if (isValidVersionRange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ const { normalizeSolcVersion } = require("../normalizeSolcVersion");
const { NoVersionError } = require("../errors");

export class Native {
private solcPath: string;

constructor(solcPath: string) {
this.solcPath = solcPath;
}

load() {
const versionString = this.validateAndGetSolcVersion();
const command = "solc --standard-json";
const command = `${this.solcPath} --standard-json`;
const maxBuffer = 1024 * 1024 * 50;

try {
Expand All @@ -25,7 +31,7 @@ export class Native {
validateAndGetSolcVersion() {
let version;
try {
version = execSync("solc --version");
version = execSync(`${this.solcPath} --version`);
} catch (error) {
throw new NoNativeError(error);
}
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/configDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const getInitialConfig = ({
},
compilers: {
solc: {
nativePath: `{process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"}`,
cds-amal marked this conversation as resolved.
Show resolved Hide resolved
settings: {
//Note: The default solc version is *not* set here!
//It's set in compilerSupplier/index.js in compile-solidity
Expand Down