Skip to content

Commit 68d50b5

Browse files
committed
Add target_triple to session::options. Use host triple by default, accept --target on command line.
1 parent 07eb29d commit 68d50b5

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

configure

+13-14
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,6 @@ then
175175
exit 0
176176
fi
177177

178-
step_msg "making directories"
179-
for i in \
180-
doc \
181-
rt rt/isaac rt/bigint rt/sync rt/test rt/arch/i386 \
182-
rt/libuv rt/libuv/src/ares rt/libuv/src/eio rt/libuv/src/ev \
183-
rustllvm \
184-
dl stage0 stage1 stage2 stage3 \
185-
stage0/lib stage1/lib stage2/lib stage3/lib \
186-
test/run-pass test/run-fail test/compile-fail \
187-
test/bench test/perf test/pretty
188-
do
189-
make_dir $i
190-
done
191-
192178
step_msg "writing out basic parameters"
193179
putvar CFG_SRC_DIR
194180
putvar CFG_BUILD_DIR
@@ -316,6 +302,19 @@ perl -i.bak -p -e 's@ ([a-zA-Z]):[/\\]@ /\1/@go;' \
316302
-e 's@\\@/@go;' config.mk
317303
rm -f config.mk.bak
318304

305+
step_msg "making directories"
306+
for i in \
307+
doc \
308+
rt rt/isaac rt/bigint rt/sync rt/test rt/arch/i386 \
309+
rt/libuv rt/libuv/src/ares rt/libuv/src/eio rt/libuv/src/ev \
310+
rustllvm \
311+
dl stage{0,1,2,3}{,/lib,/lib/$CFG_LLVM_TRIPLE} \
312+
test/run-pass test/run-fail test/compile-fail \
313+
test/bench test/perf test/pretty
314+
do
315+
make_dir $i
316+
done
317+
319318
copy ${CFG_SRC_DIR}Makefile.in ./Makefile
320319

321320
copy ${CFG_SRC_DIR}src/rt/libuv/Makefile rt/libuv/Makefile

src/comp/driver/rustc.rs

+31-14
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ fn default_configuration(sess: session::session, argv0: str, input: str) ->
3232
let mk = attr::mk_name_value_item_str;
3333

3434
ret [ // Target bindings.
35-
mk("target_os", std::os::target_os()), mk("target_arch", "x86"),
35+
mk("target_os", std::os::target_os()),
36+
mk("target_arch", "x86"),
3637
mk("target_libc", libc),
3738
// Build bindings.
38-
mk("build_compiler", argv0), mk("build_input", input)];
39+
mk("build_compiler", argv0),
40+
mk("build_input", input)];
3941
}
4042

