From ed09b2bdb8c584144890a9e9842406c9079baec9 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sun, 4 Nov 2018 12:30:05 -0800 Subject: [PATCH] Document BPF C program limitations --- programs/bpf/c/sdk/README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/programs/bpf/c/sdk/README.md b/programs/bpf/c/sdk/README.md index 5cf133bd3..ef1e4e349 100644 --- a/programs/bpf/c/sdk/README.md +++ b/programs/bpf/c/sdk/README.md @@ -21,7 +21,6 @@ $ sudo apt-get install -y clang-7 ``` ### macOS - The following depends on Homebrew, instructions on how to install Homebrew are at https://brew.sh Once Homebrew is installed, ensure the latest llvm is installed: @@ -31,3 +30,34 @@ $ brew install llvm # <- should output “Warning: llvm 7.0.0 is already instal $ brew --prefix llvm # <- should output “/usr/local/opt/llvm” ``` +## Development + +### Quick start +To get started create a `makefile` containing: +```make +include path/to/bpf.mk +``` +and `src/program.c` containing: +```c +#include + +bool entrypoint(const uint8_t *input) { + SolKeyedAccounts ka[1]; + uint8_t *data; + uint64_t data_len; + + if (!sol_deserialize(buf, ka, SOL_ARRAY_SIZE(ka), NULL, &data, &data_len)) { + return false; + } + print_params(1, ka, data, data_len); + return true; +} +``` + +Then run `make` to build `out/program.o`. +Run `make help` for more details. + +### Limitations +* Programs must be fully contained within a single .c file +* No libc is available but `solana_sdk.h` provides a minimal set of +primitives.