Skip to content

Commit 43effd4

Browse files
authored
Support Zig 0.14 (#11)
#### Problem Zig 0.14 is out, but the library is still on 0.13. #### Summary of changes Mostly straightforward changes: * Update the library name to solana_program_sdk * Bump to a new minor version * Update documentation * Use the new `addWriteFiles` API for the linker script * Use the new `Alignment` API for allocators and fix the tests * Update Rust deps for program-test to v2.2 * Update CI
1 parent 2771518 commit 43effd4

File tree

13 files changed

+3369
-1344
lines changed

13 files changed

+3369
-1344
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build library and test programs
33
on: [pull_request, push]
44

55
env:
6-
SOLANA_ZIG_VERSION: v1.43.0
6+
SOLANA_ZIG_VERSION: v1.47.0
77
SOLANA_ZIG_DIR: solana-zig
88

99
jobs:
@@ -60,7 +60,14 @@ jobs:
6060
- name: Install Rust
6161
uses: dtolnay/rust-toolchain@master
6262
with:
63-
toolchain: 1.78.0
63+
toolchain: 1.84.1
64+
65+
# took the workaround from https://github.com/sfackler/rust-openssl/issues/2149
66+
- name: Set Perl environment variables
67+
if: runner.os == 'Windows'
68+
run: |
69+
echo "PERL=$((where.exe perl)[0])" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
70+
echo "OPENSSL_SRC_PERL=$((where.exe perl)[0])" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
6471
6572
- name: Install build deps
6673
shell: bash

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ 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.15.1.tar.gz
40+
zig fetch --save https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.16.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.13.3.tar.gz
48-
zig fetch --save https://github.com/Hejsil/zig-clap/archive/refs/tags/0.9.1.tar.gz
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
4949
```
5050

5151
3. In your build.zig, add the modules that you want one by one, or use the
5252
helpers in `build.zig`:
5353

5454
```zig
5555
const std = @import("std");
56-
const solana = @import("solana-program-sdk");
56+
const solana = @import("solana_program_sdk");
5757
const base58 = @import("base58");
5858
5959
pub fn build(b: *std.build.Builder) !void {
@@ -88,7 +88,7 @@ pub fn build(b: *std.build.Builder) !void {
8888
const lib_unit_tests = b.addTest(.{
8989
.root_source_file = b.path("src/main.zig"),
9090
});
91-
lib_unit_tests.root_module.addImport("solana-program-sdk", solana_mod);
91+
lib_unit_tests.root_module.addImport("solana_program_sdk", solana_mod);
9292
const run_unit_tests = b.addRunArtifact(lib_unit_tests);
9393
test_step.dependOn(&run_unit_tests.step);
9494
}
@@ -97,7 +97,7 @@ pub fn build(b: *std.build.Builder) !void {
9797
4. Setup `src/main.zig`:
9898

9999
```zig
100-
const solana = @import("solana-program-sdk");
100+
const solana = @import("solana_program_sdk");
101101
102102
export fn entrypoint(_: [*]u8) callconv(.C) u64 {
103103
solana.print("Hello world!", .{});

build.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ 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") });
8+
const solana_mod = b.addModule("solana_program_sdk", .{ .root_source_file = b.path("src/root.zig") });
99

1010
const lib = b.addStaticLibrary(.{
11-
.name = "solana-program-sdk",
11+
.name = "solana_program_sdk",
1212
.root_source_file = b.path("src/root.zig"),
1313
.target = target,
1414
.optimize = optimize,
@@ -41,20 +41,19 @@ pub fn build(b: *std.Build) void {
4141
// General helper function to do all the tricky build steps, by adding the
4242
// solana-sdk module, adding the BPF link script
4343
pub fn buildProgram(b: *std.Build, program: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
44-
const solana_dep = b.dependency("solana-program-sdk", .{
44+
const solana_dep = b.dependency("solana_program_sdk", .{
4545
.target = target,
4646
.optimize = optimize,
4747
});
48-
const solana_mod = solana_dep.module("solana-program-sdk");
49-
program.root_module.addImport("solana-program-sdk", solana_mod);
48+
const solana_mod = solana_dep.module("solana_program_sdk");
49+
program.root_module.addImport("solana_program_sdk", solana_mod);
5050
linkSolanaProgram(b, program);
5151
return solana_mod;
5252
}
5353

5454
pub const sbf_target: std.Target.Query = .{
5555
.cpu_arch = .sbf,
5656
.os_tag = .solana,
57-
.cpu_features_add = std.Target.sbf.featureSet(&.{.solana}),
5857
};
5958

6059
pub const sbfv2_target: std.Target.Query = .{
@@ -73,7 +72,8 @@ pub const bpf_target: std.Target.Query = .{
7372
};
7473

7574
pub fn linkSolanaProgram(b: *std.Build, lib: *std.Build.Step.Compile) void {
76-
const linker_script = b.addWriteFile("bpf.ld",
75+
const write_file_step = b.addWriteFiles();
76+
const linker_script = write_file_step.add("bpf.ld",
7777
\\PHDRS
7878
\\{
7979
\\text PT_LOAD ;
@@ -100,9 +100,9 @@ pub fn linkSolanaProgram(b: *std.Build, lib: *std.Build.Step.Compile) void {
100100
\\}
101101
);
102102

103-
lib.step.dependOn(&linker_script.step);
103+
lib.step.dependOn(&write_file_step.step);
104104

105-
lib.setLinkerScript(linker_script.files.items[0].getPath());
105+
lib.setLinkerScript(linker_script);
106106
lib.stack_size = 4096;
107107
lib.link_z_notext = true;
108108
lib.root_module.pic = true;

build.zig.zon

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.{
2-
.name = "solana-program-sdk",
3-
.version = "0.15.1",
4-
.minimum_zig_version = "0.13.0",
2+
.fingerprint = 0xdc47aff950fd68c0,
3+
.name = .solana_program_sdk,
4+
.version = "0.16.0",
5+
.minimum_zig_version = "0.14.0",
56

67
// This field is optional.
78
// Each dependency must either provide a `url` and `hash`, or a `path`.
@@ -10,8 +11,8 @@
1011
// internet connectivity.
1112
.dependencies = .{
1213
.base58 = .{
13-
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.13.3.tar.gz",
14-
.hash = "1220fd067bf167b9062cc29ccf715ff97643c2d3f8958beea863b6036876bb71bcb8",
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",
1516
},
1617
},
1718
.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.43.0"
6+
solana_zig_version="v1.47.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)