Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lithdew/solana-zig
Write Solana programs in Zig.
https://github.com/lithdew/solana-zig
Last synced: 11 days ago
JSON representation
Write Solana programs in Zig.
- Host: GitHub
- URL: https://github.com/lithdew/solana-zig
- Owner: lithdew
- Created: 2022-07-29T18:18:44.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-26T10:54:48.000Z (almost 2 years ago)
- Last Synced: 2024-07-31T08:19:04.284Z (3 months ago)
- Language: Zig
- Homepage:
- Size: 39.1 KB
- Stars: 25
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome - lithdew/solana-zig - Write Solana programs in Zig. (Zig)
README
# solana-zig
## Setup
1. Add this repository as a submodule to your project:
```console
git submodule init
git submodule add https://github.com/lithdew/solana-zig.git sol
git submodule update --init --recursive
```2. In build.zig:
```zig
const std = @import("std");
const sol = @import("sol/build.zig");// Assume 'step' is a *std.build.LibExeObjStep, and 'sol/' is the directory in
// which this repository is located within your project.const sol_pkgs = sol.Packages("sol/");
inline for (@typeInfo(sol_pkgs).Struct.decls) |field| {
step.addPackage(@field(sol_pkgs, field.name));
}
```## Example
1. Setup build.zig:
```zig
const std = @import("std");
const sol = @import("sol/build.zig");const sol_pkgs = sol.Packages("sol/");
pub fn build(b: *std.build.Builder) !void {
const program = b.addSharedLibrary("helloworld", "main.zig", .unversioned);
inline for (@typeInfo(sol_pkgs).Struct.decls) |field| {
program.addPackage(@field(sol_pkgs, field.name));
}
program.install();try sol.linkSolanaProgram(b, program);
try sol.generateProgramKeypair(b, program);
}
```2. Setup main.zig:
```zig
const sol = @import("sol");export fn entrypoint(_: [*]u8) callconv(.C) u64 {
sol.print("Hello world!", .{});
return 0;
}
```3. Build and deploy your program on Solana devnet:
```console
$ zig build
Program ID: FHGeakPPYgDWomQT6Embr4mVW5DSoygX6TaxQXdgwDYU$ solana airdrop -ud 1
Requesting airdrop of 1 SOLSignature: 52rgcLosCjRySoQq5MQLpoKg4JacCdidPNXPWbJhTE1LJR2uzFgp93Q7Dq1hQrcyc6nwrNrieoN54GpyNe8H4j3T
882.4039166 SOL
$ solana program deploy -ud zig-out/lib/libhelloworld.so
Program Id: FHGeakPPYgDWomQT6Embr4mVW5DSoygX6TaxQXdgwDYU
```