-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
LOCAL_PATH := /home/$(USER)/.local/share/solana/install/active_release/bin/sdk/sbf/c/ | ||
|
||
.PHONY: all clean | ||
|
||
SRC_DIR ?= ./src | ||
OUT_DIR ?= ./out | ||
|
||
all: $(OUT_DIR)/solana_program_rosetta_helloworld.so | ||
|
||
clean: | ||
rm -rf $(OUT_DIR) | ||
|
||
LLVM_DIR = $(LOCAL_PATH)../dependencies/platform-tools/llvm | ||
LLVM_SYSTEM_INC_DIRS := $(LLVM_DIR)/lib/clang/17/include | ||
STD_INC_DIRS := $(LLVM_DIR)/include | ||
STD_LIB_DIRS := $(LLVM_DIR)/lib | ||
|
||
CC := $(LLVM_DIR)/bin/clang | ||
LLD := $(LLVM_DIR)/bin/ld.lld | ||
|
||
SYSTEM_INC_DIRS := \ | ||
$(LOCAL_PATH)inc \ | ||
$(LLVM_SYSTEM_INC_DIRS) \ | ||
|
||
C_FLAGS := \ | ||
-Werror \ | ||
-O2 \ | ||
-fno-builtin \ | ||
-std=c17 \ | ||
$(addprefix -isystem,$(SYSTEM_INC_DIRS)) \ | ||
$(addprefix -I,$(STD_INC_DIRS)) \ | ||
-target sbf \ | ||
-fPIC | ||
|
||
SBF_LLD_FLAGS := \ | ||
-z notext \ | ||
-shared \ | ||
--Bdynamic \ | ||
$(LOCAL_PATH)sbf.ld \ | ||
--entry entrypoint \ | ||
-L $(STD_LIB_DIRS) \ | ||
-lc \ | ||
|
||
$(OUT_DIR)/main.o: $(SRC_DIR)/main.c | ||
mkdir -p $(OUT_DIR) | ||
$(CC) $(C_FLAGS) -o $(OUT_DIR)/main.o -c $(SRC_DIR)/main.c | ||
|
||
$(OUT_DIR)/solana_program_rosetta_helloworld.so: $(OUT_DIR)/main.o | ||
$(LLD) $(SBF_LLD_FLAGS) -o $(OUT_DIR)/solana_program_rosetta_helloworld.so $(OUT_DIR)/main.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @brief C-based Helloworld BPF program | ||
*/ | ||
#include <solana_sdk.h> | ||
|
||
extern uint64_t entrypoint(const uint8_t *input) { | ||
sol_log("Hello world!"); | ||
return SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
PROGRAM_NAME="$1" | ||
ROOT_DIR="$(cd "$(dirname "$0")"; pwd)" | ||
set -e | ||
PROGRAM_DIR=$ROOT_DIR/$PROGRAM_NAME | ||
cd $PROGRAM_DIR/c | ||
make | ||
SBF_OUT_DIR="$PROGRAM_DIR/c/out" cargo test --manifest-path "$PROGRAM_DIR/Cargo.toml" |