Skip to content
Open
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
3 changes: 3 additions & 0 deletions tokens/escrow/zig/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
solana-zig
.zig-cache
zig-out
29 changes: 29 additions & 0 deletions tokens/escrow/zig/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const std = @import("std");
const solana = @import("solana_program_sdk");
const base58 = @import("base58");

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.addLibrary(.{ .name = "escrow_program", .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);

_ = solana.buildProgram(b, program, target, optimize);
b.installArtifact(program);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this redundant because of the following steps ?


const install_step = b.addInstallArtifact(program, .{ .dest_dir = .{ .override = .{ .custom = "../program-test/tests/fixtures" } } });
b.getInstallStep().dependOn(&install_step.step);

base58.generateProgramKeypair(b, program);
}
56 changes: 56 additions & 0 deletions tokens/escrow/zig/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .escrow,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
// Together with name, this represents a globally unique package
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need all the boilerplate from the zig init call? Maybe we should clean this up since it's a program example for solana?

// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x56bd27194122b09, // Changing this has security and trust implications.
// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.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.
.dependencies = .{
.solana_program_sdk = .{
.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.16.1.tar.gz",
.hash = "solana_program_library-0.16.1-10r-lcr-AACkeemV1ql6olBAHLdID3JPJmGcNsx1gayC",
},
.base58 = .{
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.15.0.tar.gz",
.hash = "base58-0.15.0-6-CZmwVpAAAxqof6REya9G_XyHL1fTqUsAcsZ-J1IHMF",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this is boilerplate we can remove

//"LICENSE",
//"README.md",
},
}
51 changes: 51 additions & 0 deletions tokens/escrow/zig/install-solana-zig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

if [[ -n $SOLANA_ZIG_VERSION ]]; then
solana_zig_version="$SOLANA_ZIG_VERSION"
else
solana_zig_version="v1.52.0"
fi
solana_zig_release_url="https://github.com/joncinque/solana-zig-bootstrap/releases/download/solana-$solana_zig_version"

output_dir="$1"
if [[ -z $output_dir ]]; then
output_dir="solana-zig"
fi
output_dir="$(mkdir -p "$output_dir"; cd "$output_dir"; pwd)"
cd $output_dir
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think if it's unquoted it might crash on paths with spaces


arch=$(uname -m)
if [[ "$arch" == "arm64" ]]; then
arch="aarch64"
fi
case $(uname -s | cut -c1-7) in
"Linux")
os="linux"
abi="musl"
;;
"Darwin")
os="macos"
abi="none"
;;
"Windows" | "MINGW64")
os="windows"
abi="gnu"
;;
*)
echo "install-solana-zig.sh: Unknown OS $(uname -s)" >&2
exit 1
;;
esac

solana_zig_tar=zig-$arch-$os-$abi.tar.bz2
url="$solana_zig_release_url/$solana_zig_tar"
echo "Downloading $url"
curl --proto '=https' --tlsv1.2 -SfOL "$url"
echo "Unpacking $solana_zig_tar"
tar -xjf $solana_zig_tar
rm $solana_zig_tar

solana_zig_dir="zig-$arch-$os-$abi-baseline"
mv "$solana_zig_dir"/* .
rmdir $solana_zig_dir
echo "solana-zig compiler available at $output_dir"
2 changes: 2 additions & 0 deletions tokens/escrow/zig/program-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
tests/fixtures
16 changes: 16 additions & 0 deletions tokens/escrow/zig/program-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "program-test"
version = "0.1.0"
edition = "2024"

[dev-dependencies]
litesvm = "0.6.0"
solana-instruction = "2.2.1"
solana-keypair = "2.2.1"
solana-native-token = "2.2.1"
solana-pubkey = "2.2.1"
solana-signer = "2.2.1"
solana-system-interface = "1.0.0"
solana-transaction = "2.2.1"
solana-message = "2.2.1"
solana-program = "2.2.1"
Empty file.
Loading