Skip to content

Commit 83c6621

Browse files
authored
Update to Zig 0.15 (#17)
#### Problem Zig 0.15 is out, but the package is still on 0.14. #### Summary of changes Now that the solana-zig compiler supports 0.15, update everything! BREAKING CHANGES: * since `using namespace` was removed, do the right thing and import into `root.zig`, so imports will need a full path, so `sol.PublicKey` should become `sol.public_key.PublicKey` * update `callconv(.C)` -> `callconv(.c)` * change `format` definition to match new writer API * get format strings right: `"{}"` -> `"{f}"` * update program-test to mollusk, update other deps
1 parent 60aced6 commit 83c6621

File tree

20 files changed

+1527
-6807
lines changed

20 files changed

+1527
-6807
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build library and test programs
1+
name: Main
22

33
on:
44
push:
@@ -9,7 +9,7 @@ on:
99
- 'main'
1010

1111
env:
12-
SOLANA_ZIG_VERSION: v1.47.0
12+
SOLANA_ZIG_VERSION: v1.52.0
1313
SOLANA_ZIG_DIR: solana-zig
1414

1515
jobs:
@@ -66,7 +66,7 @@ jobs:
6666
- name: Install Rust
6767
uses: dtolnay/rust-toolchain@master
6868
with:
69-
toolchain: 1.84.1
69+
toolchain: 1.86.0
7070

7171
# took the workaround from https://github.com/sfackler/rust-openssl/issues/2149
7272
- name: Set Perl environment variables

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ You can run the convenience script in this repo to download the compiler to
3737
1. Add this package to your project:
3838

3939
```console
40-
zig fetch --save https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.16.0.tar.gz
40+
zig fetch --save https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.17.0.tar.gz
4141
```
4242

4343
2. (Optional) if you want to generate a keypair during building, you'll also
4444
need to install base58 and clap:
4545

4646
```console
47-
zig fetch --save https://github.com/joncinque/base58-zig/archive/refs/tags/v0.14.0.tar.gz
48-
zig fetch --save https://github.com/Hejsil/zig-clap/archive/refs/tags/0.10.0.tar.gz
47+
zig fetch --save https://github.com/joncinque/base58-zig/archive/refs/tags/v0.15.0.tar.gz
48+
zig fetch --save https://github.com/Hejsil/zig-clap/archive/refs/tags/0.11.0.tar.gz
4949
```
5050

5151
3. In your build.zig, add the modules that you want one by one, or use the
@@ -64,13 +64,18 @@ pub fn build(b: *std.build.Builder) !void {
6464
const target = b.resolveTargetQuery(solana.sbf_target);
6565
// Choose the optimization. `.ReleaseFast` gives optimized CU usage
6666
const optimize = .ReleaseFast;
67+
// Create a module for your program
68+
const mod = b.addModule("my_program", .{
69+
.root_source_file = b.path("src/root.zig"),
70+
.target = target,
71+
.optimize = optimize,
72+
});
6773
// Define your program as a shared library
68-
const program = b.addSharedLibrary(.{
74+
const program = b.addLibrary(.{
6975
.name = "program_name",
76+
.linkage = .dynamic,
7077
// Give the root of your program, where the entrypoint is defined
71-
.root_source_file = b.path("src/main.zig"),
72-
.optimize = optimize,
73-
.target = target,
78+
.root_module = mod,
7479
});
7580
// Use the `buildProgram` helper to create the solana-sdk module, and link
7681
// the program properly.
@@ -86,7 +91,7 @@ pub fn build(b: *std.build.Builder) !void {
8691
// them with `zig build test` with this step included
8792
const test_step = b.step("test", "Run unit tests");
8893
const lib_unit_tests = b.addTest(.{
89-
.root_source_file = b.path("src/main.zig"),
94+
.root_module = mod,
9095
});
9196
lib_unit_tests.root_module.addImport("solana_program_sdk", solana_mod);
9297
const run_unit_tests = b.addRunArtifact(lib_unit_tests);
@@ -99,7 +104,7 @@ pub fn build(b: *std.build.Builder) !void {
99104
```zig
100105
const solana = @import("solana_program_sdk");
101106
102-
export fn entrypoint(_: [*]u8) callconv(.C) u64 {
107+
export fn entrypoint(_: [*]u8) callconv(.c) u64 {
103108
solana.print("Hello world!", .{});
104109
return 0;
105110
}

build.zig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ pub fn build(b: *std.Build) void {
55
const optimize = b.standardOptimizeOption(.{});
66

77
// Export self as a module
8-
const solana_mod = b.addModule("solana_program_sdk", .{ .root_source_file = b.path("src/root.zig") });
9-
10-
const lib = b.addStaticLibrary(.{
11-
.name = "solana_program_sdk",
8+
const solana_mod = b.addModule("solana_program_sdk", .{
129
.root_source_file = b.path("src/root.zig"),
1310
.target = target,
1411
.optimize = optimize,
@@ -19,15 +16,10 @@ pub fn build(b: *std.Build) void {
1916
.optimize = optimize,
2017
});
2118
const base58_mod = base58_dep.module("base58");
22-
lib.root_module.addImport("base58", base58_mod);
2319
solana_mod.addImport("base58", base58_mod);
2420

25-
b.installArtifact(lib);
26-
2721
const lib_unit_tests = b.addTest(.{
28-
.root_source_file = b.path("src/root.zig"),
29-
.target = target,
30-
.optimize = optimize,
22+
.root_module = solana_mod,
3123
});
3224

3325
lib_unit_tests.root_module.addImport("base58", base58_mod);

build.zig.zon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.{
22
.fingerprint = 0xdc47aff950fd68c0,
33
.name = .solana_program_sdk,
4-
.version = "0.16.3",
5-
.minimum_zig_version = "0.14.0",
4+
.version = "0.17.0",
5+
.minimum_zig_version = "0.15.0",
66

77
// This field is optional.
88
// Each dependency must either provide a `url` and `hash`, or a `path`.
@@ -11,8 +11,8 @@
1111
// internet connectivity.
1212
.dependencies = .{
1313
.base58 = .{
14-
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.14.0.tar.gz",
15-
.hash = "base58-0.14.0-6-CZm81qAAD4JCRHgewcNh8FS0pmnk7-OmwUkosaFKvg",
14+
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.15.0.tar.gz",
15+
.hash = "base58-0.15.0-6-CZmwVpAAAxqof6REya9G_XyHL1fTqUsAcsZ-J1IHMF",
1616
},
1717
},
1818
.paths = .{

install-solana-zig.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
if [[ -n $SOLANA_ZIG_VERSION ]]; then
44
solana_zig_version="$SOLANA_ZIG_VERSION"
55
else
6-
solana_zig_version="v1.47.0"
6+
solana_zig_version="v1.52.0"
77
fi
88
solana_zig_release_url="https://github.com/joncinque/solana-zig-bootstrap/releases/download/solana-$solana_zig_version"
99

0 commit comments

Comments
 (0)