Skip to content

Commit

Permalink
rustc: Detect the system root and allow the user to override if neces…
Browse files Browse the repository at this point in the history
…sary
  • Loading branch information
pcwalton committed May 5, 2011
1 parent 1299e74 commit bde44a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import middle.typestate_check;
import lib.llvm;
import util.common;

import std.fs;
import std.map.mk_hashmap;
import std.option;
import std.option.some;
Expand Down Expand Up @@ -141,6 +142,7 @@ options:
-c compile and assemble, but do not link
--save-temps write intermediate files in addition to normal output
--time-passes time the individual phases of the compiler
--sysroot <path> override the system root (default: rustc's directory)
--no-typestate don't run the typestate pass (unsafe!)
-h display this message\n\n");
}
Expand All @@ -152,6 +154,12 @@ fn get_os() -> session.os {
if (_str.eq(s, "linux")) { ret session.os_linux; }
}

fn get_default_sysroot(str binary) -> str {
auto dirname = fs.dirname(binary);
if (_str.eq(dirname, binary)) { ret "."; }
ret dirname;
}

fn main(vec[str] args) {

// FIXME: don't hard-wire this.
Expand All @@ -166,8 +174,9 @@ fn main(vec[str] args) {
optflag("pretty"), optflag("ls"), optflag("parse-only"),
optflag("O"), optflag("shared"), optmulti("L"),
optflag("S"), optflag("c"), optopt("o"), optopt("g"),
optflag("save-temps"), optflag("time-passes"),
optflag("no-typestate"), optflag("noverify"));
optflag("save-temps"), optopt("sysroot"),
optflag("time-passes"), optflag("no-typestate"),
optflag("noverify"));
auto binary = _vec.shift[str](args);
auto match;
alt (GetOpts.getopts(args, opts)) {
Expand Down Expand Up @@ -203,6 +212,13 @@ fn main(vec[str] args) {
auto debuginfo = opt_present(match, "g");
auto time_passes = opt_present(match, "time-passes");
auto run_typestate = !opt_present(match, "no-typestate");
auto sysroot_opt = GetOpts.opt_maybe_str(match, "sysroot");

auto sysroot;
alt (sysroot_opt) {
case (none[str]) { sysroot = get_default_sysroot(binary); }
case (some[str](?s)) { sysroot = s; }
}

let @session.options sopts =
@rec(shared = shared,
Expand All @@ -213,7 +229,8 @@ fn main(vec[str] args) {
save_temps = save_temps,
time_passes = time_passes,
output_type = output_type,
library_search_paths = library_search_paths);
library_search_paths = library_search_paths,
sysroot = sysroot);

auto crate_cache = common.new_int_hash[session.crate_metadata]();
auto target_crate_num = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/comp/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type options = rec(bool shared,
bool save_temps,
bool time_passes,
middle.trans.output_type output_type,
vec[str] library_search_paths);
vec[str] library_search_paths,
str sysroot);

type crate_metadata = rec(str name,
vec[u8] data);
Expand Down

0 comments on commit bde44a0

Please sign in to comment.