Skip to content

Commit

Permalink
Put custom link script at the proper location
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Feb 1, 2024
1 parent 4410a62 commit 4268956
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions cargo-ledger/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 4268956

Please sign in to comment.