Skip to content

Commit 4414f51

Browse files
authored
program init (#35)
* program init * fix up ci * fix up ci, take 2 * build-sbf job * configure dependent jobs * js tests: disable program loading * ci: restore program builds in test_program * review feedback
1 parent c755dfa commit 4414f51

File tree

12 files changed

+241
-16
lines changed

12 files changed

+241
-16
lines changed

.github/workflows/main.yml

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ jobs:
6969

7070
- name: Lint / Features
7171
run: pnpm interface:lint:features
72+
73+
format_and_lint_program:
74+
name: Format & Lint Program
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Git Checkout
78+
uses: actions/checkout@v4
79+
80+
- name: Setup Environment
81+
uses: ./.github/actions/setup
82+
with:
83+
toolchain: format, lint
84+
85+
- name: Format
86+
run: pnpm program:format
87+
88+
- name: Lint / Clippy
89+
run: pnpm program:lint:clippy
90+
91+
- name: Lint / Docs
92+
run: pnpm program:lint:docs
93+
94+
- name: Lint / Features
95+
run: pnpm program:lint:features
7296

7397
wasm_interface:
7498
name: Build Interface in WASM
@@ -130,10 +154,40 @@ jobs:
130154
git status --porcelain
131155
test -z "$(git status --porcelain)"
132156
157+
build_program:
158+
name: Build Program
159+
runs-on: ubuntu-latest
160+
needs: format_and_lint_program
161+
steps:
162+
- name: Git Checkout
163+
uses: actions/checkout@v4
164+
165+
- name: Setup Environment
166+
uses: ./.github/actions/setup
167+
with:
168+
cargo-cache-key: cargo-build-program
169+
solana: true
170+
171+
- name: Build
172+
run: pnpm program:build
173+
174+
- name: Upload Program Builds
175+
uses: actions/upload-artifact@v4
176+
with:
177+
name: program-builds
178+
path: ./target/deploy/*.so
179+
if-no-files-found: error
180+
181+
- name: Save Program Builds For Client Jobs
182+
uses: actions/cache/save@v4
183+
with:
184+
path: ./**/*.so
185+
key: ${{ runner.os }}-builds-${{ github.sha }}
186+
133187
test_client_js:
134188
name: Test Client JS
135189
runs-on: ubuntu-latest
136-
needs: format_and_lint_client_js
190+
needs: [format_and_lint_client_js, build_program]
137191
steps:
138192
- name: Git Checkout
139193
uses: actions/checkout@v4
@@ -143,13 +197,19 @@ jobs:
143197
with:
144198
solana: true
145199

200+
- name: Restore Program Builds
201+
uses: actions/cache/restore@v4
202+
with:
203+
path: ./**/*.so
204+
key: ${{ runner.os }}-builds-${{ github.sha }}
205+
146206
- name: Test Client JS
147207
run: pnpm js:test
148208

149209
test_client_rust:
150210
name: Test Client Rust
151211
runs-on: ubuntu-latest
152-
needs: format_and_lint_client_rust
212+
needs: [format_and_lint_client_rust, build_program]
153213
steps:
154214
- name: Git Checkout
155215
uses: actions/checkout@v4
@@ -161,5 +221,35 @@ jobs:
161221
toolchain: test
162222
solana: true
163223

224+
- name: Restore Program Builds
225+
uses: actions/cache/restore@v4
226+
with:
227+
path: ./**/*.so
228+
key: ${{ runner.os }}-builds-${{ github.sha }}
229+
164230
- name: Test Client Rust
165231
run: pnpm rust:test
232+
233+
test_program:
234+
name: Test Program
235+
runs-on: ubuntu-latest
236+
needs: build_program
237+
steps:
238+
- name: Git Checkout
239+
uses: actions/checkout@v4
240+
241+
- name: Setup Environment
242+
uses: ./.github/actions/setup
243+
with:
244+
cargo-cache-key: cargo-program-tests
245+
toolchain: test
246+
solana: true
247+
248+
- name: Restore Program Builds
249+
uses: actions/cache/restore@v4
250+
with:
251+
path: ./**/*.so
252+
key: ${{ runner.os }}-builds-${{ github.sha }}
253+
254+
- name: Test
255+
run: pnpm program:test

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[workspace]
22
resolver = "2"
3-
members = ["clients/rust", "interface"]
3+
members = [
4+
"clients/rust",
5+
"interface",
6+
"program",
7+
]
48

59
[workspace.package]
610
authors = ["Anza Maintainers <maintainers@anza.xyz>"]
@@ -9,6 +13,21 @@ homepage = "https://anza.xyz/"
913
license = "Apache-2.0"
1014
edition = "2021"
1115

16+
[workspace.dependencies]
17+
solana-account-info = "2.1"
18+
solana-cpi = "2.1"
19+
solana-decode-error = "2.1"
20+
solana-frozen-abi = "2.1"
21+
solana-frozen-abi-macro = "2.1"
22+
solana-instruction = "2.1"
23+
solana-logger = "2.1"
24+
solana-nonce = "0.0.2"
25+
solana-msg = "2.1"
26+
solana-program = { version = "2.1", default-features = false }
27+
solana-program-entrypoint = "2.1"
28+
solana-program-error = "2.1"
29+
solana-pubkey = { version = "2.1", default-features = false }
30+
1231
[workspace.metadata.cli]
1332
solana = "2.1.0"
1433

interface/Cargo.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ num-traits = "0.2"
1919
serde = { version = "1.0.210", optional = true }
2020
serde_derive = { version = "1.0.210", optional = true }
2121
solana-decode-error = "^2.1"
22-
solana-frozen-abi = { version = "^2.1", features = ["frozen-abi"], optional = true }
23-
solana-frozen-abi-macro = { version = "^2.1", features = ["frozen-abi"], optional = true }
24-
solana-instruction = { version = "^2.1", features = ["bincode", "std"], optional = true }
25-
solana-logger = { version = "^2.1", optional = true }
26-
solana-pubkey = { version = "^2.1", default-features = false }
22+
solana-frozen-abi = { workspace = true, features = ["frozen-abi"], optional = true }
23+
solana-frozen-abi-macro = { workspace = true, features = ["frozen-abi"], optional = true }
24+
solana-instruction = { workspace = true, features = ["bincode", "std"], optional = true }
25+
solana-logger = { workspace = true, optional = true }
26+
solana-msg = { workspace = true }
27+
solana-program-error = { workspace = true }
28+
solana-pubkey = { workspace = true, default-features = false }
2729

2830
[target.'cfg(target_arch = "wasm32")'.dependencies]
2931
js-sys = "0.3.72"
@@ -35,10 +37,10 @@ borsh = { version = "1.5.1", features = ["derive", "unstable__schema"] }
3537
solana-account-info = "^2.1"
3638
solana-cpi = "^2.1"
3739
solana-nonce = "^0.0.2"
38-
solana-program = { version = "^2.1", default-features = false }
39-
solana-program-entrypoint = "^2.1"
40-
solana-program-error = { version = "^2.1", features = ["borsh"] }
41-
solana-pubkey = { version = "^2.1", features = ["std"] }
40+
solana-program = { workspace = true, default-features = false }
41+
solana-program-entrypoint = { workspace = true }
42+
solana-program-error = { workspace = true, features = ["borsh"] }
43+
solana-pubkey = { workspace = true, features = ["std"] }
4244
solana-system-interface = { path = ".", features = ["bincode"] }
4345
static_assertions = "1.1.0"
4446
strum = "0.24"

interface/src/error.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
use num_traits::{FromPrimitive, ToPrimitive};
2-
use solana_decode_error::DecodeError;
1+
use {
2+
num_traits::{FromPrimitive, ToPrimitive},
3+
solana_decode_error::DecodeError,
4+
solana_msg::msg,
5+
solana_program_error::PrintProgramError,
6+
};
37

48
// Use strum when testing to ensure our FromPrimitive
59
// impl is exhaustive
@@ -118,6 +122,12 @@ impl core::fmt::Display for SystemError {
118122
}
119123
}
120124

