diff --git a/cargo-ledger/src/setup.rs b/cargo-ledger/src/setup.rs index 1170da95..10f23af8 100644 --- a/cargo-ledger/src/setup.rs +++ b/cargo-ledger/src/setup.rs @@ -40,31 +40,41 @@ pub fn install_targets() { } } - // Install link_wrap.sh script needed for relocation into proper location - let target_host = std::str::from_utf8( - Command::new("rustup") - .arg("default") - .output() - .expect("failed to call rustup") - .stdout - .as_slice(), - ) - .unwrap(); + // Install link_wrap.sh script needed for relocation + println!("[ ] Install custom link script..."); - let start = target_host.find('-')? + 1; - let end = target_host.find(' ').unwrap() + start; - println!( - " Output folder for custom link script {}", - &target_host[start..end] - ); + /* Shall be put at the same place as rust-lld */ + let custom_link_script = "link_wrap.sh"; + + let cmd = Command::new("find") + .arg(sysroot_cmd) + .arg("-name") + .arg("rust-lld") + .output() + .expect("failed to find rust-lld linker") + .stdout; + + let rust_lld_path = std::str::from_utf8(&cmd).unwrap(); + let end = rust_lld_path.rfind('/').unwrap(); let outfilepath = - sysroot.join(&target_host[start..end]).join("link_wrap.sh"); - let target_url = target_files_url.join("link_wrap.sh"); - let cmd = Command::new("curl") + sysroot.join(&rust_lld_path[..end]).join(custom_link_script); + + /* Retrieve the linker script */ + let target_url = target_files_url.join(custom_link_script); + Command::new("curl") .arg(target_url) .arg("-o") - .arg(outfilepath) + .arg(&outfilepath) .output() .expect("failed to execute 'curl'"); + + println!("* Custom link script is {}", outfilepath.display()); + + /* Make the linker script executable */ + Command::new("chmod") + .arg("+x") + .arg(outfilepath) + .output() + .expect("failed to execute chmod"); }