我正试图通过自己重写rust-lib来理解solana/example-helloworld
。我已经完成了这项工作,并从package.json文件中生成了.so
文件,下面是运行的内容:
cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program
我使用了上面的内容,因为我已经在本地进行了货物设置,并在上面运行了我的设置,我遇到了一些问题,从版本(使用2021,不得不降级到2018(到必须将main.rs
重命名为lib.rs
,以及其他我记不清的问题。以下是我从项目根目录中的终端实际运行的命令,Cargo.toml文件位于:
cargo build-bpf --manifest-path=./Cargo.toml --bpf-out-dir=dist/program
但在上面运行时,在dist目录中,没有任何
这实际上是一个多方面的问题:
.so
文件表示solana文件,对吗cargo build-bpf
是什么意思- 2021年版不适用于索拉纳的例子有什么原因吗
- 最后,为什么上面的命令不输出我的
.so
文件
我的货物.toml如下:
[package]
name = "jjoek-sc"
version = "0.0.1"
description = "My first rust program for solana (hello john)"
authors = ["JJoek <info@jjoek.com>"]
license = "Apache-2.0"
homepage = "https://jjoek.com/"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
borsh = "0.9.1"
borsh-derive = "0.9.1"
solana-program = "~1.8.14"
下面是我的lib.rs
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint,
entrypoint::ProgramResult,
pubkey::Pubkey,
msg,
program_error::ProgramError,
};
/// Define the type of state stored in accounts
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct GreetingAccount {
/// number of greetings
pub counter: u32,
}
// Declare and export the program's entrypoint
entrypoint!(process_instruction);
// Program entrypoint's implementation
pub fn process_instruction(program_id: &Pubkey, accounts: &[AccountInfo], _instruction_data: &[u8]) -> ProgramResult {
msg!("Hello, John everything is gonna be okay");
msg!("Hello World Rust program entrypoint");
// Iterating accounts is safer than indexing
let accounts_iter = &mut accounts.iter();
// Get the account to say hello to
let account = next_account_info(accounts_iter)?;
// The account must be owned by the program in order to modify its data
if account.owner != program_id {
msg!("Greeted account does not have the correct program id");
return Err(ProgramError::IncorrectProgramId);
}
// Increment and store the number of times the account has been greeted
let mut greeting_account = GreetingAccount::try_from_slice(&account.data.borrow())?;
greeting_account.counter += 1;
greeting_account.serialize(&mut &mut account.data.borrow_mut()[..])?;
msg!("Greeted {} time(s)!", greeting_account.counter);
Ok(())
}
.所以file are表示solana文件,对吧?
so
代表共享对象,也称为动态可重定位库或Cargo.toml.中的dylib
我们所说的货物构建bpf是什么意思?
BPF是内核中的一个虚拟机,因此这应该指示cargo为该目标构建。
2021版不适用于索拉纳的例子有什么原因吗?
我不知道,但我怀疑这是一个简单的修复。
最后,为什么上面的命令不输出我的.so文件?
可能是您在Cargo.toml:中缺少lib部分吗
[lib]
crate-type = ["cdylib", "lib"]