Skip to main content

compile_multi_file_with_options

Function compile_multi_file_with_options 

Source
pub fn compile_multi_file_with_options(
    sources: &[SourceFile<'_>],
    options: &CompileOptions,
) -> MultiErrorResult<CompileOutput>
Expand description

Compile multiple source files to an ELF binary.

This is the main entry point for multi-file compilation. It:

  1. Parses all files in parallel
  2. Merges symbols into a unified program
  3. Performs semantic analysis across all files
  4. Generates code for the combined program

Cross-file references (function calls, struct/enum usage) are resolved during semantic analysis since all symbols are visible in the merged program.

§Arguments

  • sources - Slice of source files to compile
  • options - Compilation options (target, linker, optimization level, etc.)

§Returns

A CompileOutput containing the ELF binary and any warnings, or errors if compilation fails.

§Example

use gruel_compiler::{SourceFile, CompileOptions, compile_multi_file_with_options};
use gruel_span::FileId;

let sources = vec![
    SourceFile::new("main.gruel", "fn main() -> i32 { helper() }", FileId::new(1)),
    SourceFile::new("utils.gruel", "fn helper() -> i32 { 42 }", FileId::new(2)),
];
let options = CompileOptions::default();
let output = compile_multi_file_with_options(&sources, &options)?;