[Solved] Compilation of contract with include

Hi all,
i’m currently struggling to compile a contract with an include of a custom library “Library.aes” which resides in a separate file at the same level of filesystem as the using contract.
The library looks like
namespace Library = type number = int function inc(x : number) : number = x + 1
The contract is using it like this
include "Library.aes"

When i compile (locally using compiler node) the contract, i always get
"Couldn't find include file 'Library.aes'\n"
also tried to pass the full path to the include, same result.
Is there a need to define the attribute options.file_system somehow?
Maybe @hanssv.chain you have an idea?

Thanks and regards,
Mitch

2 Likes

What version of the compiler are you using? It seems to work as it should when I try this:

~/Quviq/Aeternity/aesophia_cli [git:*(v4.2.0)?]: ls /tmp/*.aes
/tmp/Bar.aes	/tmp/Foo.aes
~/Quviq/Aeternity/aesophia_cli [git:*(v4.2.0)?]: cat /tmp/Bar.aes 
namespace Bar =
  function bar() = 42
~/Quviq/Aeternity/aesophia_cli [git:*(v4.2.0)?]: cat /tmp/Foo.aes 
include "Bar.aes"

contract Foo =
  entrypoint foo() = Bar.bar()
~/Quviq/Aeternity/aesophia_cli [git:*(v4.2.0)?]: ./aesophia_cli /tmp/Foo.aes 
Bytecode:
cb_+IJGA6Bgin9E8Mltn/M6jiLJEe9FQ8fTx3iATf+jWxapOb2zjMC4Va3+RNZEHwA3ADcAGg6CPwEDP/5sbA2iAjcABwEDVP64/p9/ADcABwQDEWxsDaKjLwMRRNZEHxFpbml0EWxsDaIhLkJhci5iYXIRuP6ffw1mb2+CLwCFNC4yLjAAkMFWBQ==
1 Like

Hi @hanssv.chain,
i’m using 4.2.0 and the java SDK to call the compiler endpoint (sorry missed that info)
Is there anything else to configure?

Then this question should perhaps go into the SDK pile :man_shrugging:

I have no clue how the SDK handle include files, I guess it talks to the http-compiler so you probably have to tell it that you have an additional file that you want to include somehow… But maybe @nduchak.chain or someone has a better idea.

2 Likes

basically it is about how the http-endpoint of the hosted sophia compiler needs to be called in order to get this working. we never tested this before because we always provided only the code of the contract in the request.

so specifically we don’t know how the CompileOpts (aesophia_http/swagger.yaml at master · aeternity/aesophia_http · GitHub) need to be filled in order to get it working.

do you have an example how it should work?

Yes, of course, let’s use the same example:

~/Quviq/Aeternity/aesophia_http [git:master]: FOO="include \\\"Bar.aes\\\"\\n\\ncontract Foo =\\n  entrypoint foo() = Bar.bar()"
~/Quviq/Aeternity/aesophia_http [git:master]: BAR="namespace Bar =\\n  function bar() = 42"
~/Quviq/Aeternity/aesophia_http [git:master]: curl -H "Content-Type: application/json" -d "{\"code\":\"$FOO\",\"options\":{\"backend\":\"fate\",\"file_system\":{\"Bar.aes\":\"$BAR\"}}}" -X POST http://localhost:3080/compile
{"bytecode":"cb_+IJGA6AANCB3UsSiP2HGHRML0dG95vNT9JsqZQMjPYAfEG1w6cC4Va3+RNZEHwA3ADcAGg6CPwEDP/5sbA2iAjcABwEDVP64/p9/ADcABwQDEWxsDaKjLwMRRNZEHxFpbml0EWxsDaIhLkJhci5iYXIRuP6ffw1mb2+CLwCFNC4yLjAAfreb3w=="}

Beware the quoting of strings, but apart from that it is rather straightforward.

1 Like

Hi @hanssv.chain - thanks for the hints - after initializing the file_system like you did in the sample with “namespace” and code it worked.
Thanks :slight_smile:

3 Likes