solana/sdk/bpf
Jack May b78a13d42c
Nits (#4662)
2019-06-12 13:04:24 -07:00
..
inc Add tick height syscall (#4497) 2019-05-31 16:29:21 -06:00
llvm-docker First stab at Rust BPF (#2269) 2019-01-02 15:12:42 -08:00
rust-utils Nits (#4662) 2019-06-12 13:04:24 -07:00
scripts Enable iter test (#4542) 2019-06-07 16:44:14 -07:00
.gitignore Ignore rust toolchain and sysroot 2019-02-25 16:40:35 -08:00
README.md Remove upstream LLVM install instructions as we now (temporarily) bundle a forked LLVM 2018-12-01 10:47:59 -08:00
bpf.ld Fix eh frame relocation (#2109) 2018-12-11 12:14:41 -08:00
bpf.mk Fix BPF C tests and run as part of CI (#2540) 2019-01-24 12:15:37 -08:00

README.md

Development

Quick start

To get started create a makefile containing:

include path/to/bpf.mk

and src/program.c containing:

#include <solana_sdk.h>

bool entrypoint(const uint8_t *input) {
  SolKeyedAccount 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.

Unit tests

Built-in support for unit testing is provided by the Criterion test framework. To get started create the file test/example.c containing:

#include <criterion/criterion.h>
#include "../src/program.c"

Test(test_suite_name, test_case_name) {
  cr_assert(true);
}

Then run make test.

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