sbpf 0.2.4

A complete toolchain for building and deploying Solana BPF assembly programs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::{Result, Context};
use sbpf_linker::link_program;

pub fn link(source: &str) -> Result<()> {
    let program = std::fs::read(source).context("Failed to read bytecode")?;
    let bytecode = link_program(&program)
        .map_err(|e| anyhow::anyhow!("Link error: {}", e))?;
    let src_name = std::path::Path::new(source)
        .file_stem()
        .and_then(|s| s.to_str())
        .unwrap_or("main");
    let output_path = std::path::Path::new(source)
        .parent()
        .unwrap_or_else(|| std::path::Path::new("."))
        .join(format!("{}.so", src_name));
    std::fs::write(output_path, bytecode)?;
    Ok(())
}