Skip to content

Commit b06cb0d

Browse files
committed
cargo: Install blobs to $sysroot/(bin|lib) on system-mode
Issue #1795
1 parent ff0ab6b commit b06cb0d

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/cargo/cargo.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std;
66
import rustc::syntax::{ast, codemap};
77
import rustc::syntax::parse::parser;
88
import rustc::util::filesearch::{get_cargo_root, get_cargo_root_nearest,
9-
get_cargo_sysroot};
9+
get_cargo_sysroot, libdir};
1010
import rustc::driver::diagnostic;
1111

1212
import std::fs;
@@ -467,10 +467,31 @@ fn install_one_crate(c: cargo, _path: str, cf: str, _p: pkg) {
467467
#debug(" bin: %s", ct);
468468
// FIXME: need libstd fs::copy or something
469469
run::run_program("cp", [ct, c.bindir]);
470+
if c.opts.mode == system_mode {
471+
install_one_crate_to_sysroot(ct, "bin");
472+
}
470473
} else {
471474
#debug(" lib: %s", ct);
472475
run::run_program("cp", [ct, c.libdir]);
476+
if c.opts.mode == system_mode {
477+
install_one_crate_to_sysroot(ct, libdir());
478+
}
479+
}
480+
}
481+
}
482+
483+
fn install_one_crate_to_sysroot(ct: str, target: str) {
484+
alt os::get_exe_path() {
485+
some(_path) {
486+
let path = [_path, "..", target];
487+
check vec::is_not_empty(path);
488+
let target_dir = fs::normalize(fs::connect_many(path));
489+
let p = run::program_output("cp", [ct, target_dir]);
490+
if p.status != 0 {
491+
warn(#fmt["Copying %s to %s is failed", ct, target_dir]);
492+
}
473493
}
494+
none { }
474495
}
475496
}
476497

@@ -827,23 +848,25 @@ fn cmd_usage() {
827848
"
828849
829850
init Set up .cargo
830-
install [--test] [source/]package-name Install by name
831-
install [--test] uuid:[source/]package-uuid Install by uuid
851+
install [options] [source/]package-name Install by name
852+
install [options] uuid:[source/]package-uuid Install by uuid
832853
list [source] List packages
833854
search <name | '*'> [tags...] Search packages
834855
sync Sync all sources
835856
usage This
836857
837858
Options:
838859
860+
cargo install
861+
839862
--mode=[system,user,local] change mode as (system/user/local)
840863
-g equivalent to --mode=user
841864
-G equivalent to --mode=system
842865
843866
NOTE:
844-
This command creates/uses local-level .cargo by default.
845-
To create/use user-level .cargo, use option -g/--mode=user.
846-
To create/use system-level .cargo, use option -G/--mode=system.
867+
\"cargo install\" installs bin/libs to local-level .cargo by default.
868+
To install them into user-level .cargo, use option -g/--mode=user.
869+
To install them into bin/lib on sysroot, use option -G/--mode=system.
847870
");
848871
}
849872

0 commit comments

Comments
 (0)