Skip to content

Commit bde44a0

Browse files
committed
rustc: Detect the system root and allow the user to override if necessary
1 parent 1299e74 commit bde44a0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/comp/driver/rustc.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import middle.typestate_check;
1414
import lib.llvm;
1515
import util.common;
1616

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

157+
fn get_default_sysroot(str binary) -> str {
158+
auto dirname = fs.dirname(binary);
159+
if (_str.eq(dirname, binary)) { ret "."; }
160+
ret dirname;
161+
}
162+
155163
fn main(vec[str] args) {
156164

157165
// FIXME: don't hard-wire this.
@@ -166,8 +174,9 @@ fn main(vec[str] args) {
166174
optflag("pretty"), optflag("ls"), optflag("parse-only"),
167175
optflag("O"), optflag("shared"), optmulti("L"),
168176
optflag("S"), optflag("c"), optopt("o"), optopt("g"),
169-
optflag("save-temps"), optflag("time-passes"),
170-
optflag("no-typestate"), optflag("noverify"));
177+
optflag("save-temps"), optopt("sysroot"),
178+
optflag("time-passes"), optflag("no-typestate"),
179+
optflag("noverify"));
171180
auto binary = _vec.shift[str](args);
172181
auto match;
173182
alt (GetOpts.getopts(args, opts)) {
@@ -203,6 +212,13 @@ fn main(vec[str] args) {
203212
auto debuginfo = opt_present(match, "g");
204213
auto time_passes = opt_present(match, "time-passes");
205214
auto run_typestate = !opt_present(match, "no-typestate");
215+
auto sysroot_opt = GetOpts.opt_maybe_str(match, "sysroot");
216+
217+
auto sysroot;
218+
alt (sysroot_opt) {
219+
case (none[str]) { sysroot = get_default_sysroot(binary); }
220+
case (some[str](?s)) { sysroot = s; }
221+
}
206222

207223
let @session.options sopts =
208224
@rec(shared = shared,
@@ -213,7 +229,8 @@ fn main(vec[str] args) {
213229
save_temps = save_temps,
214230
time_passes = time_passes,
215231
output_type = output_type,
216-
library_search_paths = library_search_paths);
232+
library_search_paths = library_search_paths,
233+
sysroot = sysroot);
217234

218235
auto crate_cache = common.new_int_hash[session.crate_metadata]();
219236
auto target_crate_num = 0;

src/comp/driver/session.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type options = rec(bool shared,
3333
bool save_temps,
3434
bool time_passes,
3535
middle.trans.output_type output_type,
36-
vec[str] library_search_paths);
36+
vec[str] library_search_paths,
37+
str sysroot);
3738

3839
type crate_metadata = rec(str name,
3940
vec[u8] data);

0 commit comments

Comments
 (0)