Commit 732c3bd5 authored by qinsoon's avatar qinsoon

add bootimage-external-lib/libpath for linking against other libraries

during generating shared lib or executable
parent 11c31310
......@@ -8,65 +8,83 @@ use std::path::PathBuf;
use std::process::Command;
use std::process::Output;
fn link_executable_internal (files: Vec<PathBuf>, out: PathBuf) -> PathBuf {
let mut gcc = Command::new(get_test_clang_path());
fn link_executable_internal (files: Vec<PathBuf>, lib: &Vec<String>, libpath: &Vec<String>, out: PathBuf) -> PathBuf {
let mut cc = Command::new(get_test_clang_path());
for file in files {
println!("link with {:?}", file.as_path());
gcc.arg(file.as_path());
cc.arg(file.as_path());
}
// external libs
for path in libpath.iter() {
cc.arg(format!("-L{}", path));
}
for l in lib.iter() {
cc.arg(format!("-l{}", l));
}
println!("output as {:?}", out.as_path());
if cfg!(target_os = "linux") {
gcc.arg("-ldl");
gcc.arg("-lrt");
gcc.arg("-lm");
gcc.arg("-lpthread");
cc.arg("-ldl");
cc.arg("-lrt");
cc.arg("-lm");
cc.arg("-lpthread");
}
// so we can find symbols in itself
gcc.arg("-rdynamic");
gcc.arg("-o");
gcc.arg(out.as_os_str());
cc.arg("-rdynamic");
cc.arg("-o");
cc.arg(out.as_os_str());
assert!(exec(gcc).status.success());
assert!(exec(cc).status.success());
out
}
fn link_dylib_internal (files: Vec<PathBuf>, out: PathBuf) -> PathBuf {
fn link_dylib_internal (files: Vec<PathBuf>, lib: &Vec<String>, libpath: &Vec<String>, out: PathBuf) -> PathBuf {
let mut object_files : Vec<PathBuf> = vec![];
for file in files {
let mut gcc = Command::new(get_test_clang_path());
let mut cc = Command::new(get_test_clang_path());
gcc.arg("-c");
gcc.arg("-fPIC");
cc.arg("-c");
cc.arg("-fPIC");
let mut out = file.clone();
out.set_extension("o");
gcc.arg(file.as_os_str());
gcc.arg("-o");
gcc.arg(out.as_os_str());
cc.arg(file.as_os_str());
cc.arg("-o");
cc.arg(out.as_os_str());
object_files.push(out);
exec(gcc);
exec(cc);
}
let mut cc = Command::new(get_test_clang_path());
// external libs
for path in libpath.iter() {
cc.arg(format!("-L{}", path));
}
for l in lib.iter() {
cc.arg(format!("-l{}", l));
}
let mut gcc = Command::new(get_test_clang_path());
gcc.arg("-shared");
gcc.arg("-fPIC");
gcc.arg("-Wl");
gcc.arg("-undefined");
gcc.arg("dynamic_lookup");
cc.arg("-shared");
cc.arg("-fPIC");
cc.arg("-Wl");
cc.arg("-undefined");
cc.arg("dynamic_lookup");
for obj in object_files {
gcc.arg(obj.as_os_str());
cc.arg(obj.as_os_str());
}
gcc.arg("-o");
gcc.arg(out.as_os_str());
cc.arg("-o");
cc.arg(out.as_os_str());
exec(gcc);
exec(cc);
out
}
......@@ -131,7 +149,10 @@ pub fn link_primordial (funcs: Vec<MuName>, out: &str, vm: &VM) -> PathBuf {
let mut out_path = emit_dir.clone();
out_path.push(out);
link_executable_internal(files, out_path)
link_executable_internal(files,
&vm.vm_options.flag_bootimage_external_lib,
&vm.vm_options.flag_bootimage_external_libpath,
out_path)
}
pub fn execute(executable: PathBuf) -> Output {
......@@ -160,7 +181,10 @@ pub fn link_dylib (funcs: Vec<MuName>, out: &str, vm: &VM) -> PathBuf {
let mut out_path = PathBuf::from(&vm.vm_options.flag_aot_emit_dir);
out_path.push(out);
link_dylib_internal(files, out_path)
link_dylib_internal(files,
&vm.vm_options.flag_bootimage_external_lib,
&vm.vm_options.flag_bootimage_external_libpath,
out_path)
}
pub fn link_dylib_with_extra_srcs(funcs: Vec<MuName>, srcs: Vec<String>, out: &str, vm: &VM) -> PathBuf{
......@@ -183,5 +207,8 @@ pub fn link_dylib_with_extra_srcs(funcs: Vec<MuName>, srcs: Vec<String>, out: &s
let mut out_path = PathBuf::from(&vm.vm_options.flag_aot_emit_dir);
out_path.push(out);
link_dylib_internal(files, out_path)
link_dylib_internal(files,
&vm.vm_options.flag_bootimage_external_lib,
&vm.vm_options.flag_bootimage_external_libpath,
out_path)
}
......@@ -12,25 +12,32 @@ Usage:
init_mu [options]
VM:
--log-level=<level> logging level: none, error, warn, info, debug, trace [default: trace]
--log-level=<level> logging level: none, error, warn, info, debug, trace [default: trace]
Compiler:
--disable-inline disable compiler function inlining
--disable-inline disable compiler function inlining
AOT Compiler:
--aot-emit-dir=<dir> the emit directory for ahead-of-time compiling [default: emit]
--aot-emit-dir=<dir> the emit directory for ahead-of-time compiling [default: emit]
--bootimage-external-lib=<lib> ... library that will be linked against when making bootimage [default: ]
--bootimage-external-libpath=<path> ... path for the libraries during bootimage generation [default: ]
Garbage Collection:
--gc-immixspace-size=<kb> immix space size (default 65536kb = 64mb) [default: 67108864]
--gc-lospace-size=<kb> large object space size (default 65536kb = 64mb) [default: 67108864]
--gc-nthreads=<n> number of threads for parallel gc [default: 8]
--gc-immixspace-size=<kb> immix space size (default 65536kb = 64mb) [default: 67108864]
--gc-lospace-size=<kb> large object space size (default 65536kb = 64mb) [default: 67108864]
--gc-nthreads=<n> number of threads for parallel gc [default: 8]
";
#[derive(Debug, RustcDecodable, RustcEncodable)]
pub struct VMOptions {
pub flag_log_level: MuLogLevel,
pub flag_disable_inline: bool,
pub flag_aot_emit_dir: String,
pub flag_bootimage_external_lib: Vec<String>,
pub flag_bootimage_external_libpath: Vec<String>,
pub flag_gc_immixspace_size: usize,
pub flag_gc_lospace_size: usize,
pub flag_gc_nthreads: usize
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment