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

Support multiple simultaneous solc versions #2021

Closed
1 task done
amkCha opened this issue May 15, 2019 · 18 comments
Closed
1 task done

Support multiple simultaneous solc versions #2021

amkCha opened this issue May 15, 2019 · 18 comments

Comments

@amkCha
Copy link

amkCha commented May 15, 2019


tags: compiler, solidity-versioning


Issue

In contracts folder, I have old contracts in 0.4 version of solidity and new contracts in 0.5 version. I would like to compile them in the same project but in truffle-config.js, I can only specify one version of solc.

Steps to Reproduce

In contracts folder, create a contract A in 0.4 and another one, contract B, in 0.5

Expected Behavior

I would like truffle compile to work

Actual Results

If I compile with solc 0.4.24, contract B in 0.5 fails to compile
If I compile with solc 0.5.0, contract A in 0.4 fails to compile

Environment

  • Operating System: ubuntu 18.10
  • Ethereum client: ganache
  • Truffle version (truffle version): 5.0.16
  • node version (node --version): 11.9.0
  • npm version (npm --version): 6.5.0
@CruzMolina
Copy link
Contributor

CruzMolina commented May 15, 2019

Hey @amkCha, you might be able to tinker with your older pragma statements like so:

pragma solidity >0.4.25;

(assuming you want to compile with 0.5.0 and above)

@amkCha
Copy link
Author

amkCha commented May 15, 2019

Hi @CruzMolina, thank you very much for you help !

I had to change two more things in old contracts in 0.4 for them to work

  • SyntaxError: Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it
  • Event invocations have to be prefixed by "emit"

If you see a better workaround, I'd be happy to hear about it

Else, after adding 'emit' and changing the function naming, it's compiling :)

@fainashalts
Copy link
Contributor

Hi @amkCha, thanks for bringing this up! We're aware of this limitation and will take steps to resolve this in the future.

@se3000
Copy link

se3000 commented Aug 1, 2019

Any progress here?

@eggplantzzz
Copy link
Contributor

@se3000 This problem is actually not trivial to solve so I don't know how soon it will have a solution. One solution which is a bit hacky is to build out your own "external compilation" step. You can specify your own separate compilation step manually and include it in the truffle config. You could group the contracts that require a different compiler together and compile them separately. Here are the docs for Truffle's external compilation feature https://www.trufflesuite.com/docs/truffle/reference/configuration#external-compilers

@naddison36
Copy link

I've got the same problem. See issue #2354 for how I'm dealing with it.

@elenadimitrova
Copy link

We need to maintain contracts between 0.5 and 0.6 versions and facing the same problem. I tried using the --config option with no success:

$ truffle compile lib --config ./truffle-config-lib.js
> Warning: possible unsupported (undocumented in help) command line option: --config
... 
TypeError: Cannot read property '0' of null
    at detectErrors (/Users/Elena/.nvm/versions/node/v10.12.0/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/run.js:283:61)
    at run (/Users/Elena/.nvm/versions/node/v10.12.0/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/run.js:36:29)
Truffle v5.1.12 (core: 5.1.12)
Node v10.12.0

@eggplantzzz
Copy link
Contributor

Hey @elenadimitrova! I don't think you can specify a specify a path to the file to be compiled (I think that's what lib is, right?).

This is kind of a tricky (and obnoxious, I know) thing right now but I think you could have 2 different contracts folders and 2 different truffle-config.js files with the 2 different solc versions specified. You could do something like the following:
truffle compile --config <pathToConfigForV4>
and then
truffle compile --config <pathToConfigForV5>.

Each config would have to specify a contracts_directory which would point to the directory storing the contracts for the compiler indicated.

I know, I know, this is not ideal but just wanted to provide a workaround that perhaps someone will find helpful. Eventually we'll get this problem sorted out :)

@elenadimitrova
Copy link

elenadimitrova commented Jul 28, 2020

Does contracts_directory accept array of directories as well? Currently we have the following folder structure:

contracts
   infrastructure
   infrastructure_0.5
   modules
   wallet
contracts-legacy
contracts-test
lib

contracts\infrastructure_0.5, contracts-legacy and lib are compiled with 0.5.4 while the rest with 0.6.12 . Optimiser settings is also different for lib than for the rest of the 0.5.4 contracts.

Can we get away with just 3truffle-configs supporting the respective directories or do I need to have 8 of them 🙊 ? And also can I store these configs in the root of the solution or they need to be placed in the respective contract folders?

@eggplantzzz
Copy link
Contributor

As far as I know you can only specify contracts_directory as a path but that sounds like a pretty cool idea. I'll have to look into how easy that would be to add. Let me get back to you on that.

I think right now you would have to either have a whole bunch of configs for each grouping or group them by compiler version (and optimizer settings). In other words, for each compilation you can only use one set of compiler settings.

@elenadimitrova
Copy link

I'd rather keep them grouped logically than by compiler version as the latter will change over time. I've managed to get it to compile the way I want with nine! truffle configs.

@gnidan gnidan changed the title Compile 0.4 and 0.5 contracts in same project Support multiple simultaneous solc versions Jul 28, 2020
@gnidan
Copy link
Contributor

gnidan commented Jul 28, 2020

Moving this to our backlog. I want it!

@elenadimitrova
Copy link

Thanks! I am also having problems testing with the nine-truffle-configs setup as the compile command that precedes test only executes against a single config. So do I wait for the --compile-none to be released and do my own compilation or we have a configurable compilation pipeline that truffle understands?

@gnidan
Copy link
Contributor

gnidan commented Jul 28, 2020

@elenadimitrova in the meantime, you might be able to pass --compiler=vyper as a workaround (assuming you don't have Vyper contracts to compile)

Wait... maybe that's the right place for "--compile-none", since that's already hooked up... we could make it something like --compiler=none

@haltman-at
Copy link
Contributor

Hm, does this still need to be open, now that version: "pragma" is implemented? Can this be closed?

@haltman-at
Copy link
Contributor

Closing this now that version: "pragma" has been implemented in #3704! You can read more about this here.

@ilya-korotya
Copy link

Hi. I have a question about different versions of the compiler for the library and contract.
I have the next directory structure:

project
│   truffle-config.js
└───contracts
   └───Contract1.sol
   └───lib
       └───lib1.sol
  • truffle-config.js
  compilers: {
    solc: {
      version: "pragma"
    }
  }
  • Contract1.sol
pragma solidity ^0.8.0;

import "./lib/lib1.sol";
...
  • lib1.sol
pragma solidity ^0.6.0;
...

Contract1.sol should compile with version ^0.8.0 but the lib1.sol should compile with ^0.6.0. This config doesn't work for me, because:

Do note, however, that each source file and all of its imports must be compiled with one version of Solidity; this means there must be a version of the compiler that satisfies all of their pragma expressions.

https://trufflesuite.com/blog/take-a-dive-into-truffle-5/#pragma-compilation

In theory, can I compile the library and contract with different versions of the compiler?

@haltman-at
Copy link
Contributor

No, right now if the one imports the other then they must be compiled with the same version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants