Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

env:
SOLANA_ZIG_VERSION: v1.47.0
SOLANA_ZIG_VERSION: v1.52.0
SOLANA_ZIG_DIR: solana-zig
SOLANA_C_DIR: solana-c-sdk
SOLANA_LLVM_DIR: solana-llvm
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ a little-endian u64 in instruction data.
| Language | CU Usage |
| --- | --- |
| Rust | 459 |
| Zig | 38 |
| Zig | 37 |
| C | 104 |
| Assembly | 30 |
| Rust (pinocchio) | 28 |
Expand All @@ -186,7 +186,7 @@ address and `invoke_signed` to CPI to the system program.
| Language | CU Usage | CU Usage (minus syscalls) |
| --- | --- | --- |
| Rust | 3698 | 1198 |
| Zig | 2809 | 309 |
| Zig | 2967 | 309 |
| C | 3122 | 622 |
| Rust (pinocchio) | 2802 | 302 |

Expand Down Expand Up @@ -215,39 +215,39 @@ program.
| Language | CU Usage |
| --- | --- |
| Rust | 1115 |
| Zig | 152 |
| Zig | 142 |

* Initialize Account

| Language | CU Usage |
| --- | --- |
| Rust | 2071 |
| Zig | 175 |
| Zig | 158 |

* Mint To

| Language | CU Usage |
| --- | --- |
| Rust | 2189 |
| Zig | 154 |
| Zig | 133 |

* Transfer

| Language | CU Usage |
| --- | --- |
| Rust | 2208 |
| Zig | 145 |
| Zig | 124 |

* Burn

| Language | CU Usage |
| --- | --- |
| Rust | 2045 |
| Zig | 141 |
| Zig | 123 |

* Close Account

| Language | CU Usage |
| --- | --- |
| Rust | 1483 |
| Zig | 122 |
| Zig | 114 |
12 changes: 7 additions & 5 deletions cpi/zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ const solana = @import("solana_program_sdk");
pub fn build(b: *std.Build) !void {
const target = b.resolveTargetQuery(solana.sbf_target);
const optimize = .ReleaseFast;

const dep_opts = .{ .target = target, .optimize = optimize };

const solana_lib_dep = b.dependency("solana_program_library", dep_opts);
const solana_lib_mod = solana_lib_dep.module("solana_program_library");

const program = b.addSharedLibrary(.{
const program = b.addLibrary(.{
.name = "solana_program_rosetta_cpi",
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
})
});

program.root_module.addImport("solana_program_library", solana_lib_mod);
Expand Down
8 changes: 4 additions & 4 deletions cpi/zig/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

.dependencies = .{
.solana_program_sdk = .{
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.16.2.tar.gz",
.hash = "solana_program_sdk-0.16.2-wGj9UHXjAAAK5z6ZdLUJ5uu2SxgE8o7ZJ9Il4EG22IJP",
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.17.1.tar.gz",
.hash = "solana_program_sdk-0.17.1-wGj9UBrlAADAagTi3MSX1vSpGg-DePWB_5znbUgMlH1U",
},
.solana_program_library = .{
.url = "https://github.com/joncinque/solana-program-library-zig/archive/refs/tags/v0.15.1.tar.gz",
.hash = "solana_program_library-0.15.1-10r-le4EAQBXCYrq-CeWEKfTnJEh29ErMm8tA46Mi2Dd",
.url = "https://github.com/joncinque/solana-program-library-zig/archive/refs/tags/v0.16.1.tar.gz",
.hash = "solana_program_library-0.16.1-10r-lcr-AACkeemV1ql6olBAHLdID3JPJmGcNsx1gayC",
},
},

Expand Down
4 changes: 2 additions & 2 deletions cpi/zig/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const system_ix = sol_lib.system;
const SIZE = 42;

export fn entrypoint(input: [*]u8) u64 {
const context = sol.Context.load(input) catch return 1;
const context = sol.context.Context.load(input) catch return 1;
const allocated = context.accounts[0];

const expected_allocated_key = sol.PublicKey.createProgramAddress(
const expected_allocated_key = sol.public_key.PublicKey.createProgramAddress(
&.{ "You pass butter", &.{context.data[0]} },
context.program_id.*,
) catch return 1;
Expand Down
11 changes: 7 additions & 4 deletions helloworld/zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const solana = @import("solana_program_sdk");
pub fn build(b: *std.Build) !void {
const target = b.resolveTargetQuery(solana.sbf_target);
const optimize = .ReleaseFast;
const program = b.addSharedLibrary(.{
const program = b.addLibrary(.{
.name = "solana_program_rosetta_helloworld",
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
})
});
_ = solana.buildProgram(b, program, target, optimize);
b.installArtifact(program);
Expand Down
32 changes: 6 additions & 26 deletions helloworld/zig/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
.{
.name = .solana_rosetta_helloworld,
.fingerprint = 0x34d885e7d0be5910,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.13.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
.minimum_zig_version = "0.14.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.version = "0.15.0",
.minimum_zig_version = "0.15.0",
.dependencies = .{
.base58 = .{
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.14.0.tar.gz",
.hash = "base58-0.14.0-6-CZm81qAAD4JCRHgewcNh8FS0pmnk7-OmwUkosaFKvg",
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.15.0.tar.gz",
.hash = "base58-0.15.0-6-CZmwVpAAAxqof6REya9G_XyHL1fTqUsAcsZ-J1IHMF",
},
.solana_program_sdk = .{
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.16.2.tar.gz",
.hash = "solana_program_sdk-0.16.2-wGj9UHXjAAAK5z6ZdLUJ5uu2SxgE8o7ZJ9Il4EG22IJP",
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.17.0.tar.gz",
.hash = "solana_program_sdk-0.17.0-wGj9UHjiAAC5lyL1BQ4MI7wcQYrqSjHrxdvZXDaA8Glb",
},
},

// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package.
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
// For example...
"build.zig",
"build.zig.zon",
"src",
Expand Down
2 changes: 1 addition & 1 deletion helloworld/zig/main.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sol = @import("solana_program_sdk");

export fn entrypoint(_: [*]u8) u64 {
sol.log("Hello world!");
sol.log.log("Hello world!");
return 0;
}
2 changes: 1 addition & 1 deletion install-solana-zig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if [[ -n $SOLANA_ZIG_VERSION ]]; then
solana_zig_version="$SOLANA_ZIG_VERSION"
else
solana_zig_version="v1.47.0"
solana_zig_version="v1.52.0"
fi
solana_zig_release_url="https://github.com/joncinque/solana-zig-bootstrap/releases/download/solana-$solana_zig_version"

Expand Down
11 changes: 7 additions & 4 deletions pubkey/zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const solana = @import("solana_program_sdk");
pub fn build(b: *std.Build) !void {
const target = b.resolveTargetQuery(solana.sbf_target);
const optimize = .ReleaseFast;
const program = b.addSharedLibrary(.{
const program = b.addLibrary(.{
.name = "solana_program_rosetta_pubkey",
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
})
});
_ = solana.buildProgram(b, program, target, optimize);
b.installArtifact(program);
Expand Down
20 changes: 4 additions & 16 deletions pubkey/zig/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
.{
.name = .solana_rosetta_pubkey,
.fingerprint = 0xa8636daaef29becd,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.13.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
.minimum_zig_version = "0.14.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.version = "0.15.0",
.minimum_zig_version = "0.15.0",
.dependencies = .{
.solana_program_sdk = .{
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.16.2.tar.gz",
.hash = "solana_program_sdk-0.16.2-wGj9UHXjAAAK5z6ZdLUJ5uu2SxgE8o7ZJ9Il4EG22IJP",
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.17.0.tar.gz",
.hash = "solana_program_sdk-0.17.0-wGj9UHjiAAC5lyL1BQ4MI7wcQYrqSjHrxdvZXDaA8Glb",
},
},
.paths = .{
Expand Down
2 changes: 1 addition & 1 deletion pubkey/zig/main.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const PublicKey = @import("solana_program_sdk").PublicKey;
const PublicKey = @import("solana_program_sdk").public_key.PublicKey;

export fn entrypoint(input: [*]u8) u64 {
const id: *align(1) PublicKey = @ptrCast(input + 16);
Expand Down
11 changes: 7 additions & 4 deletions token/zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ pub fn build(b: *std.Build) !void {
//const solana_lib_dep = b.dependency("solana-program-library", dep_opts);
//const solana_lib_mod = solana_lib_dep.module("solana-program-library");

const program = b.addSharedLibrary(.{
const program = b.addLibrary(.{
.name = "spl_token",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.optimize = optimize,
.target = target,
})
});

//program.root_module.addImport("solana-program-library", solana_lib_mod);
Expand Down
28 changes: 4 additions & 24 deletions token/zig/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
.{
.name = .solana_rosetta_token,
.fingerprint = 0xc77c51400e78e0da,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.13.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
.minimum_zig_version = "0.14.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.version = "0.15.0",
.minimum_zig_version = "0.15.0",
.dependencies = .{
.solana_program_sdk = .{
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.16.2.tar.gz",
.hash = "solana_program_sdk-0.16.2-wGj9UHXjAAAK5z6ZdLUJ5uu2SxgE8o7ZJ9Il4EG22IJP",
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.17.1.tar.gz",
.hash = "solana_program_sdk-0.17.1-wGj9UBrlAADAagTi3MSX1vSpGg-DePWB_5znbUgMlH1U",
},
},

// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package.
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
// For example...
"build.zig",
"build.zig.zon",
"src",
Expand Down
Loading