forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvm-bitcode-linker.rs
65 lines (48 loc) · 1.52 KB
/
llvm-bitcode-linker.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::path::PathBuf;
use clap::Parser;
use llvm_bitcode_linker::{Optimization, Session, Target};
#[derive(Debug, Parser)]
/// Linker for embedded code without any system dependencies
pub struct Args {
/// Input files - objects, archives and static libraries.
///
/// An archive can be, but not required to be, a Rust rlib.
files: Vec<PathBuf>,
/// A symbol that should be exported
#[arg(long)]
export_symbol: Vec<String>,
/// Input files directory
#[arg(short = 'L')]
input_dir: Vec<PathBuf>,
/// Target triple for which the code is compiled
#[arg(long)]
target: Target,
/// The target cpu
#[arg(long)]
target_cpu: Option<String>,
/// The target features
#[arg(long)]
target_feature: Option<String>,
/// Write output to the filename
#[arg(short, long)]
output: PathBuf,
// Enable link time optimization
#[arg(long)]
lto: bool,
/// Emit debug information
#[arg(long)]
debug: bool,
/// The optimization level
#[arg(short = 'O', value_enum, default_value = "0")]
optimization: Optimization,
}
fn main() -> anyhow::Result<()> {
tracing_subscriber::FmtSubscriber::builder().with_max_level(tracing::Level::DEBUG).init();
let args = Args::parse();
let mut linker = Session::new(args.target, args.target_cpu, args.target_feature, args.output);
linker.add_exported_symbols(args.export_symbol);
for rlib in args.files {
linker.add_file(rlib);
}
linker.lto(args.optimization, args.debug)
}