Skip to content

Commit

Permalink
Add detect missing library mode compiler version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mimi TxFusion committed Sep 8, 2023
1 parent a079196 commit e992886
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/hardhat-zksync-solc/src/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ZkSolcConfig } from '../types';
import { compileWithBinary } from './binary';
import { HardhatDocker, Image } from '@nomiclabs/hardhat-docker';
import semver from 'semver';
import {
validateDockerIsInstalled,
createDocker,
Expand All @@ -12,6 +13,7 @@ import {
import { CompilerInput } from 'hardhat/types';
import { ZkSyncSolcPluginError } from '../errors';
import { findMissingLibraries, mapMissingLibraryDependencies, writeLibrariesToFile } from '../utils';
import { DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION } from '../constants';

export async function compile(zksolcConfig: ZkSolcConfig, input: CompilerInput, solcPath?: string) {
let compiler: ICompiler;
Expand All @@ -38,21 +40,23 @@ export class BinaryCompiler implements ICompiler {

public async compile(input: CompilerInput, config: ZkSolcConfig) {
// Check for missing libraries
const zkSolcOutput = await compileWithBinary(input, config, this.solcPath, true);
if (semver.gte(config.version, DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION)) {
const zkSolcOutput = await compileWithBinary(input, config, this.solcPath, true);

const missingLibraries = findMissingLibraries(zkSolcOutput);
if (missingLibraries.size > 0) {
if (!config.settings.missingLibrariesPath) {
throw new ZkSyncSolcPluginError('Missing libraries path is not specified');
}

const missingLibraryDependencies = mapMissingLibraryDependencies(zkSolcOutput, missingLibraries);
// Write missing libraries to file
const missingLibrariesPath = config.settings.missingLibrariesPath!;
await writeLibrariesToFile(missingLibrariesPath, missingLibraryDependencies);
const missingLibraries = findMissingLibraries(zkSolcOutput);
if (missingLibraries.size > 0) {
if (!config.settings.missingLibrariesPath) {
throw new ZkSyncSolcPluginError('Missing libraries path is not specified');
}
const missingLibraryDependencies = mapMissingLibraryDependencies(zkSolcOutput, missingLibraries);
// Write missing libraries to file
const missingLibrariesPath = config.settings.missingLibrariesPath!;
await writeLibrariesToFile(missingLibrariesPath, missingLibraryDependencies);

config.settings.areLibrariesMissing = true;
return zkSolcOutput;
config.settings.areLibrariesMissing = true;
return zkSolcOutput;
}
}

return await compileWithBinary(input, config, this.solcPath);
Expand Down
1 change: 1 addition & 0 deletions packages/hardhat-zksync-solc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const PLUGIN_NAME = '@matterlabs/hardhat-zksync-solc';
export const ZK_ARTIFACT_FORMAT_VERSION = 'hh-zksolc-artifact-1';
export const ZKSOLC_BIN_REPOSITORY = 'https://github.com/matter-labs/zksolc-bin';
export const ZKSOLC_BIN_VERSION_INFO = `https://raw.githubusercontent.com/matter-labs/zksolc-bin/main`;
export const DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION = '1.3.14';

export const defaultZkSolcConfig: ZkSolcConfig = {
version: 'latest',
Expand Down

0 comments on commit e992886

Please sign in to comment.