125+
impl PrintProgramError for SystemError {
126+
fn print<E>(&self) {
127+
msg!(&self.to_string());
128+
}
129+
}
130+
121131
impl<T> DecodeError<T> for SystemError {
122132
fn type_of() -> &'static str {
123133
"SystemError"

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
"interface:publish": "tsx ./scripts/rust.mts publish interface",
2828
"interface:test": "tsx ./scripts/rust.mts test interface",
2929
"interface:wasm": "tsx ./scripts/rust.mts wasm interface",
30+
"program:format": "tsx ./scripts/rust.mts format program",
31+
"program:lint": "tsx ./scripts/rust.mts lint program",
32+
"program:lint:clippy": "tsx ./scripts/rust.mts lint-clippy program",
33+
"program:lint:docs": "tsx ./scripts/rust.mts lint-docs program",
34+
"program:lint:features": "tsx ./scripts/rust.mts lint-features program",
35+
"program:publish": "tsx ./scripts/rust.mts publish program",
36+
"program:build": "tsx ./scripts/rust.mts build-sbf program",
37+
"program:test": "tsx ./scripts/rust.mts test program",
3038
"template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts"
3139
},
3240
"devDependencies": {

program/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "solana-system-program"
3+
version = "3.0.0"
4+
description = "Solana System Program"
5+
readme = "README.md"
6+
authors = { workspace = true }
7+
repository = { workspace = true }
8+
homepage = { workspace = true }
9+
license = { workspace = true }
10+
edition = { workspace = true }
11+
12+
[package.metadata.solana]
13+
program-id = "11111111111111111111111111111111"
14+
15+
[features]
16+
bpf-entrypoint = []
17+
18+
[dependencies]
19+
solana-account-info = { workspace = true }
20+
solana-program-entrypoint = { workspace = true }
21+
solana-program-error = { workspace = true }
22+
solana-pubkey = { workspace = true }
23+
solana-system-interface = { path = "../interface" }
24+
25+
[dev-dependencies]
26+
27+
[lib]
28+
crate-type = ["cdylib"]
29+
30+
[lints.rust.unexpected_cfgs]
31+
level = "warn"
32+
check-cfg = [
33+
'cfg(target_os, values("solana"))',
34+
]

program/src/entrypoint.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Program entrypoint.
2+
3+
use {
4+
crate::processor,
5+
solana_account_info::AccountInfo,
6+
solana_program_error::{PrintProgramError, ProgramResult},
7+
solana_pubkey::Pubkey,
8+
solana_system_interface::error::SystemError,
9+
};
10+
11+
solana_program_entrypoint::entrypoint!(process_instruction);
12+
fn process_instruction(
13+
program_id: &Pubkey,
14+
accounts: &[AccountInfo],
15+
instruction_data: &[u8],
16+
) -> ProgramResult {
17+
processor::process(program_id, accounts, instruction_data)
18+
.inspect_err(PrintProgramError::print::<SystemError>)
19+
}

program/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Solana System Program.
2+
3+
#[cfg(all(target_os = "solana", feature = "bpf-entrypoint"))]
4+
pub mod entrypoint;
5+
pub mod processor;

program/src/processor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Program processor.
2+
3+
use {
4+
solana_account_info::AccountInfo, solana_program_error::ProgramResult, solana_pubkey::Pubkey,
5+
};
6+
7+
pub fn process(_program_id: &Pubkey, _accounts: &[AccountInfo], _input: &[u8]) -> ProgramResult {
8+
Ok(())
9+
}

0 commit comments

Comments
 (0)