Skip to main content

macho_assembler/
lib.rs

1//! Mach-O 汇编器库
2//!
3//! 这个库提供了用于处理 Mach-O 格式文件的工具和结构。
4
5#![warn(missing_docs, rust_2018_idioms, missing_copy_implementations)]
6
7use crate::{formats::dylib::writer::DylibWriter, helpers::MachoWriter, types::MachoProgram};
8use gaia_types::{
9    helpers::{create_file, Url},
10    Result,
11};
12use std::path::Path;
13
14/// 类型定义模块
15pub mod types;
16
17/// 格式处理模块
18pub mod formats;
19/// 辅助工具模块
20pub mod helpers;
21
22/// 构建器模块
23pub mod builder;
24
25/// 将 Mach-O 程序写入到指定路径的动态库文件
26///
27/// 这是一个高级 API 函数,隐藏了 DylibWriter 的直接使用细节。
28///
29/// # 参数
30///
31/// * `macho` - 要写入的 Mach-O 程序
32/// * `path` - 输出文件路径
33///
34/// # 返回值
35///
36/// 成功时返回文件的 URL,失败时返回 GaiaError
37///
38/// # 示例
39///
40/// ```rust,no_run
41/// # use macho_assembler::dylib_write_path;
42/// # use std::path::Path;
43///
44/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
45/// // let macho_program = /* 创建 Mach-O 程序 */;
46/// // let output_path = Path::new("output.dylib");
47/// // let url = dylib_write_path(&macho_program, output_path)?;
48/// # Ok(())
49/// # }
50/// ```
51pub fn dylib_write_path(macho: &MachoProgram, path: &Path) -> Result<Url> {
52    let (file, url) = create_file(path)?;
53    let mut dylib = DylibWriter::new(file);
54    dylib.write_program(macho)?;
55    Ok(url)
56}