Anylsite / anyl-wallet

🏦 Anyl Embedded Wallet for Internet of Things
Apache License 2.0
30 stars 16 forks source link

macOS compilation error: <endian.h> file not found #60

Closed npes-95 closed 6 years ago

npes-95 commented 6 years ago

This file isn't found when compiling under macOS. To compile under macOS, you need to modify the include in helpers/rlp_encoder.c to read:

#include <machine/endian.h>

Would this still be valid under Linux?

lorepieri8 commented 6 years ago

Can you specify which build are you playing with and report the Error log?

npes-95 commented 6 years ago

This is for the x86 build. The log reads:

../helpers/rlp_encoder.c:9:10: fatal error: 'endian.h' file not found
#include <endian.h>
lorepieri8 commented 6 years ago

Did you installed solc and run the

pip install --user -r requirements.txt

(or pip3)

?

npes-95 commented 6 years ago

Yep. I'll go over it again now to make sure everything is okay.

npes-95 commented 6 years ago

Everything is okay as far as I can tell. Is the ABI compiler called using python or python3? My default python is 2.7.

npes-95 commented 6 years ago

Apparently, you can include <sys/types.h> which will return the correct endian file for Linux/macOS.

https://stackoverflow.com/questions/27073837/fatal-error-endian-h-file-not-found

npes-95 commented 6 years ago

Okay so I've done a bit of digging, the <machine/endian.h> file on macOS doesn't define the htobe64() method, so there would have to be some kind of shim to make the code work on macOS.

https://gist.github.com/yinyin/2027912

npes-95 commented 6 years ago

I've just added the shim code to usr/local/include and the project compiles!

pcppcp commented 6 years ago

Hi @npes-95, we don't have many MacOS users so I am sorry that the build so wonky :) Great you made it work!

Regarding the endianess the shim code looks like a good solution - could you make a pull request for that?

Thanks!

npes-95 commented 6 years ago

That's okay, I was considering giving up and setting up a dual boot for a minute!

So the shim code needs to go in the user's local/include, should I modify an existing build script to copy that in there? I reckon we should keep a copy of the shim code in the repo in case the gist is deleted, where would be the best place to put it?

pcppcp commented 6 years ago

I'd create a separate directory for the shim (i.e. helpers/macos) and then we can conditionally include that path for the MacOS builds.

helpers/CMakeLists.txt

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    include_directories(helpers/macos)
endif()
devtodev commented 6 years ago

Hi! when I compiled for my desktop (Linux Fedora) all runs well, but when I change the target to a board like DBOARD=frdm_kl25z or DBOARD=nrf52840_pca10056 the endian.h file isn't found when run ninja. I tried to add <sys/types.h> but is the same.

pcppcp commented 6 years ago

@devtodev for this error, can you create a gist with an output of ninja -v

devtodev commented 6 years ago

Here it is https://gist.github.com/devtodev/ab7a30744a71bd83191d03ade64766ec

pcppcp commented 6 years ago

Thanks! Now I see where the problem is - I haven't noticed there is no endian.h for Zephyr. I'll create a shim file similar to one in #63 and then it should work.

pcppcp commented 6 years ago

that reminds me of the fact we desperately need CI builds for Zephyr target (#52) .. volunteers? :D

pcppcp commented 6 years ago

could you guys check out current master? It should compile now. (for zephyr builds)

devtodev commented 6 years ago

still is broken the zephyr compilation, here is the output https://gist.github.com/devtodev/b2edd806469eea457bbd33595fb16b60 I'll be working on it to fix it, if you have any advice please show me the light ;)

devtodev commented 6 years ago

Hi @pcppcp! I can compile for zephyr now, but to do that I made two "fixs". The first was fix wallet.c by comment the include "eth/account.h" and declare account_t struct, like this:

typedef struct {
    uint8_t *privkey;
    unsigned long nonce;
} account_t;

The correct solution will be add to the repo eth/account.h, I searched that file with:

git rev-list -n 1 HEAD -- eth/account.h

And the file never existed in this repo. Maybe when wallet.c was added, the developer forgot to add account.h to the repo.

The second fix was remove SHELL_REGISTER function call and their struct, because the struct not was correct filled. Do you know the correct way to fil this structure?

Well.. with this two fixes, the zephyr build compile fine, but to get the correct solution of this issues we need add eth/account.h and fill fine the struct of SHELL_REGISTER. Right?

MohitKAgnihotri commented 6 years ago

@devtodev I think I have the solution for the second question. We can register shell command as shown below.

SHELL_CREATE_STATIC_SUBCMD_SET(sub_crypto)
{
       /* Alphabetically sorted to ensure correct Tab autocompletion. */
       SHELL_CMD(pk2addr, NULL, "pk2addr", cmd_pk2addr),
       SHELL_SUBCMD_SET_END /* Array terminated. */
};

SHELL_CMD_REGISTER(crypto, &sub_crypto, "crypto eth", NULL);
pcppcp commented 6 years ago

@devtodev oops the account_t got lost somewhere. I've fixed it in PR #68

@MohitKumarAgniotri looks like you are using different version of Zephyr, I can't find any of the SHELL_* macros in the code. I'll update and take a look at that.

pcppcp commented 6 years ago

Yea I've been using Zephyr version from August so unsurprisingly it didn't compile for you :) Fixes in #69

npes-95 commented 6 years ago

Hey guys I'm gonna close this issue, as the solution for this has been merged. If there's still other problems, make a separate issue for them.