4143
fn build_configuration(sess: session::session, argv0: str, input: str) ->
@@ -224,6 +226,7 @@ fn version(argv0: str) {
224226
let env_vers = #env["CFG_VERSION"];
225227
if str::byte_len(env_vers) != 0u { vers = env_vers; }
226228
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
229+
io::stdout().write_str(#fmt["host: %s\n", host_triple()]);
227230
}
228231

229232
fn usage(argv0: str) {
@@ -257,6 +260,7 @@ options:
257260
--time-passes time the individual phases of the compiler
258261
--time-llvm-passes time the individual phases of the LLVM backend
259262
--sysroot <path> override the system root (default: rustc's directory)
263+
--target <triple> target to compile for (default: host triple)
260264
--no-typestate don't run the typestate pass (unsafe!)
261265
--test build test harness
262266
--gc garbage collect shared data (experimental/temporary)
@@ -295,26 +299,25 @@ fn get_default_sysroot(binary: str) -> str {
295299
ret dirname;
296300
}
297301

298-
fn build_target_config() -> @session::config {
299-
let triple: str = str::str_from_cstr(llvm::llvm::LLVMRustGetHostTriple());
302+
fn build_target_config(sopts: @session::options) -> @session::config {
300303
let target_cfg: @session::config =
301-
@{os: get_os(triple),
302-
arch: get_arch(triple),
304+
@{os: get_os(sopts.target_triple),
305+
arch: get_arch(sopts.target_triple),
303306
int_type: ast::ty_i32,
304307
uint_type: ast::ty_u32,
305308
float_type: ast::ty_f64};
306309
ret target_cfg;
307310
}
308311

312+
fn host_triple() -> str {
313+
str::str_from_cstr(llvm::llvm::LLVMRustGetHostTriple())
314+
}
315+
309316
fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
310317
-> @session::options {
311318
let library = opt_present(match, "lib");
312319
let static = opt_present(match, "static");
313320

314-
let library_search_paths = [binary_dir + "/lib"];
315-
let lsp_vec = getopts::opt_strs(match, "L");
316-
for lsp: str in lsp_vec { library_search_paths += [lsp]; }
317-
318321
let parse_only = opt_present(match, "parse-only");
319322
let no_trans = opt_present(match, "no-trans");
320323

@@ -336,6 +339,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
336339
let time_llvm_passes = opt_present(match, "time-llvm-passes");
337340
let run_typestate = !opt_present(match, "no-typestate");
338341
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
342+
let target_opt = getopts::opt_maybe_str(match, "target");
339343
let opt_level: uint =
340344
if opt_present(match, "O") {
341345
if opt_present(match, "OptLevel") {
@@ -361,6 +365,17 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
361365
none. { get_default_sysroot(binary) }
362366
some(s) { s }
363367
};
368+
let target =
369+
alt target_opt {
370+
none. { host_triple() }
371+
some(s) { s }
372+
};
373+
374+
let library_search_paths = [binary_dir + "/lib", // FIXME: legacy
375+
binary_dir + "/lib/" + target ];
376+
let lsp_vec = getopts::opt_strs(match, "L");
377+
for lsp: str in lsp_vec { library_search_paths += [lsp]; }
378+
364379
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
365380
let test = opt_present(match, "test");
366381
let do_gc = opt_present(match, "gc");
@@ -378,6 +393,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
378393
output_type: output_type,
379394
library_search_paths: library_search_paths,
380395
sysroot: sysroot,
396+
target_triple: target,
381397
cfg: cfg,
382398
test: test,
383399
parse_only: parse_only,
@@ -387,7 +403,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
387403
}
388404

389405
fn build_session(sopts: @session::options) -> session::session {
390-
let target_cfg = build_target_config();
406+
let target_cfg = build_target_config(sopts);
391407
let cstore = cstore::mk_cstore();
392408
ret session::session(target_cfg, sopts, cstore,
393409
@{cm: codemap::new_codemap(), mutable next_id: 0},
@@ -412,9 +428,10 @@ fn opts() -> [getopts::opt] {
412428
optflag("ls"), optflag("parse-only"), optflag("no-trans"),
413429
optflag("O"), optopt("OptLevel"), optmulti("L"), optflag("S"),
414430
optflag("c"), optopt("o"), optflag("g"), optflag("save-temps"),
415-
optopt("sysroot"), optflag("stats"), optflag("time-passes"),
416-
optflag("time-llvm-passes"), optflag("no-typestate"),
417-
optflag("noverify"), optmulti("cfg"), optflag("test"),
431+
optopt("sysroot"), optopt("target"), optflag("stats"),
432+
optflag("time-passes"), optflag("time-llvm-passes"),
433+
optflag("no-typestate"), optflag("noverify"),
434+
optmulti("cfg"), optflag("test"),
418435
optflag("lib"), optflag("static"), optflag("gc")];
419436
}
420437

src/comp/driver/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type options =
3434
output_type: back::link::output_type,
3535
library_search_paths: [str],
3636
sysroot: str,
37+
target_triple: str,
3738
cfg: ast::crate_cfg,
3839
test: bool,
3940
parse_only: bool,

0 commit comments

Comments
 (0)