solana/sdk/bpf/c
Pierre 8a20e7f8de
sdk: fix broken C examples (#33701)
fix C broken example
2023-10-16 23:53:03 +02:00
..
inc Add alt_bn128 syscall tests (and fix related issues) (#31436) 2023-05-22 14:05:10 -07:00
README.md sdk: fix broken C examples (#33701) 2023-10-16 23:53:03 +02:00
bpf.ld
bpf.mk Fix SDK C makefile setting the correct path to clang headers (#30378) 2023-02-17 06:53:45 -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>

extern uint64_t entrypoint(const uint8_t *input) {
  SolAccountInfo ka[1];
  SolParameters params = (SolParameters) { .ka = ka };

  if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(ka))) {
    return ERROR_INVALID_ARGUMENT;
  }
  return SUCCESS;
}

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