1- # solana-zig -sdk
1+ # solana-program -sdk-zig
22
33Write Solana on-chain programs in Zig!
44
@@ -10,6 +10,7 @@ which also provides tests and a CLI.
1010
1111Here are some other packages to help with developing Solana programs with Zig:
1212
13+ * [ Base-58] ( https://github.com/joncinque/base58-zig )
1314* [ Bincode] ( https://github.com/joncinque/bincode-zig )
1415* [ Borsh] ( https://github.com/joncinque/borsh-zig )
1516* [ Solana Program Library] ( https://github.com/joncinque/solana-program-library-zig )
@@ -36,16 +37,24 @@ You can run the convenience script in this repo to download the compiler to
36371 . Add this package and ` base58-zig ` to your project:
3738
3839``` console
39- zig fetch --save https://github.com/joncinque/base58-zig/archive/refs/tags/v0.12.2 .tar.gz
40- zig fetch --save https://github.com/joncinque/solana-sdk-zig/archive/refs/tags/v0.12 .0.tar.gz
40+ zig fetch --save https://github.com/joncinque/base58-zig/archive/refs/tags/v0.13.3 .tar.gz
41+ zig fetch --save https://github.com/joncinque/solana-program- sdk-zig/archive/refs/tags/v0.13 .0.tar.gz
4142```
4243
43- 2 . In your build.zig, add the modules that you want one by one, or use the
44+ 2 . (Optional) if you want to generate a keypair during building, you'll also
45+ need to install clap:
46+
47+ ``` console
48+ zig fetch --save https://github.com/Hejsil/zig-clap/archive/refs/tags/0.9.1.tar.gz
49+ ```
50+
51+ 3 . In your build.zig, add the modules that you want one by one, or use the
4452helpers in ` build.zig ` :
4553
4654``` zig
4755const std = @import("std");
4856const solana = @import("solana-program-sdk");
57+ const base58 = @import("base58");
4958
5059pub fn build(b: *std.build.Builder) !void {
5160 // Choose the on-chain target (bpf, sbf v1, sbf v2, etc)
@@ -60,28 +69,33 @@ pub fn build(b: *std.build.Builder) !void {
6069 const program = b.addSharedLibrary(.{
6170 .name = "program_name",
6271 // Give the root of your program, where the entrypoint is defined
63- .root_source_file = .{ . path = "src/main.zig" } ,
72+ .root_source_file = b. path( "src/main.zig") ,
6473 .optimize = optimize,
6574 .target = target,
6675 });
6776 // Use the `buildProgram` helper to create the solana-sdk module, add all
68- // of its required dependencies, link the program properly, and generate
69- // a keypair in `zig-out/lib` along with the compiled program.
77+ // of its required dependencies, link the program properly.
7078 const solana_mod = solana.buildProgram(b, program, target, optimize);
7179
80+ // Install the program artifact
81+ b.installArtifact(program);
82+
83+ // Optional: to generate a keypair in `zig-out/lib`, be sure to run this too:
84+ base58.generateProgramKeypair(b, program);
85+
7286 // Optional, but if you define unit tests in your program files, you can run
7387 // them with `zig build test` with this step included
7488 const test_step = b.step("test", "Run unit tests");
7589 const lib_unit_tests = b.addTest(.{
76- .root_source_file = .{ . path = "src/main.zig" } ,
90+ .root_source_file = b. path( "src/main.zig") ,
7791 });
7892 lib_unit_tests.root_module.addImport("solana-program-sdk", solana_mod);
7993 const run_unit_tests = b.addRunArtifact(lib_unit_tests);
8094 test_step.dependOn(&run_unit_tests.step);
8195}
8296```
8397
84- 3 . Setup ` src/main.zig ` :
98+ 4 . Setup ` src/main.zig ` :
8599
86100``` zig
87101const solana = @import("solana-program-sdk");
@@ -92,13 +106,13 @@ export fn entrypoint(_: [*]u8) callconv(.C) u64 {
92106}
93107```
94108
95- 4 . Download the solana-zig compiler using the script in this repository:
109+ 5 . Download the solana-zig compiler using the script in this repository:
96110
97111``` console
98112$ ./install-solana-zig.sh
99113```
100114
101- 5 . Build and deploy your program on Solana devnet:
115+ 6 . Build and deploy your program on Solana devnet:
102116
103117``` console
104118$ ./solana-zig/zig build --summary all
@@ -123,8 +137,8 @@ The helpers in build.zig contain various Solana targets. Here are their analogue
123137to the Rust build tools:
124138
125139* ` sbf_target ` -> ` cargo build-sbf `
126- * ` bpf_target ` -> ` cargo build-bpf `
127140* ` sbfv2_target ` -> ` cargo build-sbf --arch sbfv2 `
141+ * ** Deprecated** ` bpf_target ` -> ` cargo build-bpf `
128142
129143## Unit tests
130144
@@ -150,4 +164,4 @@ cd program-test/
150164```
151165
152166These tests require a Rust compiler along with the solana-zig compiler, as
153- mentioned in the prerequisites.
167+ mentioned in the prerequisites. Be sure to run ` ./install-solana-zig.sh ` first.
0 commit comments