|
1 | 1 | use std::collections::HashSet;
|
2 | 2 | use std::dynamic_lib::DynamicLibrary;
|
3 |
| -use std::io::{fs, BufReader, USER_RWX}; |
4 |
| -use std::io::fs::PathExtensions; |
| 3 | +use std::io::{fs, BufferedReader, BufReader, USER_RWX}; |
| 4 | +use std::io::fs::{File, PathExtensions}; |
| 5 | +use std::os; |
5 | 6 |
|
6 | 7 | use core::{SourceMap, Package, PackageId, PackageSet, Target, Resolve};
|
7 | 8 | use util::{mod, CargoResult, ProcessBuilder, CargoError, human, caused_human};
|
@@ -512,12 +513,60 @@ fn rustc(package: &Package, target: &Target,
|
512 | 513 | let show_warnings = package.get_package_id() == cx.resolve.root() ||
|
513 | 514 | is_path_source;
|
514 | 515 | let rustc = if show_warnings {rustc} else {rustc.arg("-Awarnings")};
|
| 516 | + let build_cmd_layout = cx.layout(package, KindForHost); |
| 517 | + |
| 518 | + // building the possible `build/$pkg/output` file for this local package |
| 519 | + let command_output_file = build_cmd_layout.build(package).join("output"); |
| 520 | + |
| 521 | + // building the list of all possible `build/$pkg/output` files |
| 522 | + // whether they exist or not will be checked during the work |
| 523 | + let command_output_files = cx.dep_targets(package).iter().map(|&(pkg, _)| { |
| 524 | + build_cmd_layout.build(pkg).join("output") |
| 525 | + }).collect::<Vec<_>>(); |
515 | 526 |
|
516 | 527 | (proc() {
|
| 528 | + let mut rustc = rustc; |
| 529 | + |
| 530 | + let mut additional_library_paths = Vec::new(); |
| 531 | + |
| 532 | + // list of `-l` flags to pass to rustc coming from custom build scripts |
| 533 | + let additional_library_links = match File::open(&command_output_file) { |
| 534 | + Ok(f) => { |
| 535 | + let flags = try!(CustomBuildCommandOutput::parse( |
| 536 | + BufferedReader::new(f), name.as_slice())); |
| 537 | + |
| 538 | + additional_library_paths.extend(flags.library_paths.iter().map(|p| p.clone())); |
| 539 | + flags.library_links.clone() |
| 540 | + }, |
| 541 | + Err(_) => Vec::new() |
| 542 | + }; |
| 543 | + |
| 544 | + // loading each possible custom build output file to fill `additional_library_paths` |
| 545 | + for flags_file in command_output_files.into_iter() { |
| 546 | + let flags = match File::open(&flags_file) { |
| 547 | + Ok(f) => f, |
| 548 | + Err(_) => continue // the file doesn't exist, probably means that this pkg |
| 549 | + // doesn't have a build command |
| 550 | + }; |
| 551 | + |
| 552 | + let flags = try!(CustomBuildCommandOutput::parse( |
| 553 | + BufferedReader::new(flags), name.as_slice())); |
| 554 | + additional_library_paths.extend(flags.library_paths.iter().map(|p| p.clone())); |
| 555 | + } |
| 556 | + |
| 557 | + for p in additional_library_paths.into_iter() { |
| 558 | + rustc = rustc.arg("-L").arg(p); |
| 559 | + } |
| 560 | + for lib in additional_library_links.into_iter() { |
| 561 | + rustc = rustc.arg("-l").arg(lib); |
| 562 | + } |
| 563 | + |
517 | 564 | try!(rustc.exec().chain_error(|| {
|
518 | 565 | human(format!("Could not compile `{}`.", name))
|
519 | 566 | }));
|
| 567 | + |
520 | 568 | Ok(())
|
| 569 | + |
521 | 570 | }, kind, desc)
|
522 | 571 | }).collect())
|
523 | 572 | }
|
|
0 commit comments