Replace usages of target with one definition

parent 3a3bcc51
use std::{env, io, process};
use std::ffi::OsString;
use crate::{status_error, toolchain};
use crate::{status_error, toolchain, TARGET};
fn inner() -> io::Result<()> {
let toolchain_dir = toolchain()?;
let target = "x86_64-unknown-redox";
// PATH must be set first so cargo is sourced from the toolchain path
{
let path = env::var_os("PATH").unwrap_or(OsString::new());
......@@ -23,7 +21,7 @@ fn inner() -> io::Result<()> {
// TODO: Ensure no spaces in toolchain_dir
let rustflags = format!(
"-L {}",
toolchain_dir.join(&target).join("lib").display()
toolchain_dir.join(TARGET).join("lib").display()
);
let mut args = env::args();
......@@ -56,7 +54,7 @@ fn inner() -> io::Result<()> {
crate::env::command("cargo")?
.arg(subcommand)
.arg("--target").arg(target)
.arg("--target").arg(TARGET)
.args(arguments)
.env("CARGO_TARGET_X86_64_UNKNOWN_REDOX_RUNNER", runner)
.env("RUSTFLAGS", rustflags)
......
use std::{env, ffi, io, process};
use crate::{status_error, toolchain};
use crate::{status_error, toolchain, TARGET};
pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command> {
let toolchain_dir = toolchain()?;
......@@ -17,11 +17,10 @@ pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command>
env::set_var("PATH", new_path);
}
let target = "x86_64-unknown-redox";
let ar = format!("{}-ar", target);
let cc = format!("{}-gcc", target);
let cxx = format!("{}-g++", target);
let cc_target_var = target.replace("-", "_");
let ar = format!("{}-ar", TARGET);
let cc = format!("{}-gcc", TARGET);
let cxx = format!("{}-g++", TARGET);
let cc_target_var = TARGET.replace("-", "_");
let cargo_target_var = cc_target_var.to_uppercase();
let mut command = process::Command::new(program);
......@@ -30,8 +29,8 @@ pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command>
command.env(format!("CC_{}", cc_target_var), &cc);
command.env(format!("CXX_{}", cc_target_var), &cxx);
command.env("RUSTUP_TOOLCHAIN", &toolchain_dir);
command.env("TARGET", &target);
command.env("TARGET", TARGET);
Ok(command)
}
......
......@@ -9,6 +9,8 @@ mod install;
mod redoxfs;
mod toolchain;
static TARGET: &'static str = "x86_64-unknown-redox";
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn installed(program: &str) -> io::Result<bool> {
......
......@@ -2,7 +2,7 @@ use std::{fs, io};
use std::path::{Path, PathBuf};
use std::process::Command;
use crate::{redoxer_dir, status_error};
use crate::{redoxer_dir, status_error, TARGET};
//TODO: Rewrite with hyper or reqwest, tar-rs, sha2, and some gzip crate?
fn download<P: AsRef<Path>>(url: &str, path: P) -> io::Result<()> {
......@@ -36,7 +36,7 @@ fn shasum<P: AsRef<Path>>(path: P) -> io::Result<bool> {
//TODO: Rewrite with hyper or reqwest, tar-rs, sha2, and some gzip crate?
pub fn toolchain() -> io::Result<PathBuf> {
let url = "https://static.redox-os.org/toolchain/x86_64-unknown-redox";
let url = format!("https://static.redox-os.org/toolchain/{}", TARGET);
let toolchain_dir = redoxer_dir().join("toolchain");
if ! toolchain_dir.is_dir() {
println!("redoxer: building toolchain");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment