Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling for DFINITY #7

Open
skilesare opened this issue Oct 6, 2020 · 3 comments
Open

Compiling for DFINITY #7

skilesare opened this issue Oct 6, 2020 · 3 comments

Comments

@skilesare
Copy link

I stumbled upon this project while trying to find a solution to run javascirpt on DFINITY(dfinity.org). To do so I need a wasm module that I can define a .did file for. Given these two things I should be able to run C code in a dfinity canister. I've successfully accomplished this using the example at https://github.com/skilesare/examples/tree/master/c/reverse.

I'd love to get either duktape or quickjs running. All I really need is the ability to submit some code and have it evaluated. I guess I also need to keep track of the current context I'm running in as well. Theoretically dfinity has orthogonal persistance so once the context is up and running it should stay that way. It might be a fun project and I'd love to at least get some pointers on where to start. I know very little about c and haven't compiled anything significant in it in about 25 years so some hand holding would be required.

@saghul
Copy link
Owner

saghul commented Oct 8, 2020

Hey there! I'm not familiar with DFINITY, sorry. Can you perhaps describe how a WASM module should behave so it can run in the canister?

@skilesare
Copy link
Author

I think it is pretty basic. They have a candid .did file which is used for translation(https://sdk.dfinity.org/docs/candid-spec/idl). The big thing is that there really isn't IO. Everything is a function. When you load a canister into DFINITY they analyze the candid .did file and find the functions that they need to expose. You can then call those functions via the sdk and candid transfltes the results into your file format.

Take a look at this file: https://github.com/skilesare/examples/blob/master/c/reverse/reverse.c

It is a simple example and it looks like they load in some "ic0" libraries that are "internet computer" system functions. I'd love to have a full list, but don't at the moment. Maybe there is a way to decompile the list once the wasm is compiled?

This is the did file that maps reverse and tells DFINITY to expose it: https://github.com/skilesare/examples/blob/master/c/reverse/reverse.did

Pretty much reading through how do deploy a c canister is listed here: https://github.com/skilesare/examples/blob/master/c/reverse/README.adoc

Most normal DFINITY canisters are written in a language called motoko and a bunch of the system calls are built in. It uses something called 'orthogonal persistence' which means that the program basically always stays up and running and the memory stays active, so there is no need to write storage code. I'm guessing that there is actually some ic0 system call to do this for c programs and I don't know what that is at the moment. I'd be fine with just getting an eval() function to work in the short term that proves that js can run in it. Later I can look at how to store the context in orthogonal persistence so that you can get multiple threads of parallel contexts going. I'm thinking for starters, something as simple as https://github.com/svaarala/duktape/blob/master/examples/eval/eval.c

This is a good overview of the highlevel concepts: https://sdk.dfinity.org/docs/developers-guide/introduction-key-concepts.html

@skilesare
Copy link
Author

Looks like they just published some more info here:

https://forum.dfinity.org/t/how-to-write-a-minimal-cdk/1381/5

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

No branches or pull requests

2 participants